Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class BankAccount {
- public static void main(String[] args) {}
- private double balance;
- public BankAccount()
- {
- balance = 0;
- }
- public BankAccount(double initialBalance)
- {
- balance = initialBalance;
- }
- public void deposit(double amount)
- {
- double newBalance = balance + amount;
- balance = newBalance;
- }
- public void withdraw(double amount)
- {
- double newBalance = balance - amount;
- balance = newBalance;
- }
- public double getBalance()
- {
- return balance;
- }
- public double addInterest(double rate)
- {
- balance = balance * rate + balance;
- return balance;
- }
- }
- public class BankAccountTester
- {
- public static void main(String[] args)
- {
- BankAccount momsSavings = new BankAccount(1000);
- System.out.println("old Balance: " +momsSavings.getBalance());// getBalance
- momsSavings.addInterest(.1);
- System.out.println("new Balance: " +momsSavings.getBalance());// getBalance
- System.out.println(momsSavings);
- System.out.println("Expected:1120");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement