Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package school.lemon.changerequest.java.banking;

/**
* Created by lbrdev on 10.01.2017.
* Project: exceptions.hw1
*/
public class BankAccountImpl implements BankAccount {

double balance;
double rate;
int accountNumber;
double sum;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make all fields private and delete sum and newRate fields.

double newRate;

public BankAccountImpl() {
this.balance = 0;
this.rate = 0;
this.accountNumber = 0;
}

@Override
public int getAccountNumber() {
return accountNumber;
}

@Override
public double getBalance() {
return balance;
}

@Override
public double getRate() {
return rate;
}

@Override
public void setRate(double rate) {
rate = newRate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks strange and for sure won't work.

}

@Override
public void withdraw(double sum) throws IllegalArgumentException {
if (balance < sum) {
throw new IllegalArgumentException("Not enough money for withdrawal");
}
balance = getBalance() - sum;
}

@Override
public void deposit(double sum) throws IllegalArgumentException {
balance = getBalance() + sum;
}

@Override
public void addInterest() {
balance = getBalance() + getBalance() * getRate();
}

@Override
public String toString() {
return ("Account#"
+ getAccountNumber()
+ ", ("
+ "$" + getBalance() + ")");
}
}
28 changes: 28 additions & 0 deletions src/main/java/school/lemon/changerequest/java/banking/TestBA.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package school.lemon.changerequest.java.banking;

/**
* Created by lbrdev on 10.01.2017.
* Project: exceptions.hw1
*/
public class TestBA {
public static void main(String[] args) {
BankAccountImpl bankAccount1 = new BankAccountImpl();

bankAccount1.balance = 15;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please always use getters/setters. Direct access to fields is really bad practice.

bankAccount1.rate = 10;
bankAccount1.accountNumber = 1;
bankAccount1.sum = 10;
bankAccount1.newRate = 11;

System.out.println("" + bankAccount1.toString());
bankAccount1.withdraw(bankAccount1.sum);
System.out.println("withdraw " + bankAccount1.balance );
bankAccount1.addInterest();
System.out.println("after addInterest" + bankAccount1.balance);
bankAccount1.setRate(bankAccount1.newRate);
bankAccount1.addInterest();
System.out.println("addInterst" + bankAccount1.balance);


}
}