Java程序设计当堂测试 9.20
/*
Java当堂测试 ATM机模拟系统
由于学习的知识有限,不能完成所有课上项目,文件的应用没有完成,汇款转账功能也没有写,一些要求该退出的地方也没有写,基本功能还算完善
*/
1 package account; 2 3 import java.io.File; 4 import java.util.Scanner; 5 6 class Account 7 { 8 private String accountID; 9 private String accountname; 10 private String operatedate;//时间 11 private int operatetype;//操作 12 private String accountpassword;//密码 13 private int accountbalance;//余额 14 private int amout;//流水金额 15 16 public Account(String accid,String accna,String opeda,String password,int balance) 17 { 18 this.accountID=accid; 19 this.accountname=accna; 20 this.operatedate=opeda; 21 this.accountpassword=password; 22 this.accountbalance=balance; 23 } 24 25 public String getaccountID() 26 { 27 return accountID; 28 } 29 public String getaccountname() 30 { 31 return accountname; 32 } 33 public String getoperatedate() 34 { 35 return operatedate; 36 } 37 public int getoperatetype() 38 { 39 return operatetype; 40 } 41 public String getaccountpassword() 42 { 43 return accountpassword; 44 } 45 public int getaccountbalance() 46 { 47 return accountbalance; 48 } 49 public int getamout() 50 { 51 return amout; 52 } 53 public void setaccountID(String accid) 54 { 55 accountID=accid; 56 } 57 public void setaccountname(String accna) 58 { 59 accountname=accna; 60 } 61 public void setoperatedate(String opeda) 62 { 63 operatedate=opeda; 64 } 65 public void setoperatetype(int opety) 66 { 67 operatetype=opety; 68 } 69 public void setaccountpassword(String password) 70 { 71 accountpassword=password; 72 } 73 public void setaccountbalance(int balance) 74 { 75 accountbalance=balance; 76 } 77 public void setamout(int amo) 78 { 79 amout=amo; 80 } 81 82 public void menu() 83 { 84 System.out.println("**************************************************************************"); 85 System.out.println(" 欢迎"+accountID+"使用中国工商银行自助柜员系统 "); 86 System.out.println("**************************************************************************"); 87 } 88 89 public void Manage() 90 { 91 Scanner scan1=new Scanner(System.in); 92 int a; 93 int b; 94 int c; 95 String s; 96 String s1; 97 switch(operatetype) 98 { 99 case 1:System.out.println("请输入存款金额 : "); 100 a=scan1.nextInt(); 101 accountbalance+=a; 102 System.out.println("存取款操作完成"); 103 System.out.println("存款余额为 :"+accountbalance); 104 //差一个try语句; 105 break; 106 case 2:System.out.println("当前账户每日可支取2万"); 107 System.out.println("1.100"); 108 System.out.println("2.500"); 109 System.out.println("3.1000"); 110 System.out.println("4.1500"); 111 System.out.println("5.2000"); 112 System.out.println("6.5000"); 113 System.out.println("7.其他金额"); 114 b=scan1.nextInt(); 115 switch(b) 116 { 117 case 1:accountbalance-=100;break; 118 case 2:accountbalance-=500;break; 119 case 3:accountbalance-=1000;break; 120 case 4:accountbalance-=1500;break; 121 case 5:accountbalance-=2000;break; 122 case 6:accountbalance-=5000;break; 123 case 7:System.out.println("输入金额 :");c=scan1.nextInt();accountbalance-=c;break; 124 }; 125 System.out.println("取取款操作完成"); 126 System.out.println("存款余额为 :"+accountbalance); 127 break; 128 case 3:break; 129 case 4: 130 System.out.println("请输入修改后的密码"); 131 s1=scan1.nextLine(); 132 accountpassword=s1;//修改密码 133 System.out.println("修改成功,当前密码为"+accountpassword); 134 case 5:System.out.println("当前账户余额为:"+accountbalance); 135 } 136 137 }//六项操作 138 139 } 140 141 public class acc { 142 143 public static void main(String[] args) { 144 // TODO Auto-generated method stub 145 146 147 File file1 = new File("accountlist.txt"); 148 File file2 = new File("accountinformation.txt"); 149 int i; 150 int j=0; 151 int t=0; 152 int b; 153 String c; 154 System.out.println("**************************************************************************"); 155 System.out.println(" 欢迎使用中国工商银行自动柜员系统 "); 156 System.out.println("**************************************************************************"); 157 System.out.println(" 请输入您的账号:"); 158 159 Account[] a = new Account[5]; 160 Account s1=new Account("20173427","冯利伟","2018-9-20","123456",500000); 161 Account s2=new Account("00000001","张都","2018-9-20","123456",10000); 162 Account s3=new Account("00000002","王万茜","2018-9-20","123456",5200); 163 Account s4=new Account("00000003","李三大","2018-9-20","123456",500); 164 Account s5=new Account("00000004","赵滨南","2018-9-20","123456",400); 165 a[0]=s1; 166 a[1]=s2; 167 a[2]=s3; 168 a[3]=s4; 169 a[4]=s5; 170 171 String id; 172 String password; 173 Scanner scan=new Scanner(System.in); 174 id=scan.next(); 175 for(i=0;i<5;i++) 176 { 177 if(id==a[i].getaccountID()) 178 j=i; 179 } 180 181 182 a[j].menu(); 183 System.out.println(" 请输入密码"); 184 password=scan.next(); 185 186 a[j].menu(); 187 System.out.println("1.存款"); 188 System.out.println("2.取款"); 189 System.out.println("3.转账汇款"); 190 System.out.println("4.修改密码"); 191 System.out.println("5.查询余额"); 192 System.out.println("6.退出"); 193 System.out.println("请输入要实现的功能 :"); 194 b=scan.nextInt(); 195 while(b!=6) 196 { 197 a[j].setoperatetype(b);//将操作数字赋值给类成员 198 199 a[j].Manage(); 200 a[j].menu(); 201 System.out.println("1.存款"); 202 System.out.println("2.取款"); 203 System.out.println("3.转账汇款"); 204 System.out.println("4.修改密码"); 205 System.out.println("5.查询余额"); 206 System.out.println("请输入要实现的功能 :"); 207 b=scan.nextInt(); 208 } 209 210 211 212 } 213 214 }
由于初学,所以参考了许多别人代码,相信随着练习的增多,这种情况会越来越少。