Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class AccountsTester {
- public static void main(String []args) {
- Scanner scan = new Scanner(System.in);
- Accounts a1 = new Accounts();
- System.out.print("Hello and welcome to the banking system.\nPlease enter a name to create" +
- " an account, no spaces: ");
- a1.setName(scan.next());
- System.out.println("Account name: " + a1.getName());
- int choice;
- do {
- System.out.println("\nWhat would you like to do next?" + "\n" +
- "Change account name: press 1" + "\n" +
- "See account name: press 2" + "\n" +
- "Check balance: press 3" + "\n" +
- "Add money to balance: press 4" + "\n" +
- "Withdraw money from balance: press 5" + "\n" +
- "Exit program: press 6: ");
- choice = scan.nextInt();
- if (choice == 1) {
- System.out.println("Account Name: " + firstChoice(a1, scan));
- } else if (choice == 2) {
- System.out.println("Account Name: " + secondChoice(a1));
- } else if (choice == 3) {
- System.out.println("Current Balance: " + thirdChoice(a1));
- } else if (choice == 4) {
- fourthChoice(a1, scan);
- } else if (choice == 5) {
- fifthChoice(a1, scan);
- }
- } while (choice != 6);
- }
- public static String firstChoice(Accounts someAccount, Scanner scan) {
- System.out.print("Enter account name: ");
- someAccount.setName(scan.next());
- return someAccount.getName();
- }
- public static String secondChoice(Accounts someAccount) {
- return someAccount.getName();
- }
- public static double thirdChoice(Accounts someAccount) {
- return someAccount.getBalance();
- }
- public static void fourthChoice(Accounts someAccount, Scanner scan) {
- System.out.print("Enter money to add: ");
- double moneyToAdd = scan.nextDouble();
- while (moneyToAdd < 0.0) {
- System.out.print("Enter money to add: ");
- moneyToAdd = scan.nextDouble();
- someAccount.addFunds(moneyToAdd);
- }
- someAccount.addFunds(moneyToAdd);
- System.out.printf("$%,.2f successfully added to balance.", moneyToAdd);
- }
- public static void fifthChoice(Accounts someAccount, Scanner scan) {
- System.out.print("Enter amount to withdraw: ");
- double moneyToWithdraw = scan.nextDouble();
- while (moneyToWithdraw < 0.0) {
- System.out.print("Enter money to add: ");
- moneyToWithdraw = scan.nextDouble();
- someAccount.withdraw(moneyToWithdraw);
- }
- someAccount.withdraw(moneyToWithdraw);
- System.out.printf("$%,.2f successfully withdrawn from balance.", moneyToWithdraw);
- }
- }
Add Comment
Please, Sign In to add comment