Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AccountTest
- {
- // main method begins execution of Java application
- public static void main (String [] args)
- {
- Account account1 = new Account (50.00); // create Account object
- Account account2 = new Account (-7.53); // create Account object
- //display inital balance of each object
- System.out.printf("account1 checkingBalance: $%.2f\n",
- account1.getCheckingBalance());
- System.out.printf("account1 savingsBalance: $%.2f\n",
- account1.getSavingsBalance());
- System.out.printf("account2 checkingBalance: $%.2f\n",
- account2.getCheckingBalance());
- System.out.printf("account2 savingsBalance: $%.2f\n",
- account2.getSavingsBalance());
- //create Scanner to obtain input form command window
- Scanner input = new Scanner (System.in);
- double depositAmount; //deposit amount read from user
- System.out.print("Enter deposit amount for account1: "); //promp
- depositAmount = input.nextDouble(); //obtain user input
- System.out.printf("\nadding %.2f to account1 checkingBalance\n\n",
- depositAmount);
- System.out.printf("\nadding %.2f to account1 savingsBalance\n\n",
- depositAmount);
- account1.creditChecking( depositAmount ); // add to account1 balance
- account1.creditSavings( depositAmount ); // add to account1 balance
- //display balances
- System.out.printf("account1 checkingBalance: $%.2f\n",
- account1.getCheckingBalance());
- System.out.printf("account2 savingsBalance: $%.2f\n",
- account2.getSavingsBalance());
- System.out.print("Enter deposit amount of account2: " ); //prompt
- depositAmount = input.nextDouble(); // obtain user input
- System.out.printf ("\nadding %.2f to account2 checkingBalance\n\n",
- depositAmount);
- System.out.printf ("\nadding %.2f to account2 savingsBalance\n\n",
- depositAmount);
- account2.creditChecking(depositAmount); //add to account2 balance
- account2.creditSavings( depositAmount ); // add to account1 balance
- //display balance
- System.out.printf("account1 checkingBalance $%.2f\n",
- account1.getCheckingBalance());
- System.out.printf("account1 savingsBalance $%.2f\n",
- account1.getSavingsBalance());
- System.out.printf("account2 checkingBalance $%.2f\n",
- account2.getCheckingBalance());
- System.out.printf("account2 savingsBalance $%.2f\n",
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement