模拟自助取款机操作--java小程序
2018-01-16 15:25
316 查看
import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.util.Scanner; public class Account { public int balance; public int Staticbalance; protected int AccountNumber; protected String IDcard; protected String Name; protected String Adrees; protected String password; public Account() { } public Account(String IDcard, String Name, String Adress, String password, int balance) { this.IDcard = IDcard; this.Name = Name; this.Adrees = Adress; this.password = password; this.balance = balance; } public void setStaticbalance(int Staticbalance) { this.Staticbalance = Staticbalance; } public void setAccountNumber() { AccountNumber = (int) (Math.random() * 1000000000); } public void setBalance(int balance) { this.balance = balance; } public void setIDcard(String IDcard) { this.IDcard = IDcard; } public void setName(String Name) { this.Name = Name; } public void setAdrees(String Adress) { this.Adrees = Adress; } public void setPassword(String password) { this.password = password; } public String getName() { return Name; } public String getAdrees() { return Adrees; } public String getIDcard() { return IDcard; } public int getAccountNumber() { return AccountNumber; } public int getStaticbalance() { return Staticbalance; } public String getPassword() { return password; } public int getbalance() { return balance; } public void setbalance(int balance) { this.balance = balance; } public void setAccount() throws UnsupportedEncodingException { Scanner sc = new Scanner(System.in); System.out.println("请输入姓名:"); String q = sc.nextLine(); setName(q); System.out.println("请输入身份证:"); String p = sc.nextLine(); setIDcard(p); System.out.println("请输入地址:"); String o = sc.nextLine(); o = new String(o.getBytes("GBK"),Charset.defaultCharset()); //输入中文,要转换编码格式 setAdrees(o); setBalance(100); setAccountNumber(); } public void deposite() { System.out.println("请输入你需要存的现金:"); Scanner sc = new Scanner(System.in); int w = sc.nextInt(); System.out.println("1.活期 2.定期"); int s = sc.nextInt(); if (s == 1) balance = balance + w; else { Staticbalance = Staticbalance + w; System.out.println("最低存一年 一年内不可取"); } } public void withdraw() { System.out.println("请输入你要取得钱"); Scanner sc = new Scanner(System.in); int w = sc.nextInt(); if (balance > w) balance = balance - w; else System.out.println("您的余额不足!\n您的活期为" + balance + "定期为" + Staticbalance); } }
import java.io.UnsupportedEncodingException; import java.util.Scanner; public class Main { public static void main(String[] args) throws UnsupportedEncodingException { char choise; int i = 0; boolean flag;//判断标识 Scanner sc = new Scanner(System.in); Account[] array = new Account[100]; for (int n = 0; n < 100; n++) { array = new Account("asd", "asd", "asd", "asd", 1); } do { System.out.println("------------------------------------------------"); System.out.println("| Welcome to the BUU IT Wisdom Bank |"); System.out.println("| What may I help you? |"); System.out.println("| 1.开户 |"); System.out.println("| 2.销户 |"); System.out.println("| 3.按姓名查询 |"); System.out.println("| 4.按账号查询 |"); System.out.println("| 5.存钱 |"); System.out.println("| 6.取钱 |"); System.out.println("------------------------------------------------"); System.out.println(""); System.out.println("| Enter choice 1-6: |"); System.out.println(""); choise=sc.next().charAt(0); System.out.println(); switch (choise) { case '1': System.out.println("---1.开户---"); array[i] = new Account(); array[i].setAccount(); i++; break; case '2': System.out.println("---2.销户---"); System.out.println("请输入要删除的姓名或账号:"); String t = sc.next(); flag = false; for (int y = 0; y < 100; y++) { if (array[y].getName().equals(t)) { System.out.println("删除成功"); flag = true; break; } else { continue; } } if(flag == false){ System.out.println("找不到"); } break; case '3': System.out.println("---3.按姓名查询---"); System.out.println("请输入要查找的姓名:"); String u = sc.next(); flag = false; for (int y = 0; y < 100; y++) { if (array[y].getName().equals(u)) { System.out.println("查询的姓名为:"+array[y].getName()); System.out.println("您的账号为:"+array[y].getAccountNumber()); System.out.println("您的余额为"+array[y].getbalance()); System.out.println("地址为:"+array[y].getAdrees()); flag = true; break; } else{ continue; } } if(flag == false){ System.out.println("不存在"); } break; case '4': System.out.println("---4.按账号查询 ---"); System.out.println("请输入要查找的账号:"); int m = sc.nextInt(); flag = false; for (int y = 0; y < 100; y++) { if (array[y].getAccountNumber() == m) { System.out.println("查询的姓名:" + array[y].getName()); System.out.println("您的账号为:" + array[y].getAccountNumber()); System.out.println("您的余额为" + array[y].getbalance()); System.out.println("地址为:" + array[y].getAdrees()); flag = true; } else break; } if(flag == false){ System.out.println("不存在"); } break; case '5': System.out.println("---5.存钱---"); System.out.println("请输入您的账号:"); int qw = sc.nextInt(); for (int y = 0; y < 100; y++) { if (array[y].getAccountNumber() == qw) { array[y].deposite(); } else break; } break; case '6': System.out.println("---6.取钱 ---"); System.out.println("请输入您的账号:"); Scanner qwe = new Scanner(System.in); int qwr = qwe.nextInt(); //qwe.close(); for (int y = 0; y < 100; y++) { if (array[y].getAccountNumber() == qwr) { array[y].withdraw(); } else break; } break; case '7': System.out.println("Quit Succsess"); sc.close(); break; default: System.out.println("illegl entry"); } } while (choise != '7'); } }
------------------------------------------------ | Welcome to the BUU IT Wisdom Bank | | What may I help you? | | 1.开户 | | 2.销户 | | 3.按姓名查询 | | 4.按账号查询 | | 5.存钱 | | 6.取钱 | ------------------------------------------------ | Enter choice 1-6: | 1 ---1.开户--- 请输入姓名: test 请输入身份证: 321122333313455532 请输入地址: 杭州市西湖区人民大道 ------------------------------------------------ | Welcome to the BUU IT Wisdom Bank | | What may I help you? | | 1.开户 | | 2.销户 | | 3.按姓名查询 | | 4.按账号查询 | | 5.存钱 | | 6.取钱 | ------------------------------------------------ | Enter choice 1-6: | 3 ---3.按姓名查询--- 请输入要查找的姓名: test 查询的姓名为:test 您的账号为:80586447 您的余额为100 地址为:杭州市西湖区人民大道 ------------------------------------------------ | Welcome to the BUU IT Wisdom Bank | | What may I help you? | | 1.开户 | | 2.销户 | | 3.按姓名查询 | | 4.按账号查询 | | 5.存钱 | | 6.取钱 | ------------------------------------------------ | Enter choice 1-6: | 4 ---4.按账号查询 --- 请输入要查找的账号: 80586447 查询的姓名:test 您的账号为:80586447 您的余额为100 地址为:杭州市西湖区人民大道 ------------------------------------------------ | Welcome to the BUU IT Wisdom Bank | | What may I help you? | | 1.开户 | | 2.销户 | | 3.按姓名查询 | | 4.按账号查询 | | 5.存钱 | | 6.取钱 | ------------------------------------------------ | Enter choice 1-6: | 5 ---5.存钱--- 请输入您的账号: 80586447 请输入你需要存的现金: 3 1.活期 2.定期 1 ------------------------------------------------ | Welcome to the BUU IT Wisdom Bank | | What may I help you? | | 1.开户 | | 2.销户 | | 3.按姓名查询 | | 4.按账号查询 | | 5.存钱 | | 6.取钱 | ------------------------------------------------ | Enter choice 1-6: | 4 ---4.按账号查询 --- 请输入要查找的账号: 80586447 查询的姓名:test 您的账号为:80586447 您的余额为103 地址为:杭州市西湖区人民大道 ------------------------------------------------ | Welcome to the BUU IT Wisdom Bank | | What may I help you? | | 1.开户 | | 2.销户 | | 3.按姓名查询 | | 4.按账号查询 | | 5.存钱 | | 6.取钱 | ------------------------------------------------ | Enter choice 1-6: | 6 ---6.取钱 --- 请输入您的账号: 80586447 请输入你要取得钱 5 ------------------------------------------------ | Welcome to the BUU IT Wisdom Bank | | What may I help you? | | 1.开户 | | 2.销户 | | 3.按姓名查询 | | 4.按账号查询 | | 5.存钱 | | 6.取钱 | ------------------------------------------------ | Enter choice 1-6: | 4 ---4.按账号查询 --- 请输入要查找的账号: 80586447 查询的姓名:test 您的账号为:80586447 您的余额为98 地址为:杭州市西湖区人民大道 ------------------------------------------------ | Welcome to the BUU IT Wisdom Bank | | What may I help you? | | 1.开户 | | 2.销户 | | 3.按姓名查询 | | 4.按账号查询 | | 5.存钱 | | 6.取钱 | ------------------------------------------------ | Enter choice 1-6: | 2 ---2.销户--- 请输入要删除的姓名或账号: test 删除成功 ------------------------------------------------ | Welcome to the BUU IT Wisdom Bank | | What may I help you? | | 1.开户 | | 2.销户 | | 3.按姓名查询 | | 4.按账号查询 | | 5.存钱 | | 6.取钱 | ------------------------------------------------ | Enter choice 1-6: | 7 Quit Succsess
相关文章推荐
- 一个用java模拟ATM操作的小程序
- java操作外部程序
- CORBA技术系列一:JAVA客户程序与C++服务程序互操作
- C#程序模拟鼠标操作 [Simulate Mouse Movement and Click Programmatically](转)
- 用java模拟浏览器程序
- 程序模拟键盘鼠标操作
- C#程序模拟鼠标操作 [Simulate Mouse Movement and Click Programmatically]
- 编写操作数据库的JAVA程序时需要的连接MySQL数据库的JDBC连接包mysql-connector-java-5.1.10.zip怎么安装
- java模拟系统进程算法的小程序
- 如何在c#程序中模拟域帐户进行登录操作
- 使用java程序模拟页面发送http的post请求
- 如何在c#程序中模拟域帐户进行登录操作
- java模拟--杀毒程序
- 用java模拟写字板程序
- 关于在Java程序当中创建对象等基本操作的性能测试
- Java模拟POST表单操作 HttpClient的应用及注意事项
- java模拟系统进程算法的小程序
- JAVA 实现多文件同时操作 程序代码
- java模拟银行交易系统程序
- 用java写的远程监控程序,可以看到别人计算机上正在进行的操作(2)