模拟atm机java代码 java自动取款机模拟系统

Java编程实现程序用于模拟ATM取款机 。package demo;
import java.util.Scanner;
public class Test3 {
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
int cnt=3;
String username = null;
String password = null;
double money = 1000;
String targetName = "admin33";
double targetMoney = 1000;
while(true){
if(username!=nullpassword!=null){
if("admin".equals(username)"123".equals(password)){
System.out.println("欢迎光临");
while(true){
System.out.println("请选择您的操作 1 取钱 2 存钱 3 转账 4 查询 5 退出 ");
int n = scanner.nextInt();
if(n==1){//取钱
System.out.println("请输入金额");
int getter = scanner.nextInt();
if(getter=0){
if(getter=5000){
if(getter=money){
money-=getter;
}else{
System.out.println("余额不足");
}
}else{
System.out.println("单笔只能取5000及以下");
}
}else{
System.out.println("银行不到给");
}
}else if(n==2){//存钱
System.out.println("请输入金额");
int save = scanner.nextInt();
if(save=0){
money+=save;
}
}else if(n==3){//转账
System.out.println("请输入目标账户");
String target= scanner.next();
if(target.equals(targetName)){
System.out.println("请输入金额");
int getter = scanner.nextInt();
if(getter=0){
if(getter=5000){
if(getter=money){
money-=getter;
targetMoney+=getter;
}else{
System.out.println("余额不足");
}
}else{
System.out.println("单笔只能取5000及以下");
}
}else{
System.out.println("银行不到给");
}
}
}else if(n==4){//查询
System.out.println(money);
}else if(n==5){//退出
System.exit(0);
}else{
System.out.println("没有该项服务");
}
}
}else{
cnt--;
System.out.println("输入错误,您还有"+cnt+"次机会");
username=null;
password=null;
if(cnt=0){
System.out.println("对不起,您的账号被冻结,请到最近的营业厅解除冻结");
System.exit(0);
}
}
}else{
System.out.println("请输入您的账号");
username = scanner.next();
System.out.println("请输入您的密码");
password = scanner.next();
}
}
}
}
求Java代码 模拟简易atm机参考了别人的代码 。略作修改,已经很简单了:
InfoATM.java:
public class InfoATM {
double money = 0;
public InfoATM(double cash) {
super();
this.money = cash;
}
// 存款的方法
public void save(double count) {
money += count;
}
// 取款的方法
public void draw(double count) {
money -= count;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
}
TestATM.java:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class TestATM extends JFrame {
private static final long serialVersionUID = 2531222181184935595L;
// 主面板pnBasic是用来装pnDate和标签文字的 。
private JPanel pnBasic;
// 添加到主面板中的中间 pnDate面板是为了装表单的 。
private JPanel pnDate;
// 添加到主面板中的北边 pnLabel面板是为了装欢迎词的
private JPanel pnLabel;
InfoATM atm = new InfoATM(0);
public TestATM() {
pnBasic = new JPanel();

推荐阅读