Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * SavingsAccount.java
- */
- public class SavingsAccount {
- private int accountNumber;
- private String firstName;
- private String lastName;
- private double savingsBalance;
- private static double annualInterestRate;
- public SavingsAccount(int accountNumber, String firstName, String lastName, double savingsBalance)
- {
- this.setAccountNumber(accountNumber);
- this.setFirstName(firstName);
- this.setLastName(lastName);
- if(savingsBalance >= 0)
- this.setSavingsBalance(savingsBalance);
- else
- this.setSavingsBalance(0);
- }
- /**
- * @param amt the amount to add to the current balance
- */
- public void deposit(double amt)
- {
- if(amt > 0)
- savingsBalance += amt;
- }
- /**
- * @param amt the amount to withdraw
- */
- public void withdraw(double amt)
- {
- if(amt < savingsBalance)
- savingsBalance -= amt;
- }
- /**
- *
- */
- public void calculateMonthlyInterest()
- {
- double amt = savingsBalance * (annualInterestRate / 12);
- savingsBalance += amt;
- }
- /**
- * @param rate the new interest rate
- */
- public static void modifiyInterestRate(double rate)
- {
- annualInterestRate = rate;
- }
- /**
- * @return a string representation of the current state of the class
- */
- public String toString()
- {
- /* round the value first to ensure 2 decimal places */
- savingsBalance = (double) Math.round(savingsBalance * 100) / 100;
- String result = "";
- result += "Name: " + firstName + " " + lastName + "\n";
- result += "Account Number: " + accountNumber + "\n";
- result += "Balance: $" + savingsBalance + "\n";
- return result;
- }
- /**
- * @return the accountNumber
- */
- public int getAccountNumber() {
- return accountNumber;
- }
- /**
- * @param accountNumber the accountNumber to set
- */
- public void setAccountNumber(int accountNumber) {
- this.accountNumber = accountNumber;
- }
- /**
- * @return the firstName
- */
- public String getFirstName() {
- return firstName;
- }
- /**
- * @param firstName the firstName to set
- */
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
- /**
- * @return the lastName
- */
- public String getLastName() {
- return lastName;
- }
- /**
- * @param lastName the lastName to set
- */
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
- /**
- * @return the savingsBalance
- */
- public double getSavingsBalance() {
- return savingsBalance;
- }
- /**
- * @param savingsBalance the savingsBalance to set
- */
- public void setSavingsBalance(double savingsBalance) {
- this.savingsBalance = savingsBalance;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement