Guest User

Untitled

a guest
Jul 13th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.68 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class CheckingAccount {
  4.     private String accountNumber, accountHolder;
  5.     private int balance = 0, useCount = 0;
  6.  
  7.     CheckingAccount( String accNumber, String holder, String password, int start ) {
  8.         accountNumber = accNumber ;
  9.         accountHolder = holder ;
  10.         balance       = start ;
  11.     }
  12.  
  13.     int getBalance() {
  14.        return balance;
  15.     }
  16.  
  17.     void processDeposit( int amount ) {
  18.         if (((balance + amount) < 2000000000) && amount < 2000000000) {
  19.         balance += amount;
  20.         System.out.println("Deposited " + amount + " into account.");
  21.         System.out.println("Balance is now " + balance);
  22.         skipLine(2);
  23.     } else {
  24.             System.out.println("Overflow - deposit is too high.");
  25.         }
  26.     }
  27.  
  28.     void processDeposit (int amount, int charge) {
  29.         balance += (amount-charge);
  30.         System.out.println("Deposited " + amount + " into account with a " + charge + " cent fee.");
  31.         System.out.println("Balance is now " + balance);
  32.         skipLine(2);
  33.     }
  34.  
  35.     void processCheck( int amount ) {
  36.         int charge;
  37.         if ( balance < 100000 ) {
  38.           charge = 15;
  39.         } else {
  40.           charge = 0;
  41.         }
  42.         balance -= (amount + charge)  ;
  43.         System.out.println("Withdrew " + amount + " from account with a " + charge + " cent fee.");
  44.         System.out.println("Balance is now " + balance);
  45.         skipLine(2);
  46.     }
  47.  
  48.     void display() {
  49.       System.out.println("Account number: " + accountNumber + " || Owner: " + accountHolder + " || Current Balance: " + getBalance());
  50.       skipLine(2);
  51.     }
  52.  
  53.     void skipLine(int c) {
  54.         for (int i = 0; i < c; i++) {
  55.             System.out.println("");
  56.         }
  57.     }
  58.    
  59.     void payOther(int amount, CheckingAccount c) {
  60.       processCheck(amount);
  61.       c.processDeposit(amount);
  62.       System.out.println(
  63.       "Paid " + amount + " to another account, current balance is now " + balance +
  64.       ". Other person's balance is now " + c.getBalance() + "."
  65.       );
  66.       skipLine(2);
  67.     }
  68. }
  69.  
  70. class methods {
  71.     int i = 0, status = 0, j = 0, response = 0;
  72.     String input = "";
  73.    
  74.     Scanner scan = new Scanner( System.in );
  75.     CheckingAccount David = new CheckingAccount( "92a-44-35", "David", "123123", 10000000 );
  76.     CheckingAccount Mei = new CheckingAccount( "92a-44-33", "Mei", "123123a", 0 );
  77.     CheckingAccount Feng = new CheckingAccount( "92a-44-34", "Feng", "123123a", 50000);
  78.     CheckingAccount currentAccount = null;
  79.     CheckingAccount destinedAccount = null;
  80.     String[] userNames = {"David", "Mei", "Feng"};
  81.     String[] passKeys = {"123123", "123123a", "123123a"};
  82.     String thisUser = "", menuResponse = "";
  83.    
  84.     public void login() {
  85.         System.out.println("Please enter your account name:");
  86.         String username = scan.next();
  87.         for (i = 0; i<userNames.length; i++) {
  88.             if (username.equalsIgnoreCase(userNames[i])) {
  89.                 thisUser = userNames[i];
  90.                 j = i;
  91.                 status = 2;
  92.             }
  93.         }
  94.         if (thisUser == "") {
  95.             System.out.println("Invalid user.");
  96.         }
  97.     }
  98.    
  99.     public void welcome() {
  100.         System.out.println(
  101.             "What would you like to access today? " +
  102.             "\r\n1: account"
  103.         );
  104.         input = scan.next();
  105.         if (input.equalsIgnoreCase("account")) {
  106.             status = 1;
  107.         } else {
  108.             System.out.println("Invalid.");
  109.         }
  110.     }
  111.    
  112.     public void checkPassword() {
  113.         String passKey = scan.next();
  114.         if (passKey.equalsIgnoreCase(passKeys[j])) {
  115.             System.out.println("Account confirmed.");
  116.             status = 3;
  117.         } else {
  118.             System.out.println("Wrong password.");
  119.         }
  120.     }
  121.    
  122.     public int getStatus() {
  123.         return status;
  124.     }
  125.    
  126.     public void mainMenu() {
  127.         System.out.println("Main menu:\r\n1. Deposit\r\n2. Withdraw\r\n3. Transfer Funds (xfer)\r\n4. Check balance\r\n5. Logout");
  128.         menuResponse = scan.next();
  129.         postMenu();
  130.     }
  131.    
  132.     public void postMenu() {
  133.         if (menuResponse.equalsIgnoreCase("deposit")) {
  134.             response = 1;
  135.             status = 4;
  136.         } else if (menuResponse.equalsIgnoreCase("withdraw")) {
  137.             response = 2;
  138.             status = 4;
  139.         } else if (menuResponse.equalsIgnoreCase("xfer")) {
  140.             response = 3;
  141.             status = 4;
  142.         } else if (menuResponse.equalsIgnoreCase("balance")) {
  143.             response = 4;
  144.             status = 4;
  145.         } else if (menuResponse.equalsIgnoreCase("logout")) {
  146.             response = 5;
  147.             status = 4;
  148.         } else {
  149.             System.out.println("Invalid, please try another option.");
  150.             mainMenu();
  151.         }
  152.     }
  153.    
  154.     public void accessAccount() {
  155.         if (thisUser.equalsIgnoreCase("David")) {
  156.             System.out.println("Confirmed. Please enter your password:");
  157.             currentAccount = David;
  158.         } else if (thisUser.equalsIgnoreCase("Mei")) {
  159.             System.out.println("Confirmed. Please enter your password:");
  160.             currentAccount = Mei;
  161.         } else if (thisUser.equalsIgnoreCase("Feng")) {
  162.             System.out.println("Confirmed. Please enter your password:");
  163.             currentAccount = Feng;
  164.         }
  165.     }
  166.    
  167.     public void redirection() {
  168.         if (response == 1) {
  169.             deposit();
  170.         } else if (response == 2) {
  171.             withdraw();
  172.         } else if (response == 3) {
  173.             xfer();
  174.         } else if (response == 4) {
  175.             checkThisBalance();
  176.         } else if (response == 5) {
  177.             logout();
  178.         }
  179.     }
  180.    
  181.     public void deposit() {
  182.         System.out.println("How much would you like to deposit?");
  183.         String amount = scan.next();
  184.         int thisAmount = Integer.parseInt(amount);
  185.         currentAccount.processDeposit(thisAmount);
  186.         status = 3;
  187.         mainMenu();
  188.     }
  189.    
  190.     public void withdraw() {
  191.         System.out.println("How much would you like to withdraw?");
  192.         String amount = scan.next();
  193.         int thisAmount = Integer.parseInt(amount);
  194.         currentAccount.processCheck(thisAmount);
  195.         status = 3;
  196.         mainMenu();
  197.     }
  198.    
  199.     public void xfer() {
  200.         System.out.println("Who do you want to wire your money to?");
  201.         String userInput = scan.next();
  202.         if (userInput.equalsIgnoreCase("David")) {
  203.             destinedAccount = David;
  204.         } else if (userInput.equalsIgnoreCase("Mei")) {
  205.             destinedAccount = Mei;
  206.         } else if (userInput.equalsIgnoreCase("Feng")) {
  207.             destinedAccount = Feng;
  208.         } else {
  209.             destinedAccount = currentAccount;
  210.         }
  211.         System.out.println("Please enter the amount you want to wire over:");
  212.         String amountString = scan.next();
  213.         int thisAmount = Integer.parseInt(amountString);
  214.         currentAccount.payOther(thisAmount, destinedAccount);
  215.         status = 3;
  216.         mainMenu();
  217.     }
  218.    
  219.     public void checkThisBalance() {
  220.         currentAccount.display();
  221.         status = 3;
  222.         mainMenu();
  223.     }
  224.    
  225.     public void logout() {
  226.         currentAccount = null;
  227.         System.out.println("Logged off! Goodbye.");
  228.         status = 0;
  229.     }
  230.    
  231. }
  232.  
  233. class CheckingAccountTester {
  234.     public static void main( String[] args ) {
  235.         methods m = new methods();
  236.         int omg = 0;
  237.         while (omg == 0) {
  238.             if (m.getStatus() == 0) {
  239.                 m.welcome();
  240.             }
  241.             if (m.getStatus() == 1) {
  242.                 m.login();
  243.                 m.accessAccount();
  244.             }
  245.             if (m.getStatus() == 2) {
  246.                 m.checkPassword();
  247.             }
  248.             if (m.getStatus() == 3) {
  249.                 m.mainMenu();
  250.             }
  251.             if (m.getStatus() == 4) {
  252.                 m.redirection();
  253.             } else {
  254.                 m.redirection();
  255.             }
  256.         }
  257.     }
  258. }
Add Comment
Please, Sign In to add comment