Advertisement
Giftednarwhals

Account Class ~ Homework # 7

Oct 8th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. // Name         :   Kyle Blanchard
  2. // Due          :   10/8/2014
  3. // Class        :   CSCI-401
  4. // Assignment       :   Account Class ~ Homework # 7
  5. // Contact      :   Kwblanchard@student.stcc.edu
  6.  
  7. // package csci401;
  8.  
  9. import java.util.Date;
  10.  
  11. public class Account {
  12.  
  13.     private int id;
  14.     private double balance;
  15.     private double annualIntrestRate;
  16.     private Date dateCreated;
  17.  
  18.     public Account() {
  19.  
  20.     }
  21.  
  22.     public Account(int id, double balance) {
  23.  
  24.         this.id = id;
  25.         this.balance = balance;
  26.         annualIntrestRate = 0;
  27.         dateCreated = new Date();
  28.     }
  29.  
  30.     public double getMonthlyIntrestRate() {
  31.  
  32.         return annualIntrestRate / 12.0;
  33.  
  34.     }
  35.  
  36.     public void withdraw(double withdrawel) {
  37.  
  38.         balance -= withdrawel;
  39.  
  40.     }
  41.  
  42.     public void deposit(double deposit) {
  43.  
  44.         balance += deposit;
  45.  
  46.     }
  47.  
  48.     public String toString() {
  49.         return "Balance: " + balance + "\nMonthly Intrest Rate: "
  50.                 + getMonthlyIntrestRate() + "\nAccount Creation Date: "
  51.                 + dateCreated;
  52.     }
  53.  
  54.     // Eclipse Generated Accessors and Mutators
  55.     public int getId() {
  56.         return id;
  57.     }
  58.  
  59.     public double getBalance() {
  60.         return balance;
  61.     }
  62.  
  63.     public double getAnnualIntrestRate() {
  64.         return annualIntrestRate;
  65.     }
  66.  
  67.     public Date getDateCreated() {
  68.         return dateCreated;
  69.     }
  70.  
  71.     public void setId(int id) {
  72.         this.id = id;
  73.     }
  74.  
  75.     public void setBalance(double balance) {
  76.         this.balance = balance;
  77.     }
  78.  
  79.     public void setAnnualIntrestRate(double annualIntrestRate) {
  80.         this.annualIntrestRate = annualIntrestRate;
  81.     }
  82.  
  83.     // Test Program
  84.     public static void main(String args[]) {
  85.  
  86.         Account account = new Account(1122, 20000);
  87.         account.setAnnualIntrestRate(4.5);
  88.         account.withdraw(2500);
  89.         account.deposit(3000);
  90.         System.out.println(account);
  91.  
  92.     }
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement