源代码:
import java.util.Scanner;
interface fangfa{public void show();
public void qukuan();public void cunkuan();public void zhuanzhang();public void setAcount(String string, String string2, String string3, String string4, double i);public String getMima();}class atm implements fangfa{ String kahao; //私有变量String name;String riqi;double yue;String mima;public atm(){ //无参构造函数
}
public atm(String kahao,String name,String riqi,String mima,double yue){ //有参构造函数this.kahao=kahao;
this.name=name;this.riqi=riqi;this.mima=mima;this.yue=yue;}public void setAcount(String kahao,String name,String riqi,String mima,double yue){ //赋值
this.kahao=kahao;
this.name=name;this.riqi=riqi;this.mima=mima;this.yue=yue;}public String getkahao(){ return kahao;}//获得值public String getName(){return name;}
public String getRiqi(){return riqi;}public String getMima(){return mima;}public double getYue(){return yue;}public void show()
{ System.out.println("余额为:"+yue);}public void cunkuan(){ System.out.println("请输入存款金额:");Scanner s=new Scanner(System.in);yue+=s.nextDouble();show();}public void zhuanzhang()
{ atm q=new atm();Scanner s=new Scanner(System.in);System.out.println("请输入对方卡号:");q.kahao=s.nextLine();System.out.println("请输入转账金额:");double zhuan=s.nextDouble();yue=yue-zhuan;q.yue=q.yue+zhuan;show();}public void qukuan(){ boolean f=true;while(f){ System.out.println("1、100元");System.out.println("2、500元");System.out.println("3、1000元");System.out.println("4、1500元");System.out.println("5、2000元");System.out.println("6、5000元");System.out.println("7、其他金额");System.out.println("8、退卡");System.out.println("9、返回");System.out.println("请选择");Scanner s=new Scanner(System.in);int ch=s.nextInt();switch(ch){ case 1:yue=yue-100;show();break;case 2:yue=yue-500;show();break;case 3:yue=yue-1000;show();break;case 4:yue=yue-1500;show();break;case 5:yue=yue-2000;show();break;case 6:yue=yue-5000;show();break;case 7:System.out.println("请输入取款金额:");double qu=s.nextDouble();yue=yue-qu;show();break;case 8:f=false;break;case 9:f=false;break;}
}}}
public class ABC { public static void main(String[] args) { // TODO Auto-generated method stubfangfa a=new atm();
a.setAcount("111111111111", "nasdf", "199508030048", "123456", 20000);System.out.println("请输入密码:");Scanner aa=new Scanner(System.in);String ba=aa.nextLine();if(ba.equals(a.getMima()))while(true){
System.out.println("1、取款");
System.out.println("2、存款");System.out.println("3、转账");System.out.println("4、查询");System.out.println("请选择:");Scanner s=new Scanner(System.in);int b=s.nextInt();switch(b){ case 1:a.qukuan();break;case 2:a.cunkuan();break;case 3:a.zhuanzhang();break;case 4:a.show();}}}}实验截图: