编写一个程序模拟银行ATM交易系统:

ATM

package bank;

import java.util.Scanner;

public  class ATM  {
   
	
	private UnionCar unionCar;
	private int inputPSwCount =0;
	Scanner sc = new Scanner(System.in);
	
	
	public ATM(){
   
		
	}
	
	public boolean insertCar(Car car){
   
		inputPSwCount ++;
		if(inputPSwCount>3) return false;
		boolean flag = false;
		if(car instanceof UnionCar){
   
			this.unionCar = (UnionCar)car;			
			flag = true;
			System.out.println("请输入密码:");
			Scanner sc = new  Scanner(System.in);
			String psw = sc.nextLine();			
			if(unionCar.userCheck(psw)){
   
				//unionCar.showMenu();				
				doSome();
			}else{
   
				System.out.println("密码错误!");
				
				insertCar(car);
			}	
			sc.close();
						
		}else{
   			
			flag = false;
			System.out.println("插入的卡片无法识别!");
		}		
		return flag;		
	}
	
	public  void doSome(){
   		
		System.out.println("请选择业务类型:\n 1. 存款 \n 2.取款 \n 3.查询余额  \n 4.在线支付\n 0:退出" );
		Scanner sc = new Scanner(System.in);
		 int i = sc.nextInt();		 
		 switch(i){
   
		 case 1:
			 saveMoney();
			 break;
		 case 2:
			 drawMoney();
			 break;			 
		 case 3:
			 getBalance(true);
			 break;
		 case 4:
			 onlinePay();
			 break;
		 case 0:
			 System.out.println("请取走你的卡,欢迎下次光临!");
			 System.exit(0);
			 break;
			 default:
				 System.out.println(

你可能感兴趣的:(Java,java)