Home / Expert Answers / Computer Science / please-help-me-on-my-balance-variable-i-need-to-add-deposit-and-withdraw-on-the-superclass-bank-an-pa415

# (Solved): Please help me on my balance variable: I need to add deposit and withdraw on the superclass Bank an ...

Please help me on my balance variable:

I need to add deposit and withdraw on the superclass Bank and the sublass Check.

public class Bank {

private int Pin;
protected double Balance;

public Bank() {
Pin=0;
Balance=0.0;
try { // try catch block
if (pin > 4) {
throw new Exception();
}
}catch (Exception ex) {// if any exception handle it
System.out.println("The PIN number should be 4 digits");
}
}
public int getPIN() {
return Pin;
}
public int setPIN(String string) {
return Pin;
}
public String getBalance() {
return Balance;
}

public void deposit(double amount) {
if (amount > 0) {
this.Balance += amount;
this.Balance = Math.round(this.Balance * 100.0) / 100.0;
} else {
System.out.println("Cannot deposit a negative amount.");
}
}
public void withdraw(double amount) {
this.Balance -= amount;
this.Balance = Math.round(this.balance * 100.0) / 100.0;
}
}

public class Check extends Bank{

protected static final double OVER=250.00;
protected static final double MFEE = 15.0;
protected static final double OFEE = 10.0;

public Checking(int Pin, double Balance) {
super(Pin, Balance);

}
@Override
public void withdraw(double amount) {
if (this.Balance - amount >= -OVER) {
super.withdraw(amount);
if (this.Balance < 0) {
super.withdraw(OFEE);
}
} else {
System.out.println("Cannot overdraft more than \$250.");
}
}
public void monthElapsed(int months) {
for (int i = 0; i < months; i++) {
if (this.Balance < 1500) {
super.withdraw(MFEE);
}
}
}

We have an Answer from Expert

### Expert Answer

We have an Answer from Expert