Skip to content

Instantly share code, notes, and snippets.

@anikseu
Created March 11, 2018 05:38
Show Gist options
  • Select an option

  • Save anikseu/919df5e5dec2201f11406202b11c891c to your computer and use it in GitHub Desktop.

Select an option

Save anikseu/919df5e5dec2201f11406202b11c891c to your computer and use it in GitHub Desktop.
Homework for SavingsAccount
public class SavingAccount{
private long accountId;
private String accountName;
private String address;
private double balance;
public SavingAccount(long accountId, String accountName, String address, double balance) {
this.accountId = accountId;
this.accountName = accountName;
this.address = address;
this.balance = balance;
}
public boolean withdraw(long amount) {
if(amount<=1000 && amount<=balance ){
balance=balance-amount;
return true;
}
int charge=(1.5*amount)/100;
else if(amount>1000 && amount+charge<=balance){
//calculating 1.5%
int charge=(1.5*amount)/100;
balance=balance-amount-charge;
return true;
}
else{
System.err.printf("You do not have sufficient balance\n");
return false;
}
}
public boolean deposit(long amount) {
if (amount > 0) {
balance = balance + amount;
return true;
} else {
System.err.println("Depositing negative amount is not allowed\n");
return false;
}
}
public void print() {
System.out.printf("Id: %d Name: %s Balance: %.2f\n", accountId, accountName, balance);
}
public long getAccountId() {
return accountId;
}
public String getAccountName() {
return accountName;
}
public String getAddress() {
return address;
}
public double getBalance() {
return balance;
}
public void setAddress(String address) {
this.address = address;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment