[实验任务一]:银行账户
用Java代码模拟实现课堂上的“银行账户”的实例,要求编写客户端测试代码模拟用户存款和取款,注意账户对象状态和行为的变化。
1. 提交源代码
2. public class Account
3. {
4. private int userID;//账号
5. private int password;//密码
6. private double deposit;//存款余额
7. private double rate;//利率
8. private double balance;//最小余额
9. static int aotonomic_number=2021001;
10. {
11. userID=aotonomic_number;
12. System.out.println("账号为:"+userID);
13. aotonomic_number++;
14. }
15.
16. public double getBalance()
17. {
18. return balance;
19. }
20.
21. public void setBalance(double balance)
22. {
23. this.balance = balance;
24. }
25. public String toString()
26. {
27. return "Account [账号" + userID + ", 密码" + password + ", 存款余额"
28. + deposit + ", 利率" + rate + ", 最小余额" + balance + "]";
29. }
30.
31. public int getUserID()
32. {
33. return userID;
34. }
35.
36. public void setUserID(int userID)
37. {
38. this.userID = userID;
39. }
40.
41. public int getPassword()
42. {
43. return password;
44. }
45.
46. public void setPassword(int password)
47. {
48. this.password = password;
49. }
50.
51. public double getDeposit()
52. {
53. return deposit;
54. }
55.
56. public void setDeposit(double deposit)
57. {
58. this.deposit = deposit;
59. }
60.
61. public double getRate()
62. {
63. return rate;
64. }
65.
66. public void setRate(double rate)
67. {
68. this.rate = rate;
69. }
70. }
71.
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Account user1=new Account();
Account user2=new Account();
Account user3=new Account();
Scanner reader = new Scanner(System.in);
System.out.println("设置密码:");
user1.setPassword(reader.nextInt());
user2.setPassword(reader.nextInt());
user3.setPassword(reader.nextInt());
System.out.println("输入存款:");
user1.setDeposit(reader.nextDouble());
user2.setDeposit(reader.nextDouble());
user3.setDeposit(reader.nextDouble());
System.out.println("输入利率:");
user1.setRate(reader.nextDouble());
user2.setRate(reader.nextDouble());
user3.setRate(reader.nextDouble());
System.out.println("输入最小余额:");
user1.setBalance(reader.nextDouble());
user2.setBalance(reader.nextDouble());
user3.setBalance(reader.nextDouble());
System.out.println(user1.toString()+'\n'+user2.toString()+'\n'+user3.toString());
}
}
标签:状态,Account,double,userID,模式,reader,public,nextDouble
From: https://www.cnblogs.com/yzx-sir/p/17903910.html