Search⌘ K

Solution Review: Design a Banking Application

Explore how inheritance works in Java by reviewing a banking application design. Understand how to create subclasses that extend superclass features, use constructors with the super keyword, and implement methods like withdrawal, deposit, and interest calculation. Learn how these principles apply in real coding scenarios to build reliable software.

Account class

Rubric criteria

First, look at the Account class.

Java
public class Account
{
// private instances
private String accNo;
private double balance;
// constructor
public Account(String accNo, double balance)
{
this.accNo = accNo;
this.balance = balance;
}
// withdrawal method
public void withdrawal(double cash)
{
if (cash != 0 && cash <= this.balance && cash <= 50000)
{
balance -= cash; // Deducting balance
System.out.println("Withdrawal is successful. Your current balance is $" + balance);
}
else // error message
{
System.out.println("Please enter the correct amount.");
}
}
// deposit method
public void deposit(double cash)
{
if (cash != 0 && cash <= 100)
{
balance += cash; // Updating balance
System.out.println("Deposit is successful. Your current balance is $" + balance);
}
else // error message
{
System.out.println("Please enter the correct amount.");
}
}
}

Rubric-wise explanation


Point 1:

We create the header of the Account class at line 1.

Point 2:

Initially, we create its private instances: accNo and balance. Next, at line 8, we design its constructor.

Point 3:

Now look at line 15. We create the header of the withdrawal() method. According to the problem statement, it takes an amount of double type: cash. We can only withdraw the money if cash is not 00, is less than or equal to balance, and is less than or equal to ...