You are to implement an Automatic Teller Machine (ATM) for a small bank. Each da
ID: 3725717 • Letter: Y
Question
You are to implement an Automatic Teller Machine (ATM) for a small bank. Each day, the machine is started up by the bank’s IT support. At this time, the ATM reads a list of current accounts, Personal Id Numbers (PINs), and account balances from a file.
Once started, customers use the ATM to make deposits, withdrawals and balance inquiries. For each customer, the ATM asks for and validates the account number and PIN
number, then performs the deposit/withdrawal/balance-inquiry for the customer. For each successful withdrawal and deposit, the ATM maintains a list of transactions, including
account number and amount for each, and updates the account’s current balance. The ATM is limited to a maximum number of total withdrawal/deposit transactions it can process per day, and will refuse to do deposits and withdrawals once this limit is surpassed.
At the end of the day, IT support enters a secret account number and PIN (10000 and 1000). Once entered, the ATM shuts down, writing the list of transactions to a file. About the
data: - Account Numbers are length 12 or less, made up of any characters, but no white space. - PINs are integers of four digits. - Balances are assumed to not exceed $ 99999.99
Detailed Description: Start Up: - The logo is displayed, and a startup message printed. - The account file is read in. When there is an error reading the file, an error message is
printed and the shutdown process (see below) is completed. When there is not an error, a report of the account data read from the file is printed. File format: - File name:
“accounts.txt” - First Line: the number of accounts - Each following line, one per account: account# pin and balance, separated by a space. - The ATM then proceeds to processing customers.
Processing a Customer: this process is repeated until the shutdown account and PIN are entered. - The logo is displayed. - The user is asked to enter an account number and PIN.
When an invalid account/pin are entered (not on the list read at startup, and not the shutdown code), the ATM reports an error and this process is finished. When a valid
account/pin are entered, the ATM proceeds to the next step. - When the secret shutdown codes are entered, the ATM proceeds to the shutdown process. - When a valid
account/pin is entered: A menu with options Deposit, Withdraw, and Balance Inquiry is presented. The user selects one of the options (D,W,B). The user may enter an entire string
(ie. Withdraw) but the ATM only looks at the first character entered. It also accepts both upper and lower case entries. When an invalid entry is made, an error message is printed
and the menu repeats until the user enters a valid option. - Withdrawal: The customer is asked for a withdrawal amount. When the amount is: o less than 0.00: print Invalid amount!
Enter a value 0.00 or greater o greater than the account’s balance: print Your account only has $ currentBalance o 0: print Transaction canceled and end the process for this
customer o Valid (more than 0 and less/equal the Balance): the account balance is updated a Transaction is added to the ATM’s transaction list with account number and
(negative) amount. Prints: Transaction complete. Your new balance is now: $ newCurrentBalance Except: If the maximum number of transactions for the ATM is exceeded,
just print: Transaction cannot be done. Contact IT Support. - Deposit: The customer is asked for a deposit amount. When the amount is:
Explanation / Answer
Below is the Tested Code for this Question :
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package cheggquestions;
import java.util.*;
import java.io.*;
/**
*
* @author Prashant Tomer
*/
public class MyAtm
{
static List<String> accsummary=new ArrayList<>(); //I Just retrieve data from from file and added into this file.
boolean verification(String acc,String id) //This Method verified the user if it it is available in our data or not
{
String fileid[]=new String[3];
boolean status=false;
int i=-1;
for(String str2:accsummary) //Loop for read every element from Arraylist(accsummary)
{
StringTokenizer st=new StringTokenizer(str2," "); //Now Tokenizer just split the accnumber,id number and amount is now stored in ArrayList as a object
while(st.hasMoreTokens())
{
++i;
//System.out.println(st.nextToken());
fileid[i]=st.nextToken();
}
if(fileid[0].equalsIgnoreCase(acc) & fileid[1].equalsIgnoreCase(id)) //verify if both data match or not
{
status=true;
}
i=-1;
}
return status;
}
public static void main(String args[] ) throws FileNotFoundException, IOException
{
MyAtm atm=new MyAtm();
int balance = 5000, withdraw, deposit;
Scanner s = new Scanner(System.in);
String str="";
String str1="";
String id="";
String accno="";
//Map <String,List<String>> accsummary=new HashMap();
FileReader read=new FileReader("D://accountsummary.txt");
BufferedReader bfr=new BufferedReader(read);
while((str=bfr.readLine())!=null)
{
str1=str1+str;
accsummary.add(str1);
str1="";
}
System.out.println(new MyAtm().verification("19826", "3135"));
while(true)
{
System.out.println("Welcome to Automated Teller Machine");
System.out.println("1. for Withdraw");
System.out.println("2. for Deposit");
System.out.println("3. for Check Balance");
System.out.println("4. for account summary");
System.out.println("5. for EXIT");
System.out.print("Please enter your choice from above option:");
int n = s.nextInt();
switch(n)
{
case 1:
System.out.print("Enter your Account number:");
accno=s.next();
System.out.print("Enter id:");
id=s.next();
if(atm.verification(accno, id)) // Verification with accno and id
{
System.out.print("Enter money to be withdrawn:");
withdraw = s.nextInt();
if(balance >= withdraw)
{
balance = balance - withdraw;
System.err.println("Please collect your money");
}
else
{
System.err.println("Insufficient Balance");
}
}
else
System.err.println("Not Valid User");
break;
case 2:
System.out.print("Enter money to be deposited:");
deposit = s.nextInt();
balance = balance + deposit;
System.out.println("Your Money has been successfully depsited");
System.out.println("");
break;
case 3:
System.out.println("Balance : "+balance);
System.out.println("");
break;
case 4:
case 5:
System.exit(0);
}
}
}
}
OUTPUT:
Welcome to Automated Teller Machine
1. for Withdraw
2. for Deposit
3. for Check Balance
4. for account summary
5. for EXIT
Please enter your choice from above option:
1
Enter your Account number:234567
Enter id:1234
Not Valid User
Welcome to Automated Teller Machine
1. for Withdraw
2. for Deposit
3. for Check Balance
4. for account summary
5. for EXIT
Please enter your choice from above option:1
Enter your Account number:19826
Enter id:3135
Enter money to be withdrawn:200
Please collect your money
Welcome to Automated Teller Machine
1. for Withdraw
2. for Deposit
3. for Check Balance
4. for account summary
5. for EXIT
Please enter your choice from above option:5
FILEDATA
ACCNo PIN Amount
19823 3434 23000.
19824 3535 1200
19825 3434 23000
19826 3135 1200
19827 3234 23000
19828 3335 1200
19829 3530 23000
19830 3333 1200
19831 3400 23000
19832 3539 1200
19833 3830 23000
19834 5535 1200
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.