ATM机程序Linux,c语言模拟银行ATM机程序

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.util.Calendar;

public class userlogin {

static ATM1 atm =new ATM1();  // 创建一个实例

static String[] a =new String[10];  //最近9次交易的清单

static int k=0;

public static String selectTime (){

//用于获取交易时间

Calendar c = Calendar.getInstance();

String

time1=c.get(Calendar.YEAR)+"年"+c.get(Calendar.MONTH)+"月"+

c.get(Calendar.DATE)+"日"+

c.get(Calendar.HOUR_OF_DAY)+"时"+

+

c.get(Calendar.MINUTE)+"分"+c.get(Calendar.SECOND)+"秒";

return time1;

}

public static void login(){

//登录页面

int

username,userpass,name,pass;  //账号与密码

name=atm.getusername();

pass=atm.getuserpass();

System.out.println("欢迎使用银行自主服务终端机");

try{

BufferedReader in =new

BufferedReader(new InputStreamReader(System.in));

System.out.println("请输入账号:");

String

inputLine=in.readLine();

username

=Integer.valueOf(inputLine).intValue();

System.out.println("请输入密码:");

String

inputLine1=in.readLine();

userpass

=Integer.valueOf(inputLine1).intValue();

}catch(Exception

exc){

return;

}

if((userpass==pass)&&(username==name)){

int choice=-1;

while(choice!=0){

choice=selectServer();

handle(choice);

}

}

else

System.out.println("账号或密码错误");

}

//

public static int selectServer(){

//显示服务并返回用户的选择结果

System.out.println("\n\n=============\n");

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("0.退出");

System.out.println("\n\n=============\n");

//用户选择

int choice=-1;

try{

BufferedReader in =new BufferedReader(new

InputStreamReader(System.in));

System.out.println("请选择服务(0--6):\n");

String inputLine=in.readLine();

choice =Integer.valueOf(inputLine).intValue();

}catch(Exception exc){

}

return choice;

}

//对用户的选择结果choice分别作处理

public static void handle(int choice){

switch(choice){

//查询帐户当前的余额

case 1:

double balance =atm.getBalance();

System.out.println("您的余额为:" +balance );

break;

//向帐户取款,取款金额为amount

case 2:

double amount;

int choice1;  //是否确定取款

System.out.println("请输入取款金额:");

try{

BufferedReader in =new BufferedReader(new

InputStreamReader(System.in));

String inputLine=in.readLine();

amount =Double.valueOf(inputLine).doubleValue();

}

catch(Exception exc){

return;

}

System.out.println("您确定取"+amount+"元吗?");

System.out.println("确定请按1");

System.out.println("取消请按0");

try{

BufferedReader in =new BufferedReader(new

InputStreamReader(System.in));

String inputLine=in.readLine();

choice1 =Integer.valueOf(inputLine).intValue();

}

catch(Exception exc){

return;

}

boolean isa,iswithdraw=false;

if(choice1==1){

isa=true;

iswithdraw =atm.withdraw(amount);

}

else isa=false;

if(iswithdraw && isa){

System.out.println("交易成功");

if(k<9){

k=k+1;

a[k]=selectTime()+"取款 "+amount+"元";

}else {

k=0;

k++;

}

try{

BufferedReader in =new BufferedReader(new

InputStreamReader(System.in));

System.out.println("是否打印凭条:");

System.out.println("1.打印凭条");

System.out.println("0.不打印凭条");

String

inputLine=in.readLine();

int choice2

=Integer.valueOf(inputLine).intValue();

if(choice2==1)System.out.println(selectTime()+"取款

"+amount+"元");

}

catch(Exception

exc){

return;

}

}

else System.out.println("交易失败");

break;

//向帐户存款,存款金额为amount

case 3:

double amount1;

try{

System.out.println("请输入存款金额:");

BufferedReader in =new BufferedReader(new

InputStreamReader(System.in));

String inputLine=in.readLine();

amount1 =Double.valueOf(inputLine).doubleValue();

atm.deposit(amount1);

System.out.println("交易成功");

if(k<9){

k=k+1;

a[k]=selectTime()+"存款 "+amount1+"元";

}else {

k=0;

k++;

}

try{

BufferedReader in1 =new BufferedReader(new

InputStreamReader(System.in));

System.out.println("是否打印凭条:");

System.out.println("1.打印凭条");

System.out.println("0.不打印凭条");

String

inputLine1=in1.readLine();

int choice2

=Integer.valueOf(inputLine1).intValue();

if(choice2==1)System.out.println(selectTime()+"存款

"+amount1+"元");

}

catch(Exception

exc){

return;

}

}

catch(Exception exc){

}

break;

//修改帐户密码

case 4:

System.out.println("请输入新密码:");

int userpass1,userpass2;

try{

BufferedReader in =new BufferedReader(new

InputStreamReader(System.in));

String inputLine=in.readLine();

userpass1 =Integer.valueOf(inputLine).intValue();

}

catch(Exception exc){

return;

}

System.out.println("请再次输入密码:");

try{

BufferedReader in =new BufferedReader(new

InputStreamReader(System.in));

String inputLine=in.readLine();

userpass2 =Integer.valueOf(inputLine).intValue();

}

catch(Exception exc){

return;

}

if(userpass1==userpass2){

atm.updatepass(userpass2);

System.out.println("修改密码成功:");

System.out.println("您新密码为:"+atm.getuserpass());

}

else System.out.println("修改密码失败:");

break;

//退出

case 0:

System.out.println("谢谢使用ATM再见");

break;

case 5:

int user;

double amount11;

try{

System.out.println("请输入转入账号:");

BufferedReader in =new BufferedReader(new

InputStreamReader(System.in));

String inputLine=in.readLine();

user =Integer.valueOf(inputLine).intValue();

System.out.println("请输入转账金额:");

String inputLine1=in.readLine();

amount11 =Double.valueOf(inputLine1).doubleValue();

atm.withdraw(amount11);

System.out.println("交易成功");

if(k<9){

k=k+1;

a[k]=selectTime()+"向"+user+"转账 "+amount11+"元";

}else {

k=0;

k++;

}

try{

BufferedReader in1 =new BufferedReader(new

InputStreamReader(System.in));

System.out.println("是否打印凭条:");

System.out.println("1.打印凭条");

System.out.println("0.不打印凭条");

String

inputLine11=in1.readLine();

int choice2

=Integer.valueOf(inputLine11).intValue();

if(choice2==1)System.out.println(selectTime()+"存款

"+amount11+"元");

}

catch(Exception

exc){

return;

}

}

catch(Exception exc){

}

break;

case 6:

for(k=1;k<10;k++)

System.out.println(a[k]);

}

}

//主程序

public static void main (String [] args){

System.out.println("刚开始时帐号为123,密码为123");

login();

}

}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值