First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).Then create a new Java application called "AtmSimDoLoop" (without the quotation marks) that simulates a simple ATM according to the following guidelines.The program should start with an initial account balance, which you can set to any legitimate double value. All output of currency values should include a leading dollar sign and use two decimal positions.  Prompt the user with the following prompt (without the dashed lines) using a do loop.Enter the number of your desired transaction type.BalanceDepositWithdrawalQuit  Enter choose: If a balance is requested, the program should output "Your current balance is $X.XX" where X.XX is the initial balance, and then re-display the prompt and await the next transaction type.If a deposit is requested, prompt the user to enter the amount of the deposit (use a double for this). Add the deposit amount to the initial balance and then print "Your current balance is $X.XX" where X.XX is the new balance after the deposit, and then re-display the prompt and await the next transaction type.If a withdrawal is requested, prompt the user to enter the amount of the withdrawal (use a double for this). If the proposed withdrawal amount is less than or equal to the initial balance, print “Your current balance is $X.XX” where X.XX is the new balance after the withdrawal, and then re-display the prompt and await the next transaction type. If the proposed withdrawal amount exceeds the initial balance, print "Insufficient funds. Your current balance is $X.XX" where X.XX is the initial balance, and then re-display the prompt and await the next transaction type.If "Quit" is requested, the program should print "Good-bye" and then stop.ThoughtsBefore you begin coding, sketch out the logic that will handle each condition appropriately. Return to the feedback and score you received for the PA - AtmSimulator and fix any errors that were noted for this PA - AtmSimDoLoop exercise.Refer to Horstmann chapter 2 for details on formatting output values.Note that you need to keep track of the current balance during each iteration of the loop.Include multiple iterations through the menu to fully test your code and all of your calculations. You should include TWO complete sample runs using different values for deposits and withdrawals, testing for insufficient funds and invalid input values.Copy and paste all of your sample runs in your source code as a block comment at the bottom below the closing curly brace.

Question
Asked Oct 17, 2019
85 views

First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).

Then create a new Java application called "AtmSimDoLoop" (without the quotation marks) that simulates a simple ATM according to the following guidelines.

The program should start with an initial account balance, which you can set to any legitimate double value. All output of currency values should include a leading dollar sign and use two decimal positions.  Prompt the user with the following prompt (without the dashed lines) using a do loop.

Enter the number of your desired transaction type.

  1. Balance
  2. Deposit
  3. Withdrawal
  4. Quit

  Enter choose: 

  • If a balance is requested, the program should output "Your current balance is $X.XX" where X.XX is the initial balance, and then re-display the prompt and await the next transaction type.
  • If a deposit is requested, prompt the user to enter the amount of the deposit (use a double for this). Add the deposit amount to the initial balance and then print "Your current balance is $X.XX" where X.XX is the new balance after the deposit, and then re-display the prompt and await the next transaction type.
  • If a withdrawal is requested, prompt the user to enter the amount of the withdrawal (use a double for this). If the proposed withdrawal amount is less than or equal to the initial balance, print “Your current balance is $X.XX” where X.XX is the new balance after the withdrawal, and then re-display the prompt and await the next transaction type. If the proposed withdrawal amount exceeds the initial balance, print "Insufficient funds. Your current balance is $X.XX" where X.XX is the initial balance, and then re-display the prompt and await the next transaction type.
  • If "Quit" is requested, the program should print "Good-bye" and then stop.

Thoughts

  • Before you begin coding, sketch out the logic that will handle each condition appropriately. 
  • Return to the feedback and score you received for the PA - AtmSimulator and fix any errors that were noted for this PA - AtmSimDoLoop exercise.
  • Refer to Horstmann chapter 2 for details on formatting output values.
  • Note that you need to keep track of the current balance during each iteration of the loop.

Include multiple iterations through the menu to fully test your code and all of your calculations. 
You should include TWO complete sample runs using different values for deposits and withdrawals, testing for insufficient funds and invalid input values.
Copy and paste all of your sample runs in your source code as a block comment at the bottom below the closing curly brace.

check_circle

Expert Answer

Step 1

Program Instructions:

  • Declare the initial balance to $5000.
  • Use do-while loop to repeatedly show the menu to the user.
  • Use switch statement to execute different user choices.
Step 2

Program:

package atmsimdoloop;

 

import java.util.Scanner;

 

public class AtmSimDoLoop {

    // driver program

    public static void main(String[] args) {

        // variable declarations

        double balance = 5000, withdraw, deposit;

        int n;

        // user input

        Scanner s = new Scanner(System.in);

        // do-while loop

        do

        {

            // menu

            System.out.println("Enter the number of your desired transaction type.");

            System.out.println("\n\t1. Balance");

            System.out.println("\t2. Deposit");

            System.out.println("\t3. Withdrawal");

            System.out.println("\t4. Quit");

            System.out.print("\nEnter choice: ");

            n = s.nextInt();

            switch(n)

            {

                // display balance

                case 1:

                    System.out.printf("Your current balance is $%.2f",balance);

                    System.out.println("");

                    break;

               

                    // deposit money

                case 2:

                    System.out.print("Enter the amount of the deposit: ");

                    deposit = s.nextInt();

                    balance = balance + deposit;

                    System.out.printf("Your current balance is $%.2f",balance);

                    System.out.println("");

                    break;

 

                    // withdraw money

                case 3:

                    System.out.print("Enter the amount of the withdrawal: ");

                    withdraw = s.nextInt();

                    // input validation

                    if(balance >= withdraw)

                    {

                        balance = balance - withdraw;

      &nbs...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Java

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: All programming languages have a loop capability. Looping is the program logic’s ability to repeat o...

A: Program://inlcude the header files#include <iostream>using namespace std; //definition of main...

question_answer

Q: in python This program requires two functions. In the main function: create an empty list. use a lo...

A: Programming instructions: First, make a list with no values.Then, utilize for-loop to add values in ...

question_answer

Q: Write a program which does the following (name=xxx_and_xxx_lab2):1) Create a 2 dim array containing ...

A: Description:The following program is to print the two dimensional array with the given information i...

question_answer

Q: I need help programming this C++ program: Write a C++ console application that calculates and displa...

A: Given,Minimum parking charges for up to three hours = 3$Addition charges per hours = 0.85$Maximum ch...

question_answer

Q: Hello, I am using the Intro to Java programmming and data structures by Y. Daniel Liang. Our profess...

A: A java program to check the user’s input is a factor of random number generated is given below;Progr...

question_answer

Q: I am completely stumped on this homework question and cannot figure out how to make the range count ...

A: Program Instructions:Use -1 to decrement down the count.The text can be made 5 characters wide by us...

question_answer

Q: Draw the truth tables for the following Boolean expressions. xy+yz+xz x¯y+yz¯+x¯z (x⊕y)+(y⊕z)+(x...

A:  The logic gates are basically an elementary building block of the digital circuits. Logic gates are...

question_answer

Q: In C++ Ask the user for three friends names, store the names in an array.  Output the array to a fil...

A: Program://include the required header files#include <iostream>#include<fstream>#include ...

question_answer

Q: The extraterrestrials living in the planet Numerion revere a specific type of integers N. In particu...

A: Program code #1: