import java.util.Scanner; public class MiniTellerShell { /* in the main method y
ID: 3801233 • Letter: I
Question
import java.util.Scanner; public class MiniTellerShell { /* in the main method you need to call the method validChoice as long as the user's choice is not Q or q based on the user's choice call the appropriate methods such as balance, depoist, withdraw and cretate once the user select Q or q, prompt the user if there is another customer */ public static void main(String[] args) { Scanner kb = new Scanner(System.in); String choice =""; double balance = 0; description(); boolean repeat = true; String answer = ""; boolean account = false; while (repeat) //as long as there is another user { balance = 0; choice = ""; account = false; while (!choice.equalsIgnoreCase("Q"))// as long as the user has not selected quit { //your code includes conditional statments } } System.out.println("The system is about to shut down"); } /*This method accepts a Scanner object and the balance of the money that the person has as its parameter prompt the user to enter the amount of the money to withdraw call the method dataValiation to get the user's input if the user's input is more than the balance display that the user cannot withdraw that amount if the balance - the user's input is less than 100 then no withdraw can be done otherwise the withdraw can be done therefore the user's input must be subtracted from the balance. then return the new balance */ public static double withdraw(Scanner kb, double balance) { return 0; } /*this method prompt the user for the amount to deposit call the method dataValidation to get the user's input add the amonmut to the balance, return the new balance*/ public static double deposit(Scanner kb, double balance) { return 0; } /* this method prompts the user to enter the initial amount of the money to cretae the account call the method dataValidation if the user's input is less than 100, the account cannot be cretaed otherwise the account will be cretaed and a message will be displayed indicating that the account has been cretaed, the initial amount of the money will be returned */ public static double create(Scanner kb) { return 0; } /* This method outputs Welcome to the Bank of America message including all the back slashes */ public static void description( ) { } /* This method displays the choices that the user has*/ public static void displayChoices() { } /*this method prompts the user to enter the choice as long as the user does not have a valid choice, it will keep prompting the user for a valid choice*/ public static String validChoice(Scanner kb) { return ""; } /*This method accepts the scanner object and a message to be displayed on the screen Outputs the prompt on the screen sking the user to enter the amount As long as the amount is less than zero and as long as the user is entering an invalid double value, this method should keep prompting the user for a valid amount. return the valid amount*/ public static double dataValidation(String prompt, Scanner kb) { return 0; } } /*sample output ____________________________________________________________________________________________________ \\\\\\\\\\\\\\\\\\\\\\ \ Welcome to the Bank of America \ \\\\\\\\\\\\\\\\\\\\\\ Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> r Enter a valid choice ---> t Enter a valid choice ---> c lets cretae an account for you. Enter the initial amount of money--> -20 You must enter a positive amount of money. Enter a valid amount: 80 You must deposit 100 or more to create a new account Do you want to cretae a new account? yes Enter the initial amount of money--> 100 Your account has been cretaed successfully Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> w Enter the amount of the withdraw--> 20 Your balance cannot go below 100 dollars. your balance after withdraw will be :80.0 The amount of the money that you have is-->100.0 Hit enter key to continue --> Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> w Enter the amount of the withdraw--> 100 Your balance cannot go below 100 dollars. your balance after withdraw will be :0.0 The amount of the money that you have is-->100.0 Hit enter key to continue --> Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> d Your balance is--> 100.0 Enter the amount of the money to deposit--> 200 Your new balance after deposit is: 300.0 Hit enter key to continue --> Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> w Enter the amount of the withdraw--> 150 The amount of the money you have--> 300.0 The amount of the money that you have is-->150.0 Hit enter key to continue --> Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> c You already have an account. Hit enter key to continue --> Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> B Your balance is --> 150.0 Hit enter key to continue --> Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> w Enter the amount of the withdraw--> 200 You do not have enough money to withdraw The amount of the money that you have is-->150.0 Hit enter key to continue --> Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> w Enter the amount of the withdraw--> 51 Your balance cannot go below 100 dollars. your balance after withdraw will be :99.0 The amount of the money that you have is-->150.0 Hit enter key to continue --> Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> q Thanks for being our loyal customer. Is there another user?yes/no yes Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> C lets cretae an account for you. Enter the initial amount of money--> 100 Your account has been cretaed successfully Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit Enter your choice ---> q Thanks for being our loyal customer. Is there another user?yes/no no The system is about to shut down _____________________________________________________________________________________________________ */
Explanation / Answer
import java.util.Scanner;
public class MiniTellerShell
{
/* in the main method you need to call the method validChoice
as long as the user's choice is not Q or q
based on the user's choice call the appropriate methods such as balance, depoist, withdraw and cretate
once the user select Q or q, prompt the user if there is another customer
*/
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
Scanner kb2 = new Scanner(System.in);
Scanner kb3 = new Scanner(System.in);
Scanner kb4 = new Scanner(System.in);
Scanner kb5 = new Scanner(System.in);
Scanner kb7 = new Scanner(System.in);
String choice = "";
double balance = 0;
description();
boolean repeat = true;
String answer = "";
boolean account = false;
while(repeat) //as long as there is another user
{
balance = 0;
choice = "";
account = false;
while (!choice.equalsIgnoreCase("Q"))// as long as the user has not selected quit
{
displayChoices();
choice = validChoice(kb);
if(choice.equalsIgnoreCase("C")) balance = create(kb2);
else if(choice.equalsIgnoreCase("D")) balance = deposit(kb3, balance);
else if(choice.equalsIgnoreCase("W")) balance = withdraw(kb4, balance);
else if(choice.equalsIgnoreCase("B")) System.out.println("Your balance is --> " + balance);
if(!choice.equalsIgnoreCase("Q"))
{
System.out.println(" Hit enter key to continue --> ");
String s = kb7.nextLine();
if(s.equals("")) continue;
}
}
System.out.println("Thanks for being our loyal customer.");
System.out.println("Is there another user?yes/no");
answer = kb5.nextLine();
if(answer.equals("yes")) repeat = true;
else repeat = false;
}
account = true;
System.out.println("The system is about to shut down");
}
/*This method accepts a Scanner object and the balance of the money that the person has as its parameter
prompt the user to enter the amount of the money to withdraw
call the method dataValiation to get the user's input
if the user's input is more than the balance display that the user cannot withdraw that amount
if the balance - the user's input is less than 100 then no withdraw can be done
otherwise the withdraw can be done therefore the user's input must be subtracted from the balance. then return the new balance
*/
public static double withdraw(Scanner kb4, double balance)
{
double amount;
System.out.print(" Enter the amount of the withdraw--> ");
amount = kb4.nextDouble();
if(amount > balance)
{
System.out.print(" You do not have enough money to withdraw");
}
if((balance-amount) < 100 && (balance-amount) >= 0)
{
System.out.print(" Your balance cannot go below 100 dollars.");
System.out.print(" your balance after withdraw will be :" + (balance-amount));
System.out.print(" The amount of the money that you have is--> "+ balance);
}
else if((balance-amount) >= 100)
{
System.out.print(" The amount of the money you have--> "+balance);
System.out.print("The amount of the money that you have is--> " + (balance - amount));
balance -= amount;
}
return balance;
}
/*this method prompt the user for the amount to deposit
call the method dataValidation to get the user's input
add the amonmut to the balance, return the new balance*/
public static double deposit(Scanner kb3, double balance)
{
System.out.println("Your balance is--> " + balance);
double amount = dataValidation("Enter the amount of the money to deposit--> ", kb3);
balance += amount;
System.out.println("Your new balance after deposit is: " + balance);
return balance;
}
/*
this method prompts the user to enter the initial amount of the money to cretae the account
call the method dataValidation
if the user's input is less than 100, the account cannot be cretaed
otherwise the account will be cretaed and a message will be displayed
indicating that the account has been cretaed, the initial amount of the money will be returned
*/
public static double create(Scanner kb2)
{
System.out.println("lets create an account for you.");
double amount = dataValidation("Enter the initial amount of money--> ", kb2);
if(amount < 100 && amount >= 0)
{
System.out.println("You must deposit 100 or more to create a new account");
System.out.println("Do you want to cretae a new account? ");
Scanner kb1 = new Scanner(System.in);
String ch = kb1.nextLine();
if(ch.equals("yes"))
amount = dataValidation("Enter the initial amount of money--> ", kb2);
else return 0;
}
else
{
System.out.println("Your account has been cretaed successfully");
}
return amount;
}
/*
This method outputs Welcome to the Bank of America message including all the back slashes
*/
public static void description( )
{
System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\");
System.out.println("\\ Welcome to the Bank of America \\");
System.out.println("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\");
}
/*
This method displays the choices that the user has*/
public static void displayChoices()
{
System.out.println("Select one of the following options Press C to create a new account press D to deposit press W to withdraw press B for Balance Press Q to quit");
}
/*this method prompts the user to enter the choice
as long as the user does not have a valid choice, it will keep prompting the user
for a valid choice*/
public static String validChoice(Scanner kb)
{
System.out.print(" Enter your choice ---> ");
String ch = kb.nextLine();
while(!ch.equalsIgnoreCase("C") && !ch.equalsIgnoreCase("D") && !ch.equalsIgnoreCase("W") && !ch.equalsIgnoreCase("B") && !ch.equalsIgnoreCase("Q"))
{
System.out.print(" Enter your choice ---> ");
ch = kb.nextLine();
}
return ch;
}
/*This method accepts the scanner object and a message to be displayed on the screen
Outputs the prompt on the screen sking the user to enter the amount
As long as the amount is less than zero and as long as the user is entering an invalid
double value, this method should keep prompting the user for a valid amount.
return the valid amount*/
public static double dataValidation(String prompt, Scanner kb6)
{
System.out.println(prompt);
double amount = kb6.nextDouble();
while(amount < 0)
{
System.out.println("You must enter a positive amount of money.");
System.out.println("Enter a valid amount: ");
amount = kb6.nextDouble();
}
return amount;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.