You are on page 1of 4

import java.util.

Scanner;

public class BankAccount{

//Main Function
public static void main(String []args){

//Declare and initialize a variable for balance to $5000.


double acctBalance = 5000.00;

//Declare other variables as needed


int acctNumber=0, depositAmt, withdrawAmt;
//String menuChoice="X";
//String menuChoicee="X";
char menuChoice='X';

Scanner input = new Scanner (System.in);

//Display the welcome message - (HINT: This method does NOT


require a value returned!)
//Call the welecomeMessage() function
welcomeMessage();

//Prompt the user to enter the account number


//HINT: The account number must be returned to main()! In main(),
dont forget to assign the call statement to a variable.
//Call the accountInfo() function AND assign it to a variable
accountInfo();

//Process menu using a Do-While loop and Switch statement


//This will Display the menu and Call the Function(s) based on the
user's choice until the user enters X

do{
//Call the function to display the menu and prompt the user
for their choice
//HINT: The displayMenu() function must return the choice
back to main()! In main(), dont forget to assign the call statement to a variable.
//Call the displayMenu() function AND assign it to a
variable
menuChoice=displayMenu(menuChoice);

//Start the switch() statement to determine which function


is called based on the users choice
//HINT: Each case calls or invokes a function to perform
some specific task

switch(menuChoice){

//Case (If the menu choice is D)


//Call the depositFunds(balance) function
AND assign it to a variable
case 'D':
case 'd':

acctBalance=depositFunds(acctBalance);
break;

//Case (If the menu choice is W)


//Call the withdrawFunds(balance) function
AND assign it to a variable

case 'W':
case 'w':

acctBalance=withdrawFunds(acctBalance);
break;

//Case (If the menu choice is B)


//Call the checkBalance(account number,
balance) function

case 'B':
case 'b':

checkBalance(acctNumber, acctBalance);
break;

//Case (If the menu choice is X)

case 'X':
case 'x':

System.out.println("Thank you for being a loyal


Seminole Bank customer!");
break;

//Default for user error handling

default:

System.out.print("Error, please enter a D, W, B, or


X.\n");
break;

}//end of switch

if(false)
break;

}while(menuChoice != 'X');

//Display final message

}//end of main
/**************************************************** FUNCTION DEFINITIONS
*****************************************************/

//Display welcome message


public static void welcomeMessage(){

System.out.println("********************************************************Welcome
to Seminole Bank!********************************************************");

}//end of welcomeMessage

//Prompt and Read users account number. RETURN the account number to
main().
public static int accountInfo (){
Scanner input = new Scanner (System.in);

int acctNumber;
System.out.println("\n\nPlease enter your 5-digit Account
Number: \n");
acctNumber = input.nextInt();
System.out.println("Thank you!");
return acctNumber;

//Don't forget to declare local Scanner object to read account


number.
}//end of accountInfo

//Display menu choices to the user and Read the users banking choice.
RETURN the users menu choice to main().
public static char displayMenu (char menuChoice){
Scanner input = new Scanner (System.in);

System.out.print("\nEnter D for deposit, W for withdrawal, B for


balance, X to exit the menu: ");
menuChoice = input.next().charAt(0);
menuChoice = Character.toUpperCase(menuChoice);
return menuChoice;

//Don't forget to declare local Scanner object to read menu choice.


}//end of displayMenu

//Prompt the user for the amount to deposit and Read deposit amount.
Update the balance and RETURN the balance to main().
public static double depositFunds(double acctBalance){
Scanner input = new Scanner (System.in);

int depositAmt;
System.out.println("Enter the amount for this deposit: ");
depositAmt = input.nextInt();
acctBalance = acctBalance + depositAmt;
return acctBalance;

//Don't forget to declare local Scanner object to read deposit


amount.
}//end of depositFunds

//Prompt the user for the amount to withdraw and Read withdrawal amount.
Update the balance and RETURN the balance to main().
public static double withdrawFunds (double acctBalance){
Scanner input = new Scanner (System.in);

int withdrawAmt;
System.out.print("Enter the amount of the withdrawal: ");
withdrawAmt = input.nextInt();
acctBalance = acctBalance - withdrawAmt;
return acctBalance;

//Don't forget to declare local Scanner object to read withdrawal


amount.
}//end of withdrawFunds

//Display the balance and DO NOT RETURN anything to main().


public static void checkBalance(int acctNumber, double acctBalance){

System.out.print("Account number: " + acctNumber + ", Your total


balance is: " + acctBalance);

}//end of checkBalance

/**************************************************END OF FUNCTION
DEFINITIONS **************************************************/

}//end of BankAccount Class

You might also like