Advertisement
Bomixius

Untitled

Nov 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2. import java.text.DecimalFormat;
  3. public class AccountTest
  4. {
  5. public static void main(String[] args)
  6. {
  7. DecimalFormat dollar = new DecimalFormat("$#,###.00");
  8.  
  9.  
  10. String balanceInput = JOptionPane.showInputDialog ("Enter starting balance: ");
  11. Double startingBalance = Double.parseDouble(balanceInput);
  12.  
  13.  
  14. String annualInterestRate = JOptionPane.showInputDialog ("Enter annual intrest rate: ");
  15. Double interest = Double.parseDouble(annualInterestRate);
  16.  
  17. String numberOfMonths= JOptionPane.showInputDialog ("Enter the number of months: ");
  18. int months = Integer.parseInt(numberOfMonths);
  19. SavingsAccount account = new SavingsAccount(startingBalance, interest);
  20.  
  21. for (int i = 1; i <= months; i++)
  22. {
  23. String deposit = JOptionPane.showInputDialog ("Enter amount of deposits for month " + i );
  24. account.makeDeposit(Double.parseDouble(deposit));
  25.  
  26. String withdraw = JOptionPane.showInputDialog ("Enter amount of withdrawals for month " + i);
  27. account.makeWithdraw(Double.parseDouble(withdraw));
  28.  
  29. double thisMonthsInterest = account.balance * account.annualInterest / 12;
  30. account.interestYTD += thisMonthsInterest;
  31. account.balance += thisMonthsInterest;
  32.  
  33. String output = "Months " + i + "\nDeposits " + dollar.format(account.getTotalDeposits()) + "\nWithdrawals " +
  34. dollar.format(account.getTotalWithdraws()) + "\nInterest " + dollar.format(account.interestYTD)
  35. + "\nBalance " + dollar.format(account.balance);
  36. JOptionPane.showMessageDialog(null, output);
  37.  
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement