Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. public class AccountTest
  2. {
  3. // main method begins execution of Java application
  4. public static void main (String [] args)
  5. {
  6. Account account1 = new Account (50.00); // create Account object
  7. Account account2 = new Account (-7.53); // create Account object
  8.  
  9. //display inital balance of each object
  10. System.out.printf("account1 checkingBalance: $%.2f\n",
  11. account1.getCheckingBalance());
  12. System.out.printf("account1 savingsBalance: $%.2f\n",
  13. account1.getSavingsBalance());
  14. System.out.printf("account2 checkingBalance: $%.2f\n",
  15. account2.getCheckingBalance());
  16. System.out.printf("account2 savingsBalance: $%.2f\n",
  17. account2.getSavingsBalance());
  18.  
  19. //create Scanner to obtain input form command window
  20. Scanner input = new Scanner (System.in);
  21. double depositAmount; //deposit amount read from user
  22.  
  23. System.out.print("Enter deposit amount for account1: "); //promp
  24. depositAmount = input.nextDouble(); //obtain user input
  25. System.out.printf("\nadding %.2f to account1 checkingBalance\n\n",
  26. depositAmount);
  27. System.out.printf("\nadding %.2f to account1 savingsBalance\n\n",
  28. depositAmount);
  29. account1.creditChecking( depositAmount ); // add to account1 balance
  30. account1.creditSavings( depositAmount ); // add to account1 balance
  31.  
  32. //display balances
  33. System.out.printf("account1 checkingBalance: $%.2f\n",
  34. account1.getCheckingBalance());
  35. System.out.printf("account2 savingsBalance: $%.2f\n",
  36. account2.getSavingsBalance());
  37.  
  38. System.out.print("Enter deposit amount of account2: " ); //prompt
  39. depositAmount = input.nextDouble(); // obtain user input
  40. System.out.printf ("\nadding %.2f to account2 checkingBalance\n\n",
  41. depositAmount);
  42. System.out.printf ("\nadding %.2f to account2 savingsBalance\n\n",
  43. depositAmount);
  44. account2.creditChecking(depositAmount); //add to account2 balance
  45. account2.creditSavings( depositAmount ); // add to account1 balance
  46.  
  47. //display balance
  48. System.out.printf("account1 checkingBalance $%.2f\n",
  49. account1.getCheckingBalance());
  50. System.out.printf("account1 savingsBalance $%.2f\n",
  51. account1.getSavingsBalance());
  52. System.out.printf("account2 checkingBalance $%.2f\n",
  53. account2.getCheckingBalance());
  54. System.out.printf("account2 savingsBalance $%.2f\n",
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement