Colorado State University Logo | CS 150: Culture and Coding (AUCC 3B/GT-AH3) Colorado State University Logo | CS 150: Culture and Coding (AUCC 3B/GT-AH3)
CS 150: Culture and Coding (AUCC 3B/GT-AH3)
Computer Science

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. In order to do this you will be using a Scanner, if you are unsure about how Scanner works click here.

Step 0 - Getting Started

Before you start writing the methods take a look at the code provided for you. The main method is provided and includes a call to the method menuOptions(). A method called menuOptions() is also provided for you. This method prints all the options available to the user and obtains what action the user would like to perform using a Scanner. If an invalid input is provided then the user is prompted to enter a valid input using a while loop that continues to run until valid input is provided.

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.

Step 7 - Turning in

Once you have run the program and are satisfied it is working, you may submit for grading. Note that you only get five submission attempts, so make sure it is mostly working before you submit. We will bypass the main method in our tests, running our own tests on each method you wrote.

Computer Science Department

279 Computer Science Building
1100 Centre Avenue
Fort Collins, CO 80523
Phone: (970) 491-5792
Fax: (970) 491-2466

CS 150: Culture and Coding (AUCC 3B/GT-AH3)

Survey of computer science, formal logic, and computational thinking. Explores the historical, gender, and cultural perspectives on the role of technology in society. Includes learning a basic programming language. Students will be expected to write small programs, and construct written arguments on ways in which technology influences our modern culture. Previous computer science experience not necessary.