binibiningtinamoran

AccountsTester

Jul 7th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class AccountsTester {
  4.  
  5.     public static void main(String []args) {
  6.  
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.         Accounts a1 = new Accounts();
  10.  
  11.         System.out.print("Hello and welcome to the banking system.\nPlease enter a name to create" +
  12.                 " an account, no spaces: ");
  13.         a1.setName(scan.next());
  14.         System.out.println("Account name: " + a1.getName());
  15.  
  16.         int choice;
  17.  
  18.         do {
  19.             System.out.println("\nWhat would you like to do next?" + "\n" +
  20.                     "Change account name: press 1" + "\n" +
  21.                     "See account name: press 2" + "\n" +
  22.                     "Check balance: press 3" + "\n" +
  23.                     "Add money to balance: press 4" + "\n" +
  24.                     "Withdraw money from balance: press 5" + "\n" +
  25.                     "Exit program: press 6: ");
  26.             choice = scan.nextInt();
  27.  
  28.             if (choice == 1) {
  29.                 System.out.println("Account Name: " + firstChoice(a1, scan));
  30.             } else if (choice == 2) {
  31.                 System.out.println("Account Name: " + secondChoice(a1));
  32.             } else if (choice == 3) {
  33.                 System.out.println("Current Balance: " + thirdChoice(a1));
  34.             } else if (choice == 4) {
  35.                 fourthChoice(a1, scan);
  36.             } else if (choice == 5) {
  37.                 fifthChoice(a1, scan);
  38.             }
  39.  
  40.         } while (choice != 6);
  41.     }
  42.  
  43.     public static String firstChoice(Accounts someAccount, Scanner scan) {
  44.  
  45.         System.out.print("Enter account name: ");
  46.  
  47.         someAccount.setName(scan.next());
  48.  
  49.         return someAccount.getName();
  50.     }
  51.  
  52.     public static String secondChoice(Accounts someAccount) {
  53.         return someAccount.getName();
  54.     }
  55.     public static double thirdChoice(Accounts someAccount) {
  56.         return someAccount.getBalance();
  57.     }
  58.  
  59.     public static void fourthChoice(Accounts someAccount, Scanner scan) {
  60.         System.out.print("Enter money to add: ");
  61.         double moneyToAdd = scan.nextDouble();
  62.  
  63.         while (moneyToAdd < 0.0) {
  64.             System.out.print("Enter money to add: ");
  65.             moneyToAdd = scan.nextDouble();
  66.             someAccount.addFunds(moneyToAdd);
  67.         }
  68.  
  69.         someAccount.addFunds(moneyToAdd);
  70.  
  71.         System.out.printf("$%,.2f successfully added to balance.", moneyToAdd);
  72.  
  73.     }
  74.  
  75.     public static void fifthChoice(Accounts someAccount, Scanner scan) {
  76.         System.out.print("Enter amount to withdraw: ");
  77.         double moneyToWithdraw = scan.nextDouble();
  78.         while (moneyToWithdraw < 0.0) {
  79.             System.out.print("Enter money to add: ");
  80.             moneyToWithdraw = scan.nextDouble();
  81.             someAccount.withdraw(moneyToWithdraw);
  82.         }
  83.         someAccount.withdraw(moneyToWithdraw);
  84.  
  85.         System.out.printf("$%,.2f successfully withdrawn from balance.", moneyToWithdraw);
  86.  
  87.     }
  88. }
Add Comment
Please, Sign In to add comment