Write an application that simulates a simple Bank Automated Teller Machine (ATM).
This application provides a menu that allows a user to select the following operations:
Withdrawal
Deposit
Check Balance
Other requirements:
-Add an extra choice to let the user quit the system.
-After every withdrawal and deposit, display the current balance.
-Withdraw amount must be:
Less than or equal to current balance
In multiple of 10 (e.g amount of 1034.00 is not allowed)
-Before the menu is displayed, the user is authenticated by reading the account number and the pin number. The account number and the pin number enterd by the user must match with the account number and the pin number of the user account.
- Create a BankAcount object for every customer. Each BankAccount object contains:
- An account number
- The account’s owner name
- The pincode
- The account balance amount
- All relevant methods for a bank account (such as the getters & setters method, withdraw, deposit & checkbalance and the constructor.
- All values for every BankAccount objects are read and stored in a textfile.
BankAcc.txt
This is my user from the Bank , but i only can read the first person detail from this txt. Means, Afiq Bin Ahmad only.
Then how i going to read the second or the third user information(bank account number and pincode) ? For Cheah Soon Kit and David Krishnan?
Now my code is :
import java.util.*;
import javax.swing.JOptionPane;
import java.io.*;
public class ATMProject
{
public static void main(String[] args)throws IOException
{
int number = 1;
int choice = 0 ;
Scanner scan = new Scanner(System.in);
drawLine ("=");
System.out.println (" Bank Of Malaysia ");
drawLine ("=");
System.out.print("Enter your account number> ");
String search = scan.nextLine();
System.out.print("Enter your pincode> ");
String searchString = scan.nextLine().toLowerCase();
File file = new File("BankAcc.txt");
FileReader fileReader = new FileReader(file);
BufferedReader bufReader = new BufferedReader(fileReader);
String name,AccNum,pinCode;
String balance;
name=bufReader.readLine();
AccNum=bufReader.readLine();
pinCode=bufReader.readLine();
balance=bufReader.readLine();
double i = Double.parseDouble(balance);
if ((search.equals(AccNum)) && (searchString.equals(pinCode)))
{
drawLine ("=");
System.out.println ("Welcome " + name);
drawLine ("=");
selection();
do {
try {
choice = printMenu();
if (choice == 1 ) {
drawLine("-");
System.out.println("Withdrawing.....");
System.out.print ("Enter the amount to withdraw> ");
double withdraw = scan.nextDouble();
System.out.println ("Withdrawal successful");
i=i-withdraw;
System.out.println ("your balance now is=" +i);
drawLine("-");
selection();
} else if (choice == 2 ) {
drawLine("-");
System.out.println("Depositing.....");
System.out.print("Enter the amount to deposit> ");
double deposit= scan.nextDouble();
i=i+deposit;
System.out.println ("your balance now is " + i);
drawLine("-");
selection();
} else if (choice == 3) {
drawLine("-");
System.out.println("Checking Balance......");
drawLine("-");
selection();
} else if (choice == 4) {
System.out.println("Bye....");
} else {
System.out.println("You have chosen invalid input!Try again..");
}
}catch (Exception e){
}
} while (choice != 4);
}
else
{
System.out.println("Incorrect Account number and pinCode");
}
bufReader.close();
}
public static void drawLine() {
System.out.println("+++++++++++++++++++++++++++");
}
public static void selection (){
System.out.println (" please make your selection in the menu");
}
public static void drawLine(String symbol) {
for (int i=1; i<=30; i++) {
System.out.print(symbol);
}
System.out.println();
}
public static int printMenu() {
String choice =JOptionPane.showInputDialog ("1. Withdraw\n2. Deposit\n3. Check balance\n4. Exit");
int choiceInt = Integer.parseInt(choice);
return choiceInt;
}
}