Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication3;
- import java.io.*;
- public class Main
- {
- static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- static BankAccount bank;
- public static void main(String[] xxx) throws IOException
- {
- bank.CreateAccounts();
- bank.BottableATM();
- do
- {
- switch(bank.getAccountBalance())
- {
- case 1:
- Inquire();
- break;
- case 2:
- Widraw();
- break;
- default:
- System.out.print("Error");
- break;
- }
- } while (bank.getAccountBalance() != 5);
- }
- public static void Inquire() throws IOException
- {
- //BankAccount acc = new BankAccount(1);
- if(bank.accNum1 == bank.accountNumber1)
- {
- System.out.println("Your Account Balance is " + bank.accountBalance1);
- bank.transactSelect();
- }
- else
- {
- System.out.println("Your Account Balance is " + bank.accountBalance2);
- bank.transactSelect();
- }
- }
- public static void Widraw() throws IOException
- {
- //BankAccount acc = new BankAccount(2);
- if(bank.accNum1 == bank.accountNumber1)
- {
- System.out.println("Enter amount: ");
- double val = Integer.parseInt(bank.in.readLine());
- double Value = bank.accountBalance1 - val;
- System.out.println("Your New Account Balance is " + Value);
- bank.transactSelect();
- }
- else
- {
- System.out.println("Enter amount: ");
- double val = Integer.parseInt(bank.in.readLine());
- double Value = bank.accountBalance2 - val;
- System.out.println("Your New Account Balance is " + Value);
- bank.transactSelect();
- }
- }
- }
- class BankAccount
- {
- static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
- static double accountBalance1, accountBalance2;
- static int accountNumber1,accountNumber2;
- static String accountName1, accountName2;
- static String num1, bal1, num2, bal2;
- static int choose;
- //EnterAccount Checker if There's an Account, else ERROR...
- static int accNum1;
- //The 1st INPUT to know the FILES
- public static void CreateAccounts() throws IOException
- {
- //First Account
- System.out.print("Enter Name of First Account: ");
- accountName1 = in.readLine();
- System.out.print("Enter Number of First Account: ");
- num1 = in.readLine();
- accountNumber1 = Integer.parseInt(num1);
- System.out.print("Enter Balance of First Account: ");
- bal1 = in.readLine();
- accountBalance1 = Integer.parseInt(bal1);
- //Second Account
- System.out.print("Enter Name of Second Account: ");
- accountName2 = in.readLine();
- if(accountName2 == accountName1)
- {
- System.out.println("Please Input Another Account Name, \nSecond Accout Name Is Similar to the others Name");
- do
- {
- System.out.println("Please Input Another Account Name, \nSecond Accout Name Is Similar to the others Name");
- System.out.print("Enter Name of Second Account: ");
- accountName2 = in.readLine();
- }while(accountName2 == accountName1);
- }
- else
- {
- System.out.print("Enter Number of Second Account: ");
- num2 = in.readLine();
- accountNumber2 = Integer.parseInt(num2);
- if(accountNumber2 == accountNumber1)
- {
- System.out.println("Please Input Another Account Number, \nSecond Accout Number Is Similar to the others Number");
- do
- {
- System.out.println("Please Input Another Account Number, \nSecond Accout Number Is Similar to the others Number");
- System.out.print("Enter Number of Second Account: ");
- num2 = in.readLine();
- accountNumber2 = Integer.parseInt(num2);
- }while(accountNumber2 == accountNumber1);
- }
- System.out.print("Enter Balance of Second Account: ");
- bal2 = in.readLine();
- accountBalance2 = Integer.parseInt(bal2);
- System.out.println("Thank You!!!\nYou may now do transaction\nWelcome!!!");
- }
- }
- public static void BottableATM() throws IOException
- {
- System.out.print("Enter an account Number: ");
- accNum1 = Integer.parseInt(in.readLine());
- if(accNum1 == accountNumber1)
- {
- System.out.println("Welcome " +accountName1+ "!");
- transactSelect();
- }
- else if(accNum1 == accountNumber2)
- {
- System.out.println("Welcome " +accountName2+ "!");
- transactSelect();
- }else
- {
- System.out.println("Invalid Account Number!!\nTry it Again");
- BottableATM();
- }
- }
- BankAccount(int i) {
- choose = i;
- }
- public static void transactSelect() throws IOException
- {
- System.out.print("Select a Transaction\n1. Inquire Balance\n2. Withdraw Amount\n3. Transfer Balance\n4. Deposit an amount\n5. EXIT\n");
- System.out.print("\nOption: ");
- choose = Integer.parseInt(in.readLine());
- getAccountBalance();
- }
- public static int getAccountBalance() {
- return choose;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement