Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ope.account;
- /**
- * The class <CODE>Account</CODE> represents accounts in
- * a simple (unrealistic) banking system.
- */
- public class Account {
- private double balance; // gatherer: sum of the deposits and withdrawals
- private Customer owner; // fixed value
- private double rate;
- public Account(Customer owner, double interestRate) {
- this.owner = owner;
- this.balance = 0;
- this.rate = interestRate;
- }
- public Customer getOwner() {
- return this.owner;
- }
- public double getBalance() {
- return this.balance;
- }
- public double getInterestRate(){
- return this.rate;
- }
- public void addInterest() {
- this.balance = this.balance*(1+this.rate);
- }
- public void deposit(double amount) {
- this.balance = this.balance + amount;
- }
- public void setInterestRate(double interestRate){
- this.rate = interestRate;
- }
- public double withdraw(double amount) {
- if (amount >= 0) {
- if (amount > this.balance){
- amount = this.balance;
- }
- this.balance = this.balance - amount;
- }else{
- amount = 0;
- }
- return amount;
- }
- public boolean transferTo(Account anotherAccount, double amount) {
- if(this.balance>=amount){
- this.withdraw(amount);
- anotherAccount.deposit(amount);
- return true;
- }
- return false;
- }
- }
Add Comment
Please, Sign In to add comment