Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- import java.text.DecimalFormat;
- public class AccountTest
- {
- public static void main(String[] args)
- {
- DecimalFormat dollar = new DecimalFormat("$#,###.00");
- String balanceInput = JOptionPane.showInputDialog ("Enter starting balance: ");
- Double startingBalance = Double.parseDouble(balanceInput);
- String annualInterestRate = JOptionPane.showInputDialog ("Enter annual intrest rate: ");
- Double interest = Double.parseDouble(annualInterestRate);
- String numberOfMonths= JOptionPane.showInputDialog ("Enter the number of months: ");
- int months = Integer.parseInt(numberOfMonths);
- SavingsAccount account = new SavingsAccount(startingBalance, interest);
- for (int i = 1; i <= months; i++)
- {
- String deposit = JOptionPane.showInputDialog ("Enter amount of deposits for month " + i );
- account.makeDeposit(Double.parseDouble(deposit));
- String withdraw = JOptionPane.showInputDialog ("Enter amount of withdrawals for month " + i);
- account.makeWithdraw(Double.parseDouble(withdraw));
- double thisMonthsInterest = account.balance * account.annualInterest / 12;
- account.interestYTD += thisMonthsInterest;
- account.balance += thisMonthsInterest;
- String output = "Months " + i + "\nDeposits " + dollar.format(account.getTotalDeposits()) + "\nWithdrawals " +
- dollar.format(account.getTotalWithdraws()) + "\nInterest " + dollar.format(account.interestYTD)
- + "\nBalance " + dollar.format(account.balance);
- JOptionPane.showMessageDialog(null, output);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement