Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.59 KB | None | 0 0
  1. /**
  2.  * SavingsAccount.java
  3.  */
  4. public class SavingsAccount {
  5.     private int accountNumber;
  6.     private String firstName;
  7.     private String lastName;
  8.     private double savingsBalance;
  9.     private static double annualInterestRate;
  10.  
  11.     public SavingsAccount(int accountNumber, String firstName, String lastName, double savingsBalance)
  12.     {
  13.         this.setAccountNumber(accountNumber);
  14.         this.setFirstName(firstName);
  15.         this.setLastName(lastName);
  16.  
  17.         if(savingsBalance >= 0)
  18.             this.setSavingsBalance(savingsBalance);
  19.         else
  20.             this.setSavingsBalance(0);
  21.     }
  22.    
  23.     /**
  24.      * @param amt the amount to add to the current balance
  25.      */
  26.     public void deposit(double amt)
  27.     {
  28.         if(amt > 0)
  29.             savingsBalance += amt;
  30.     }
  31.    
  32.     /**
  33.      * @param amt the amount to withdraw
  34.      */
  35.     public void withdraw(double amt)
  36.     {
  37.         if(amt < savingsBalance)
  38.             savingsBalance -= amt;
  39.     }
  40.    
  41.     /**
  42.      *
  43.      */
  44.     public void calculateMonthlyInterest()
  45.     {
  46.         double amt = savingsBalance * (annualInterestRate / 12);
  47.        
  48.         savingsBalance += amt;
  49.     }
  50.    
  51.     /**
  52.      * @param rate the new interest rate
  53.      */
  54.     public static void modifiyInterestRate(double rate)
  55.     {
  56.         annualInterestRate = rate;
  57.     }
  58.    
  59.     /**
  60.      * @return a string representation of the current state of the class
  61.      */
  62.     public String toString()
  63.     {
  64.         /* round the value first to ensure 2 decimal places */
  65.         savingsBalance = (double) Math.round(savingsBalance * 100) / 100;
  66.        
  67.         String result = "";
  68.        
  69.         result += "Name: " + firstName + " " + lastName + "\n";
  70.         result += "Account Number: " + accountNumber + "\n";
  71.         result += "Balance: $" + savingsBalance + "\n";
  72.        
  73.         return result;
  74.     }
  75.  
  76.     /**
  77.      * @return the accountNumber
  78.      */
  79.     public int getAccountNumber() {
  80.         return accountNumber;
  81.     }
  82.  
  83.     /**
  84.      * @param accountNumber the accountNumber to set
  85.      */
  86.     public void setAccountNumber(int accountNumber) {
  87.         this.accountNumber = accountNumber;
  88.     }
  89.  
  90.     /**
  91.      * @return the firstName
  92.      */
  93.     public String getFirstName() {
  94.         return firstName;
  95.     }
  96.  
  97.     /**
  98.      * @param firstName the firstName to set
  99.      */
  100.     public void setFirstName(String firstName) {
  101.         this.firstName = firstName;
  102.     }
  103.  
  104.     /**
  105.      * @return the lastName
  106.      */
  107.     public String getLastName() {
  108.         return lastName;
  109.     }
  110.  
  111.     /**
  112.      * @param lastName the lastName to set
  113.      */
  114.     public void setLastName(String lastName) {
  115.         this.lastName = lastName;
  116.     }
  117.  
  118.     /**
  119.      * @return the savingsBalance
  120.      */
  121.     public double getSavingsBalance() {
  122.         return savingsBalance;
  123.     }
  124.  
  125.     /**
  126.      * @param savingsBalance the savingsBalance to set
  127.      */
  128.     public void setSavingsBalance(double savingsBalance) {
  129.         this.savingsBalance = savingsBalance;
  130.     }
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement