Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please debug my Java inheritance code and see if it works on test main: ASAP!! public class Bank { private String pin; protected double balance;

Please debug my Java inheritance code and see if it works on test main: ASAP!!

public class Bank {

private String pin;

protected double balance;

if (pin.length() >4) {

throw new Exception();

}

} catch (Exception ex) {

System.out.println("The PIN number should be 4 digits");

}

public Bank(String pIn) {

pIn = pin;

balance = 0.0;

try {

if (pin.length() >4) {

throw new Exception();

}

} catch (Exception ex) {

System.out.println("The PIN number should be 4 digits");

}

}

public Bank(double amt) { balance = amt; }

public static String getPin() {

return pin;

}

public String setPin(String pin) {

return pin;

}

public void getBalance(String pIn) { if(pIn == pin) { System.out.println("Current balance of your checking account: $" + 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 Check() { super(); }

public Check(String pin) {

super.setPIN(pin);

}

public String setPIN(String pin) { return super.setPIN(pin); }

@Override

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

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);

}

}

}

public void getBalance(String pIn) { if(pIn == Check.getPIN()) { System.out.println("Current balance c: $" + super.balance); } }

}

public class Save extends Account { private static final double MONTHLY_RATE = 0.001; private static final double WDRAWAL_FEE = 5.0; public Save () { super(); } public Save (String pin) { super.setPIN(pin); } public String setPIN(String pin) { return super.setPIN(pin); } @Override public void deposit(double amount) { if (amount > 0) { super.balance += amount; super.balance = Math.round(this.balance * 100.0) / 100.0; } else { System.out.println("Cannot deposit a negative amount."); } } public void withdraw(double amount) { if (this.balance - amount >= 0) { super.withdraw(amount + WDRAWAL_FEE); } else { System.out.println("Cannot withdraw more than the current balance."); } } public void monthElapsed(int months) { for (int i = 0; i < months; i++) { this.balance = this.balance + this.balance * MONTHLY_RATE; this.balance = Math.round(this.balance * 100.0) / 100.0; } } public void getBalance(String pIn) { if(pIn == Save.getPIN()) { System.out.println("Current balance of s: $" + super.balance); } } }

public class BankTest{

public static void main(String[] args) { Check c = new Checki(); Save s = new Save(); c.setPIN("64587"); c.setPIN("0275"); c.deposit(100.8); c.withdraw(200.8); c.getBalance("0275"); c.withdraw(90); c.getBalance("0275"); System.out.println("------------------"); c.monthElapsed(1); c.getBalance("0275"); c.deposit(2000); c.monthElapsed(5); c.getBalance("0000"); c.getBalance("0275"); System.out.println("------------------"); s.setPIN("5555"); s.withdraw(50); s.deposit(1200.2); s.withdraw(195.2); s.getBalance("5555"); s.monthElapsed(1); s.getBalance("4444"); s.getBalance("5555"); s.monthElapsed(30); s.getBalance("5555"); }

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Informix Database Administrators Survival Guide

Authors: Joe Lumbley

1st Edition

0131243144, 978-0131243149

More Books

Students also viewed these Databases questions

Question

Discuss the goals of financial management.

Answered: 1 week ago

Question

Ensure continued excellence in people management.

Answered: 1 week ago

Question

Enhance the international team by recruiting the best people.

Answered: 1 week ago