Guest User

Untitled

a guest
Jul 16th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.40 KB | None | 0 0
  1.  
  2. package ope.account;
  3.  
  4. /**
  5.  * The class <CODE>Account</CODE> represents accounts in
  6.  * a simple (unrealistic) banking system.
  7.  */
  8. public class Account {
  9.  
  10.   private double balance;         // gatherer: sum of the deposits and withdrawals
  11.   private Customer owner;         // fixed value
  12.   private double rate;
  13.  
  14.   public Account(Customer owner, double interestRate) {
  15.     this.owner = owner;
  16.     this.balance = 0;  
  17.     this.rate = interestRate;
  18.   }
  19.  
  20.  
  21.   public Customer getOwner() {
  22.     return this.owner;
  23.   }
  24.  
  25.  
  26.   public double getBalance() {
  27.     return this.balance;
  28.   }
  29.  
  30.   public double getInterestRate(){
  31.     return this.rate;
  32.   }
  33.  
  34.   public void addInterest() {
  35.     this.balance = this.balance*(1+this.rate);
  36.   }
  37.  
  38.   public void deposit(double amount) {
  39.     this.balance = this.balance + amount;
  40.   }
  41.  
  42.   public void setInterestRate(double interestRate){
  43.     this.rate = interestRate;
  44.   }
  45.  
  46.   public double withdraw(double amount) {
  47.     if (amount >= 0) {
  48.       if (amount > this.balance){
  49.         amount = this.balance;
  50.       }
  51.       this.balance = this.balance - amount;
  52.     }else{
  53.       amount = 0;
  54.     }
  55.     return amount;
  56.   }
  57.  
  58.  
  59.   public boolean transferTo(Account anotherAccount, double amount) {
  60.     if(this.balance>=amount){
  61.       this.withdraw(amount);
  62.       anotherAccount.deposit(amount);
  63.       return true;
  64.     }
  65.     return false;
  66.   }
  67.  
  68.  
  69. }
Add Comment
Please, Sign In to add comment