Java - In NetBeans IDE:
•Design an abstract class called BankAccount which stores the balance.
–Implement a constructor that takes the balance (float).
–Provide abstract methods deposit(amount) and withdraw(amount)
•Design a class called SavingsAccount which extends BankAccount.
–Implement a constructor that takes the balance as input.
–It should store a boolean flag active. If the balance at any point falls below $25, it sets the active flag to false. It should NOT allow the balance to fall below $0.
–If the active flag is false, no more withdraws can be made until deposits are made to bring the account back up to $25. An error message should be printed when withdraws fail.
–Implement the deposit and withdraw methods. They should print at the end the amount deposited/withdrew and the new balance.
•Write a main method that asks the user for the starting balance and creates a SavingsAccount object. It asks the user whether they want to deposit or withdraw until they choose to exit. Use D, W, and E for the menu options to choose deposit withdraw or exit.
//BankAccount.java
public abstract class BankAccount {
private float balance;
// constructor
public BankAccount(float balance)
{
this.balance = balance;
}
// return the balance of the account
public float getBalance()
{
return balance;
}
// set the balance of the account
public void setBalance(float balance)
{
this.balance = balance;
}
// abstract methods
public abstract void deposit(float amount);
public abstract void withdraw(float amount);
}
//end of BankAccount.java
// SavingsAccount.java
public class SavingsAccount extends BankAccount{
private boolean active;
// constructor
public SavingsAccount(float balance)
{
super(balance); // call
BankAccount's constructor
if(balance < 25)
active =
false;
else
active =
true;
}
// method to deposit an amount
@Override
public void deposit(float amount) {
System.out.printf("Amount to
deposit: $%.2f",amount);
if(amount > 0) // amount is
valid
{
setBalance(getBalance()+amount);
if(!active
&& getBalance() > 25)
active = true;
}else // invalid amount
System.out.print("\nAmount to deposit > 0");
System.out.printf("\nUpdated
balance: $%.2f",getBalance());
}
// method to withdraw amount
@Override
public void withdraw(float amount) {
System.out.printf("Amount to
withdraw: %.2f",amount);
if(active) // check if account is
active
{
// check if
withdrawal can be made
if(amount >
getBalance())
{
System.out.print("\nInsufficient funds in the
account");
}else
{
setBalance(getBalance()-amount); // withdraw the
amount
if(getBalance() < 25) // set active to false
if balance < 25
active = false;
}
}else // inactive account
System.out.print("\nCannot withdraw from an inactive account.
Deposit amount to bring the account back up to $25 and activate
it");
System.out.printf("\nUpdated
balance: $%.2f",getBalance());
}
}
//end of SavingsAccount.java
//BankAccountDriver.java
public class BankAccountDriver{
public static void main(String[] args)
{
float balance, amount;
String choice;
Scanner scan = new
Scanner(System.in);
SavingsAccount account;
// input of starting balance
System.out.print("Enter the
starting balance: ");
balance = scan.nextFloat();
// validate balance and re-prompt
until valid
while(balance < 0)
{
System.out.print("Balance cannot be negative. Re-enter: ");
balance =
scan.nextFloat();
}
account = new
SavingsAccount(balance); // create an account
scan.nextLine();
// loop that continues till the
user wants
do
{
// display the
menu
System.out.println("\nD - Deposit\nW - Withdraw\nE- Exit");
System.out.print("Select an option(D/W/E): ");
choice =
scan.nextLine(); // input the menu choice
// validate menu
choice and re-prompt until valid
while(!choice.equalsIgnoreCase("D") &&
!choice.equalsIgnoreCase("W") &&
!choice.equalsIgnoreCase("E"))
{
System.out.print("Invalid option. Re-enter:
");
choice = scan.nextLine();
}
// deposit an
amount
if(choice.equalsIgnoreCase("D"))
{
System.out.print("Enter the amount to deposit:
");
amount = scan.nextFloat();
account.deposit(amount);
scan.nextLine();
}
else
if(choice.equalsIgnoreCase("W")) // withdraw an amount
{
System.out.print("Enter the amount to withdraw:
");
amount = scan.nextFloat();
account.withdraw(amount);
scan.nextLine();
}
System.out.println();
}while(!choice.equalsIgnoreCase("E"));
scan.close();
}
}
//end of BankAccountDriver.java
Output:
Java - In NetBeans IDE: •Design an abstract class called BankAccount which stores the balance. –Implement...
In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...
Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...
Write a Java class called BankAccount (Parts of the code is given below), which has two fields name (String) and balance (double), two constructors and five methods getName(), getBalance(), deposit (double amount), withdraw(double amount) and toString(). The first constructor should initialize name to null and balance to 0. The second constructor initializes name and balance to the parameters passed. deposit method deposits the amount to the account causing the current balance to increase, withdraw method withdraws the amount causing the...
Must be in GUI interfaceDesign an abstract class namedBankAccountto hold the following data for a bankaccount:* Balance* Number of deposits this month* Number of withdrawals (this month)* Annual interest rate* Monthly service chargesThe class should have the following methods:Constructor: The constructor should accept arguments for the balance and annual interest rate.deposit: A method that accepts an argument for the amount of the deposit. The methods should add the argument to the account balance. It should also increment thevariable holding the...
TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...
In python: Make a BankAccount class. The class should have the initial balance be set to a parameter passed into the constructor, but should be 0 if no such parameter is passed in. It should have a method called "withdraw" that withdraws an amount that's supplied as a parameter and returns the new balance. It should also have a method called "deposit" that deposits an amount that's supplied as a parameter and returns the new balance. Both "withdraw" and "deposit"...
The program needs to be in python : First, create a BankAccount class. Your class should support the following methods: class BankAccount (object): """Bank Account protected by a pin number.""" def (self, pin) : init "n"Initial account balance is 0 and pin is 'pin'."" self.balance - 0 self.pin pin def deposit (self, pin, amount): """Increment account balance by amount and return new balance.""" def withdraw (self, pin, amount): """Decrement account balance by amount and return amount withdrawn.""" def get balance...
solve this JAVA problem in NETBEANS Problem #12 in page 400 of your text (6th edition): SavingsAccount Class. Design a SavingsAccount class that stores a savings account's annual interest rate and balance. The class constructor should accept the amount of the savings account's starting balance. The class should also have methods for subtracting the amount of a withdrawal, adding the amount of a deposit, and adding the amount of monthly twelve. To add the monthly interest rate to the balance,...
Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class the we implemented in class. Your main program should initialize a list of accounts with the following values and store them in an array Account 101 → balance = 100, interest = 10% Account 201 → balance = 50, interest = 20% Account 108 → balance = 200, interest = 11% Account 302 → balance = 10, interest = 5% Account 204 → balance...