...

/

Solution Review: Design a Banking Application

Solution Review: Design a Banking Application

Have a look at the solution to the 'Design a Banking Application' challenge.

Account class

Rubric criteria

First, look at the Account class.

Press + to interact
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 0 ...