Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.85 KB | None | 0 0
  1.  
  2.  
  3. package javaapplication3;
  4. import java.io.*;
  5.  
  6.  
  7. public class Main
  8. {
  9.  
  10.     static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  11.         static BankAccount bank;
  12.     public static void main(String[] xxx) throws IOException
  13.     {
  14.         bank.CreateAccounts();
  15.                 bank.BottableATM();
  16.                 do
  17.                 {
  18.                     switch(bank.getAccountBalance())
  19.                     {
  20.                         case 1:
  21.                             Inquire();
  22.                             break;
  23.                         case 2:
  24.                             Widraw();
  25.                             break;
  26.                         default:
  27.                             System.out.print("Error");
  28.                             break;
  29.                     }
  30.                 } while (bank.getAccountBalance() != 5);
  31.     }
  32.  
  33.         public static void Inquire() throws IOException
  34.         {
  35.  
  36.                 //BankAccount acc = new BankAccount(1);
  37.                 if(bank.accNum1 == bank.accountNumber1)
  38.                 {
  39.                     System.out.println("Your Account Balance is " + bank.accountBalance1);
  40.                     bank.transactSelect();
  41.                 }
  42.                 else
  43.                 {
  44.                     System.out.println("Your Account Balance is " + bank.accountBalance2);
  45.                     bank.transactSelect();
  46.                 }
  47.         }
  48.  
  49.         public static void Widraw() throws IOException
  50.         {
  51.             //BankAccount acc = new BankAccount(2);
  52.                 if(bank.accNum1 == bank.accountNumber1)
  53.                 {
  54.                     System.out.println("Enter amount: ");
  55.                     double val = Integer.parseInt(bank.in.readLine());
  56.                     double Value = bank.accountBalance1 - val;
  57.                     System.out.println("Your New Account Balance is " + Value);
  58.                     bank.transactSelect();
  59.                 }
  60.                 else
  61.                 {
  62.                     System.out.println("Enter amount: ");
  63.                     double val = Integer.parseInt(bank.in.readLine());
  64.                     double Value = bank.accountBalance2 - val;
  65.                     System.out.println("Your New Account Balance is " + Value);
  66.                     bank.transactSelect();
  67.                 }
  68.         }
  69.  
  70. }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77. class BankAccount
  78. {
  79.     static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  80.  
  81.     static double  accountBalance1,  accountBalance2;
  82.         static int accountNumber1,accountNumber2;
  83.         static String accountName1, accountName2;
  84.     static String  num1, bal1, num2, bal2;
  85.         static int choose;
  86.        
  87.     //EnterAccount Checker if There's an Account, else ERROR...
  88.     static int accNum1;
  89.  
  90.        
  91.     //The 1st INPUT to know the FILES
  92.     public static void CreateAccounts() throws IOException
  93.     {
  94.         //First Account
  95.         System.out.print("Enter Name of First Account: ");
  96.         accountName1 = in.readLine();
  97.         System.out.print("Enter Number of First Account: ");
  98.         num1 = in.readLine();
  99.         accountNumber1 = Integer.parseInt(num1);
  100.                
  101.         System.out.print("Enter Balance of First Account: ");
  102.         bal1 = in.readLine();
  103.         accountBalance1 = Integer.parseInt(bal1);
  104.  
  105.  
  106.         //Second Account
  107.         System.out.print("Enter Name of Second Account: ");
  108.         accountName2 = in.readLine();
  109.  
  110.         if(accountName2 == accountName1)
  111.         {
  112.                 System.out.println("Please Input Another Account Name, \nSecond Accout Name Is Similar to the others Name");
  113.             do
  114.             {
  115.                 System.out.println("Please Input Another Account Name, \nSecond Accout Name Is Similar to the others Name");
  116.                 System.out.print("Enter Name of Second Account: ");
  117.                                 accountName2 = in.readLine();
  118.             }while(accountName2 == accountName1);
  119.         }
  120.         else
  121.         {
  122.         System.out.print("Enter Number of Second Account: ");
  123.         num2 = in.readLine();
  124.         accountNumber2 = Integer.parseInt(num2);
  125.             if(accountNumber2 == accountNumber1)
  126.             {
  127.                     System.out.println("Please Input Another Account Number, \nSecond Accout Number Is Similar to the others Number");
  128.                 do
  129.                 {
  130.                     System.out.println("Please Input Another Account Number, \nSecond Accout Number Is Similar to the others Number");
  131.                     System.out.print("Enter Number of Second Account: ");
  132.                     num2 = in.readLine();
  133.                     accountNumber2 = Integer.parseInt(num2);
  134.                 }while(accountNumber2 == accountNumber1);
  135.             }
  136.  
  137.         System.out.print("Enter Balance of Second Account: ");
  138.         bal2 = in.readLine();
  139.         accountBalance2 = Integer.parseInt(bal2);
  140.         System.out.println("Thank You!!!\nYou may now do transaction\nWelcome!!!");
  141.         }
  142.     }
  143.  
  144.  
  145.  
  146.     public static void BottableATM() throws IOException
  147.     {
  148.         System.out.print("Enter an account Number: ");
  149.         accNum1 = Integer.parseInt(in.readLine());
  150.                 if(accNum1 == accountNumber1)
  151.                 {
  152.                         System.out.println("Welcome " +accountName1+ "!");
  153.                         transactSelect();
  154.                 }
  155.                 else if(accNum1 == accountNumber2)
  156.                 {
  157.                         System.out.println("Welcome " +accountName2+ "!");
  158.                         transactSelect();
  159.                 }else
  160.                 {
  161.                     System.out.println("Invalid Account Number!!\nTry it Again");
  162.                     BottableATM();
  163.                 }
  164.     }
  165.  
  166.         BankAccount(int i) {
  167.             choose = i;
  168.         }
  169.  
  170.         public static void transactSelect() throws IOException
  171.         {
  172.                 System.out.print("Select a Transaction\n1. Inquire Balance\n2. Withdraw Amount\n3. Transfer Balance\n4. Deposit an amount\n5. EXIT\n");
  173.                 System.out.print("\nOption: ");
  174.                 choose = Integer.parseInt(in.readLine());
  175.                 getAccountBalance();
  176.         }
  177.  
  178.         public static int getAccountBalance() {
  179.                 return choose;
  180.         }
  181.  
  182.  
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement