标签:name string play 了解 out bar 操作 exit 心得
import Java. u till. scanner; public class Account{ public int id; public String name; public int password; public int money; public Account(int id,String name,int password,int money){ this. id=id; this. name=name; this. password=password; this. money=money; } pubilc void Display(){ System. out. printIn("账户:"+id); System. out. printIn("姓名:"+name); System. out. printIn("余额:"+money); } public void takeMoney(){ while(true){ Scanner sc=new Scanner(System.in); System. out. printIn("请输入密码进行验证"); int pass=sc.nextInt(); if(pass==password){ System. out. printIn("请输入需要取款的金额:"); int withdrawals=sc.nexInt(); if(withdrawals<=money){ money=money-withdrawals; System. out. printIn("账户余额:"+money); } else{ System. out. printIn("当前余额不足"); } break; }else{ System. out. printIn("你输入的密码有误,请重新输入"); } sc. close(); } } public void saveMoney(inmoney){ money=money+inmoney; System. out. printIn("此次存款为:"+inmoney); System. out. printIn("账户余额:"+money); } public static void main(String[]args){ Account acc=new Account(10000,"lxf",123456,100000); acc. id=10000; acc. name="lxf"; acc. money=100000; Scanner sc=new Scanner(System.in); while(true){ System. out. printIn("欢迎进入银行账户操作系统"); System. out. printIn("1银行账户信息"); System. out. printIn("2取款操作"); System. out. printIn("3存款操作"); System. out. printIn("4退出系统"); int choice=sc.nexInt(); switch(choice){ case 1: System. out. printIn("银行账户信息"); acc. Display(); break; case 2: System. out. printIn("取款操作"); acc. takeMoney(); break; case 3: System. out. printIn("存款操作"); acc. saveMoney(1000); break; case 4: System. exit(0); break; default: System. out. printIn("你的选择有误"); break; } } } }
心得:
对类的封装还不太熟,在同学的帮助下完成。
自己对java还不太了解,各方面都被不太懂,应该加强学习,多上机联系,争取多懂一点。
标签:name string play 了解 out bar 操作 exit 心得
原文地址:https://www.cnblogs.com/java199-yx/p/11111381.html