BankAccount Application Java Program Throughout this module, we have discussed t
ID: 3902315 • Letter: B
Question
BankAccount Application Java Program
Throughout this module, we have discussed the five steps involved in the program development. The first three of these steps include the following:
Gather requirements
Use CRC cards to find classes, responsibilities, and collaborators
Use UML diagrams to record class names, attributes, methods, and relationships
Apply these steps to the following program scenario:
A program is needed that acts as a BankAccount application. It should allow for the user to check their balance for Checking and Savings accounts. Analyze the requirements needed for this application. Then complete the first three steps of the program development process for this application.
Compile the components of these first three steps into a Word document, and submit your assignment by the posted due date.
Explanation / Answer
//BankAccount.java
public class BankAccount
{
public String accountNo;
public double balance;
/*Constructor*/
public BankAccount ()
{
accountNo="unknown";
balance=0;
}
/*Constructor with account number and balance*/
public BankAccount(String acct, double balance)
{
this.accountNo = acct;
this.balance = balance;
}
/*Returns balance*/
public double getbalance()
{
return balance;
}
/*Method to deposit amount*/
public void depost(double amt)
{
balance=balance+amt;
}
/**Method to withdraw amount*/
public void withdraw(double amt)
{
balance=balance-amt;
}
/*Override the toString method that retuers
* account number and balance*/
public String toString()
{
return String.format("Account Number:%-10s Balance:%-5.2f ", accountNo,balance);
}
}
------------------------------------------------------------------------
//Checking.java
public class Checking extends BankAccount
{
//set charge $1 for withdrawl
private double FEE=1;
public Checking(String actNum,double bal)
{
super(actNum, bal);
}
/*Override the withdraw method*/
public void withdraw(double amt)
{
//withdraw fee
balance=balance-amt-FEE;
}
}//end of the Checking class
------------------------------------------------------------------------
//Savings.java
public class Savings extends BankAccount
{
//one percent interest RATE
private double INTEREST=0.01;
//Savings contructor
public Savings(String actNum,double bal)
{
super(actNum, bal);
}
/*Override the depost method*/
public void depost(int amt) {
double interest=super.getbalance()*INTEREST;
super.depost(interest+amt);
}
}//end of the class, Savings
------------------------------------------------------------------------
//Code to copy
//TestAccount.java
public class TestAccount {
public static void main(String[] args) {
//Create BankAccount class with account number and balance
BankAccount act=new BankAccount("1001", 100);
System.out.println("***BankAccount***");
System.out.println(act.toString());
System.out.println("***SavingsAccount***");
//Create Savings class with account number and balance
Savings savact=new Savings("1002", 200);
System.out.println(savact.toString());
System.out.println("Deposit : 100");
savact.depost(100);
System.out.println(savact.toString());
//Create Checking class with account number and balance
System.out.println("***CheckingAccount***");
Checking chk=new Checking("1003", 500);
System.out.println(chk);
chk.withdraw(100);
System.out.println("Withdraw : 100");
System.out.println(chk.toString());
}
}
------------------------------------------------------------------------
Sample Output:
***BankAccount***
Account Number:1001
Balance:100.00
***SavingsAccount***
Account Number:1002
Balance:200.00
Deposit : 100
Account Number:1002
Balance:302.00
***CheckingAccount***
Account Number:1003
Balance:500.00
Withdraw : 100
Account Number:1003
Balance:399.00
Note : Above classes BankAccount.java, Savings.java, Checking.java and TestAccount.java are written based on the assumtion of the Bank system.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.