Question: Complete accountMenu.java. You must complete the code in the order specified Use a switch statement to call menu choices The switch statement should include a
Complete accountMenu.java.
You must complete the code in the order specified
Use a switch statement to call menu choices
The switch statement should include a default for an invalid choice
The menu and the switch should be in a do-while loop
The loop should continue to execute until user enters 6
Make the following modifications to Account:
Add the method public Boolean validateAmount(double amount) to insure the amount deposited is a positive number
Call validateAmount from each method that uses an amount
The withdraw method must also call the chargeFee method to determine if there are sufficient funds to cover both the withdrawal amount and the fee amount. Do not use a fee for any other method.
// ****************************************************************
// accountMenu.java
//
// Use Account class to create and manage bank accounts
// ****************************************************************
import java.util.Scanner;
public class accountMenu
{
public static void main(String[] args)
{
// declare variables
//prompt user for beginning information for the account: name, //number, and beginning balance
// create an instance of the account using the beginning information
// create the following menu
// ------------------------------------------------
// Welcome to CSCI Bank
//
// Choose one of the following options
// by entering the number in front of the option:
//
// 1) Check account balance
// 2) Deposit to account
// 3) Withdraw from account
// 4) Print account information
// 5) Change account name
// 6) Finished
//
// ------------------------------------------------
// final output thanking user by name for using CSCI Bank
}
}
// ******************************************************* //Account.java // //A bank account class with methods to deposit to, withdraw from, // change the name on, charge a fee to, and print a summary of the account. //******************************************************* public class Account { private double balance; private String name; private long acctNum; //----------------- //Constructor -- initializes balance, owner, and account number //-------------------------------------------- public Account(double initBal, String owner, long number) { balance = initBal; name = owner; acctNum = number; } //-------------------------------------------- //Checks to see if balance is sufficient for withdrawal. //If so, decrements balance by amount; if not, prints message. //-------------------------------------------- public void withdraw(double amount) { if (balance >= amount) balance -= amount; else System.out.println("There are insufficient funds"); } //-------------------------------------------- //Adds deposit amount to balance. //-------------------------------------------- public void deposit(double amount) { balance += amount; } //-------------------------------------------- //Returns balance. //-------------------------------------------- public double getBalance() { return balance; } //----------------------------- //Deducts $10 service fee //-------------------------------------------- public double chargeFee() { this.balance = balance-10; return balance; } //-------------------------------------------- //Changes the name on the account //-------------------------------------------- public void changeName(String newName) { this.name = newName; } public String toString(){ return "Name :"+this.name+" AccountNumber :"+this.acctNum+" Balance :"+this.balance; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
