Need help in writing JAVA program for a Bank Account, Savings, and Checking Clas
ID: 3764730 • Letter: N
Question
Need help in writing JAVA program for a Bank Account, Savings, and Checking Class. that follows these critrea: Write a program that allows a user to create savings/checking accounts, make deposits and withdrawals, and calculate monthly changes/interest. Account Class Design a class to hold the following information for a bank account: Balance Number of deposits this month Number of withdrawals Annual interest rate Monthly service charge The class should have the following methods: Constructor - accepts arguments for balance and interest rate Deposit - Method that accepts an argument for the amount of the deposit. Add the argument to the account balance and increase the number of deposits. Withdraw - Method that accepts an argument for the amount of the withdrawal. Subtract the argument from the account balance and increase the number of withdrawals. CalculateInterest – Method that updates the balance by calculating the monthly interest earned by the account and adding it to the balance. MonthlyProcess – A method that subtracts the monthly service charge from the balance, calls the calculateInterest method, and displays a monthly statement before setting the number of withdrawals and deposits to zero. Savings Account Class The savings account class is a subclass of the account class. The class should have an additional member: status (active or inactive account) If the balance of a savings account falls below $25, it becomes inactive. No more withdrawals can be made until the account is active. The savings account class should have the following overriding methods: Withdraw – A method that checks if the account is active before a withdrawal is made. A withdrawal is then made by calling the superclass version on the method. Deposit – A method that checks if the account is active before a deposit is made. If the account is inactive and the deposit brings the balance above $25, the account becomes active again. The deposit is made by calling the superclass version on the method. MonthlyProcess – Before the superclass version is called, this method checks the number of withdrawals. If the number of withdrawals is more than 4, a service charge of $1 for each withdrawal above 4 is added to the superclass’s monthly service charge. Checking Account Class The checking account class is a subclass of the account class. The class should have the following overriding methods: Withdraw – Before the superclass version is called, this method determines if a withdrawal will cause a negative balance. If the balance is negative, a service charge of $15 will be subtracted from the account (not part of the monthly service charge). MonthlyProcess – Before the superclass version is called, this method adds a fee of $0.10 per withdrawal to the superclass’s monthly service charge. Driver class Create a class with the main() method. Create a checking and savings account. Give the user a list of menu options which allows them to use the accounts until they decide to stop.
Explanation / Answer
Bank account:
public class BankAccount
{
String firstName;
String lastName;
String ssn;
protected float balance;
float withdraw;
float deposit;
long accountNumber;
BankAccount ()
{
}
BankAccount(String firstName, String lastName, String ssn, float balance)
{
this.firstName = firstName;
this.lastName = lastName;
this.ssn = ssn;
this.balance = balance;
}
long accountNumber()
{
long accountNumber = (long) Math.floor(Math.random() * 9000000000L) + 1000000000L;
return accountNumber;
}
public void deposit(float amount)
{
balance = balance + amount;
System.out.println(firstName + " " + lastName + " deposited $" + deposit + ". Current Balance $" + balance);
}
public void withdraw(float amount)
{
if (balance >= amount)
{
balance = balance - amount;
System.out.println(firstName + " " + lastName + " withdrew $" + amount + ". Current Balance $" + balance);
}
if (balance < amount)
{
System.out.println("Unable to withdraw " + amount + " for " + firstName + " " + lastName + " due to insufficient funds.");
}
}
}
Checking Account Subclass:
public class CheckingAccount extends BankAccount
{
float amtInterest;
float applyInterest;
String displayBalance;
public CheckingAccount()
{
}
public CheckingAccount(String firstName, String lastName, String ssn, float balance)
{
super(firstName, lastName, ssn, balance);
System.out.println("Successfully created account for " + firstName + " " + lastName + " " + accountNumber);
System.out.println(firstName + " " + lastName + ", Balance $" + balance);
}
float applyInterest ()
{
if (balance <= 10000)
{
balance = balance * 0.1f;
}
if (balance > 10000)
{
balance = 1000 + (balance * 0.02f);
}
return balance;
}
float displayBalance()
{
return balance;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.