Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LAB PROMPT: Lab 09 - Simple ATM lab For this lab you will be creating your own simple ATM machine that be able to perform

LAB PROMPT:

Lab 09 - Simple ATM lab

For this lab you will be creating your own simple ATM machine that be able to perform a series of actions depending on the input provided by the user.

Step 1 - Declaring Class Constants

At the top of your class you should declare the following static variables:

  • double variable called depositAmount
  • double variable called accountBalance
  • double variable called withdrawalAmount
  • double variable called principal
  • double variable called interestRate initialized to .025
  • double variable called futureAmount
  • int variable called timesCompoundPerYear initialized to 2
  • int variable called numYearsGrows

Step 2 - usersChoice

The method signature is already written for you for this method. The method is a public static method called usersChoice and does not return anything. It has one parameter of type int called atmMenuOptions that represent the menu option the user selected.

The valid options the user may have selected are 0-4. So in the body of the method you are going to use if statements to check what atmMenuOptions is equal to.

If the atmMenuOptions is equal to 0 print Thank you for using the Simple ATM. Goodbye. followed by a new line.

For now leave the body of the if statements blank. As you write the rest of the methods in the lab you will add calls to the methods into the body of the corresponding if statement.

Step 3 - deposit

This method is a public static method called deposit that does not return anything. This method asks the user for an amount they would like to deposit and then displays the updated account balance.

You must first print a new line. After that print Enter the amount to deposit: and then read the input from the user into the class constant depositAmount variable using the .nextDouble() method. It should look this:

System.out.println(); System.out.print("Enter the amount to deposit: "); depositAmount = scan.nextDouble(); 

Next you want to make sure that the user is depositing a valid amount. While depositAmount is less than 0.0 then you want to print Deposit value may not be negative. followed by another print statement prompting the user to Enter the amount to deposit: and assign the users input from the Scanner to depositAmount. You will perform this check using a while loop. For more info on while loops click here.

Finally you need to update accountBalance by adding depositAmount to it and print New account balance is: with the accountBalance in the same line.

Testing deposit

First add a call to deposit() in the usersChoice() method. It should look like:

if (atmMenuOptions == 1) { deposit(); } 

In the terminal when prompted select the deposit option by typing 1. Then enter an amount to deposit.

Step 4 - withdrawal

This method is a public static method called withdrawal that does not return anything. It does not have any parameters. This method asks the user for an amount they would like to withdraw and displays the updated account balance.

The beginning of this method is the almost exactly the same as the deposit method. You will first print a blank line. Then print Enter amount to withdrawal: to prompt the user and then assign to the class constant withdrawalAmount the amount that the users provides using the Scanner method .nextDouble() to get the userInput.

You want to make sure the user is not trying to withdraw more money than is in the account. While accountBalance minus withdrawalAmount is less than 0.0 you want to print Withdrawal amount can not be more than account balance. followed by another print statement prompting the user to Enter amount to withdrawal: . Then read the users new input into withdrawalAmount again using the Scanner.

If the user provided a valid withdrawal amount then you must reassign accountBalance to be equal to accountBalance minus withdrawalAmount. Then print the account balance and New account balance is: .

Testing withdrawal

First add a call to withdrawal() in the usersChoice() method.

In the terminal when prompted select the withdrawal option by typing 2. Then enter the amount to withdraw.

Step 5 - currentBalance

This method is a public static method called currentBalance and returns nothing. This method prints the current balance that is in the account.

First print a blank line. Then print Current account balance: followed by the accountBalance.

Testing currentBalance

First add a call to currentBalance() in the usersChoice() method.

In the terminal when prompted select the currentBalance option by typing 3.

Step 6 - principalAmount

The method is a public static method called principal and returns nothing. This method calculates the amount principal interest will grow in a certain number of years.

First print a blank line. Then print Enter principal amount: to prompt the user and then assign to the class constant principal the amount that the users provides using the Scanner method .nextDouble() to get the userInput.

Then check using a while loop to see if principal is less than 0. If so print Principal amount can not be negative. followed by another print statement prompting the user to Enter principal amount: . Then read the users new input into principal again using the Scanner.

Next print Enter number of years to grow investment: and read the users input into numYearsGrows using the Scanner method .nextInt().

Then check to see if numYearsGrows is less than 0. If so print Growth period can not be negative. followed by a print statement prompting the user to Enter number of years to grow investment: . Then read the users new input into principal again using the Scanner.

You will then calculate the futureAmount which is numYearsGrows * timesCompoundPerYear.

The last step is to calculate the principal amount inside a for loop. The for loop goes from 0 to the futureAmount. Inside the for loop you want to set principal equal to principal times 1.0 + interestRate / timesCompoundPerYear.

Lastly you want to print In numYearsGrows years your principal will grow to $ followed by principal

Testing principalAmount

First add a call to principalAmount() in the usersChoice() method.

In the terminal when prompted select the principalAmount option by typing 4. Then enter a value that represents the principle amount and then you will enter a second value that represents the number of years to grow investment.

PROVIDED CODE:

import java.util.Scanner;

public class SimpleATM { // declare your class-level variables here static Scanner scan = new Scanner(System.in); // declare your methods here public static void usersChoice(int atmMenuOptions) { } // ************** don't modify below this line ************************

public static void main(String[] args) { menuOptions(); } public static void menuOptions() { int atmMenuOptions = 99;

System.out.println("Welcome to the Simple ATM"); while (atmMenuOptions != 0) {

System.out.println("0: Exit ATM"); System.out.println("1: Make a Deposit"); System.out.println("2: Make a Withdrawal"); System.out.println("3: Display Balance"); System.out.println("4: Calculate Compound Interest"); System.out.print("What action would you like to perform? "); atmMenuOptions = scan.nextInt(); while (atmMenuOptions < 0 || atmMenuOptions > 4) { System.out.println(); System.out.println("That is not a valid menu option."); System.out.print("What action would you like to perform? "); atmMenuOptions = scan.nextInt(); } usersChoice(atmMenuOptions); } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions