所以这是我的源代码:
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.*;
public class ATM {
String names []= {"Nikhil", "Furrqaan", "Raj", "Saron", "Abishiek", "Aditya"};
static int pin_no;static int card_no;
static int card[]={1806978,1244668,5769124,7658301,6571354,5155499};
static int pin[]={4444, 3333, 2222, 1111, 6666, 7988};
int balance []={17867, 23345, 24670, 37532, 43637, 37356};
int account[]={219075286,156482798,456482748,465295772,665793758,565738957};
int f,ch,z;
static int r = 0;
static int opt=0;
Scanner s=new Scanner(System.in);
public static void main(String args []) {
int pincode=0;
int repeat=0;
ATM k=new ATM();
do{
k.info();
k.login();
for(int choice=0;choice<=5;choice++)
if(card_no==card[choice] && pin_no==pin[choice]){
k.menu(choice);
break;
}else{
System.out.println("Wrong card no. or pincode");
break;
}
k.End(repeat);
}while(k.End(repeat)==0);
}
void info(){
Calendar calender = Calendar.getInstance();
SimpleDateFormat dateformatter = new SimpleDateFormat(" dd EEEEEEEEE',' yyyy ");
SimpleDateFormat timeformatter = new SimpleDateFormat(" hh:mm:ss a");
System.out.println("");
System.out.println(" **************************************************************** ");
System.out.println(" *** HSBC's ATM **** ");
System.out.println(" **************************************************************** ");
System.out.println(" Date - "+ dateformatter.format(calender.getTime()));
System.out.println(" Time - "+timeformatter.format(calender.getTime()));
System.out.println(" **************************************************************** ");
System.out.println("");
}
void login (){
System.out.println(" >> Enter card number - ");
card_no=s.nextInt();
System.out.println(" >> Enter pin number - ");
pin_no= s.nextInt();
}
void menu (int choice){
System.out.println(" Welcome "+names[choice]);
System.out.println(" Your Account no: is " + account[choice]);
System.out.println(" ############################################### ");
System.out.println(" >>> [1]. Cash Withdrawal ");
System.out.println("");
System.out.println(" >>> [2]. Fast Cash ");
System.out.println("");
System.out.println(" >>> [3]. Cash Deposit ");
opt=s.nextInt();
switch (opt){
case 1:
Calendar calender = Calendar.getInstance();
SimpleDateFormat dateformatter = new SimpleDateFormat(" dd'/'MM ");
SimpleDateFormat timeformatter = new SimpleDateFormat(" HH:mm ");
ATM k=new ATM();
int ammount;
System.out.println(" ========================== ");
System.out.println(" CASH WITHDRAWAL ");
System.out.println(" ========================== ");
System.out.print(" Enter amount to withdraw - Rs.");
ammount=s.nextInt();
System.out.println(" ::::::::::::::::::::::::::::::::::::::::::::::");
System.out.println(" Please wait while we process your request...");
if (ammount>balance[z]){
System.out.println(" You do not have sufficient balance in your account.");
k.menu(choice);
for(z=1;z<=1000000000;z++)
System.out.print("\f");
}else if (ammount>25000){
System.out.println(" The daily limit for cash withdrawal is Rs.25000 .");
k.menu(choice);
}else{
balance[z]=balance[z]-ammount;
System.out.println("");
System.out.println(" You have withdrawn Rs."+ammount+" from your account.");
System.out.println(" Please collect the cash.");
System.out.println(" Current Balance - Rs."+balance[z]);
System.out.println(" ::::::::::::::::::::::::::::::::::::::::::::::");
}
break;
case 2:
int fast[]={100,500,1000,5000};
System.out.println(" ========================== ");
System.out.println(" FAST CASH WITHDRAWAL ");
System.out.println(" ========================== ");
System.out.println(" Please select a desired amount.");
System.out.println(" (1) Rs. 100 ");
System.out.println(" (2) Rs. 500 ");
System.out.println(" (3) Rs. 1000 ");
System.out.println(" (4) Rs. 5000 ");
System.out.print(" Your choice ? ");
ch=s.nextInt();
if (fast[ch-1]>balance[z])
{
System.out.println(" You do not have sufficient balance in your account.");
}else{
switch(ch)
{
case 1:
balance[z]=balance[z]-fast[ch-1];
break;
case 2:
balance[z]=balance[z]-fast[ch-1];
break;
case 3:
balance[z]=balance[z]-fast[ch-1];
break;
case 4:
balance[z]=balance[z]-fast[ch-1];
break;
}
}
System.out.println("");
System.out.println(" You have withdrawn Rs. "+fast[ch-1]+" from your account.");
System.out.println(" Please collect the cash.");
System.out.println(" Current Balance - Rs."+balance[z]);
System.out.println(" ::::::::::::::::::::::::::::::::::::::::::::::");
break;
case 3:
System.out.println(" ========================== ");
System.out.println(" CASH DEPOSIT ");
System.out.println(" ========================== ");
System.out.print(" Enter amount to deposit - Rs.");
int deposite =s.nextInt();
System.out.println(" ::::::::::::::::::::::::::::::::::::::::::::::");
System.out.println(" Please wait while we process your request...");
System.out.println("");
System.out.println(" You have deposited Rs."+deposite+" to your account.");
System.out.println(" The amount will be credited shortly.");
System.out.println(" Current Balance - Rs."+balance[z]+" + Rs."+deposite);
System.out.println(" ::::::::::::::::::::::::::::::::::::::::::::::");
break;
case 4:
System.out.println(" ========================== ");
System.out.println(" BALANCE ENQUIRY ");
System.out.println(" ========================== ");
System.out.println(" Account Number - "+card[z]);
System.out.println(" Available Balance - Rs."+balance[z]);
System.out.println(" ::::::::::::::::::::::::::::::::::::::::::::::");
System.out.println(" Please collect the reciept...");
}
}
int End(int repeat){
ATM k=new ATM();
System.out.println();
System.out.println(" What would you like to do next? ");
System.out.println(" [1]. Enter main menu. ");
System.out.println(" [2]. Exit. ");
int option=s.nextInt();
switch (option){
case 1:
repeat=0;
break;
case 2:
repeat=1;
break;
default:
System.out.println("Please check input.");
}
return repeat;
}
}
唯一有效的卡号和密码组合是第一个。其他一切 打印错误消息,即“错误的密码或卡号”。程序的最后一个功能(无效重复)打印“你接下来想做什么?” 分两次。任何帮助表示赞赏。