Advertisement
nate23nate23

Hw 8

Oct 9th, 2015
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. /**
  2.  *
  3.  * Nate Wheeler
  4.  * HW 8
  5.  * Compsci 220
  6.  * nrwheeler@student.stcc.edu
  7.  *
  8.  */
  9. import java.util.Date;
  10.  
  11. public class Account {
  12.  
  13.     private int id;
  14.     private double balance;
  15.     private static double annualInterestRate;
  16.     private Date dateCreated;
  17.  
  18.     public Account() {
  19.         this.id = 0;
  20.         this.balance = 0;
  21.         this.annualInterestRate = 0;
  22.         this.dateCreated = new Date();
  23.     }
  24.  
  25.     public Account(int a, double b) {
  26.         this.id = a;
  27.         this.balance = b;
  28.         this.annualInterestRate = 0;
  29.         this.dateCreated = new Date();
  30.     }
  31.  
  32.     public int getId() {
  33.         return id;
  34.     }
  35.  
  36.     public void setId(int id) {
  37.         this.id = id;
  38.     }
  39.  
  40.     public double getBalance() {
  41.         return balance;
  42.     }
  43.  
  44.     public void setBalance(double balance) {
  45.         this.balance = balance;
  46.     }
  47.  
  48.     public static double getAnnualInterestRate() {
  49.         return annualInterestRate;
  50.     }
  51.  
  52.     public static void setAnnualInterestRate(double annualInterestRate) {
  53.         Account.annualInterestRate = annualInterestRate;
  54.     }
  55.  
  56.     public Date getDateCreated() {
  57.         return dateCreated;
  58.     }
  59.  
  60.     public double getMonthlyInterestRate() {
  61.         double interest = this.balance * Account.annualInterestRate;
  62.         return interest;
  63.     }
  64.  
  65.     public void withdraw(double d) {
  66.         balance -= d;
  67.     }
  68.  
  69.     public void deposit(double d) {
  70.         balance += d;
  71.     }
  72.  
  73.     public static void main(String[] args) {
  74.         // TODO Auto-generated method stub
  75.         Account bank = new Account(1122, 20000);
  76.         Account.setAnnualInterestRate(4.5);
  77.         bank.withdraw(2500);
  78.         bank.deposit(3000);
  79.         System.out.println("balance: " + bank.getBalance() + "\nmonthly Interest: " + bank.getMonthlyInterestRate()
  80.                 + "\ndate created: " + bank.getDateCreated());
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement