Question

Write a complete Java program called "AtmSimDoLoop" (without the quotation marks) according to the following specifications....

Write a complete Java program called "AtmSimDoLoop" (without the quotation marks) according to the following specifications. It should use a do-while loop to prompt the user with the following starting prompt (without the horizontal lines) until the user enters 4 to quit.

The program should start with an initial account balance, which you can set to any legitimate double value. Prompt the user with the following prompt (without the horizontal lines).

Enter the number of your desired transaction type.

Deposit

Withdrawal

Balance

Quit

If a balance is requested, the program should output “Your current balance is $X.” where X is the current balance, and repeat the prompt for the user.

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 current balance and then print “Your new balance is $X.” where X is the new balance after the deposit, and repeat the prompt for the user.

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 current balance, print “Your new balance is $X.” where X is the new balance after the withdrawal, and then repeat the prompt for the user. If the proposed withdrawal amount exceeds the current balance, print “Transaction cannot be completed because there are insufficient funds. Your current balance is $X.” where X is the currrent balance, and then repeat the prompt for the user.

If “Quit” is requested, the program should print “Thank you. Have a wonderful day!” and then stop.

All balances should be printed to two decimal places.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
/*For Simplicity I used 3 different methods to do 3 different operations
* 1.public void deposit(double amount)=> to deposit balance
* 2.public void withdrawal(double amount)=> to withdrawal balance
* 3.public void getBalance()=> to print balance
* 4. constructor is used to initiliase minimum balance
* 
* If you don't want methods then you can simply write logic written inside the method body in place of method call in main
* function
*
* You can use infinite loop by defining always true inside the loop
* 
* Sample Input/Output:
* Enter the number of your desired transaction type.
 1-Deposit
 2-Withdrawal
 3-Balance 
 4-Quit 
3
Your current balance is $200.0
Enter the number of your desired transaction type.
 1-Deposit
 2-Withdrawal
 3-Balance 
 4-Quit 
1
Enter deposit balance: 
210
Your new balance is $410.0
Enter the number of your desired transaction type.
 1-Deposit
 2-Withdrawal
 3-Balance 
 4-Quit 
3
Your current balance is $410.0
Enter the number of your desired transaction type.
 1-Deposit
 2-Withdrawal
 3-Balance 
 4-Quit 
2
Enter deposit balance: 
50
Your new balance is $360.0
Enter the number of your desired transaction type.
 1-Deposit
 2-Withdrawal
 3-Balance 
 4-Quit 
4
Thank you. Have a wonderful day!
* 
* */
//----------------------------------------------------------------
//-----------------------------------------------------------------
// /Java Program to do simple transaction operations
import java.util.*;

public class AtmSimDoLoop {
    //Instance variable to store balance
    public double balance;

    //Constructor to initialize balance with default value 200 , you can set any value
    public AtmSimDoLoop()
    {
        balance=200;
    }

    public void deposit(double amount)
    {
        //Adding new balance to existing balance
        balance=balance+amount;
        //printing new balance
        System.out.println("Your new balance is $"+balance);
    }
    //Method to deposite balance
    public void withdrawal(double amount)
    {
        //Checking for positive remaining balance after withdrawal
        if(balance-amount>=0)
        {
            balance=balance-amount;
            System.out.println("Your new balance is $"+balance);
        }
        else
        {
            System.out.println("Transaction cannot be completed because there are insufficient funds. Your current balance is $"+balance);
        }
    }
    //Method to print current balance
    public void getBalance()
    {
        System.out.println("Your current balance is $"+balance);
    }

    public static void main(String[] args){
        //Instantiating Scanner to read inputs from user
        Scanner scan=new Scanner(System.in);
        //Creating objct of AtmSimdoLoop class
        AtmSimDoLoop atmObj=new AtmSimDoLoop();
        do{
            System.out.println("Enter the number of your desired transaction type.");
            System.out.println(" 1-Deposit\n 2-Withdrawal\n 3-Balance \n 4-Quit ");
            //Reading user's choice
            int choice=scan.nextInt();
            if(choice==1)
            {
                //Asking user for deposit balance
                System.out.println("Enter deposit balance: ");
                double new_balance=scan.nextDouble();
                atmObj.deposit(new_balance);
            }
            else if(choice==2)
            {
                //Asking user for withdrawal balance
                System.out.println("Enter withdrawal balance: ");
                double withdrawal=scan.nextDouble();
                atmObj.withdrawal(withdrawal);
            }
            else if(choice==3)
            {
                //printing balance using method getBalance
                atmObj.getBalance();
            }
            else if(choice==4)
            {
                //System.exit will terminate program
                System.out.println("Thank you. Have a wonderful day!");
                System.exit(0);
            }
        }while(true);
    }
}

//-----------------------------------------------------------------------------------------------------------

//------------------------------------------------------------------------------------------------------------

/ /Java Program to do simple transaction operations
import java.util.*;

public class AtmSimDoLoop {

    public static void main(String[] args){
        //creating balance variable with minimum balance $200
        double balance=200;
        //Instantiating Scanner to read inputs from user
        Scanner scan=new Scanner(System.in);
        do{
            System.out.println("Enter the number of your desired transaction type.");
            System.out.println(" 1-Deposit\n 2-Withdrawal\n 3-Balance \n 4-Quit ");
            //Reading user's choice
            int choice=scan.nextInt();
            if(choice==1)
            {
                //Asking user for deposit balance
                System.out.println("Enter deposit balance: ");
                double amount=scan.nextDouble();
                //Adding new balance to existing balance
                balance=balance+amount;
                //printing new balance
                System.out.println("Your new balance is $"+balance);
            }
            else if(choice==2)
            {
                //Asking user for withdrawal balance
                System.out.println("Enter withdrawal balance: ");
                double amount=scan.nextDouble();
                //Checking for positive remaining balance after withdrawal
                if(balance-amount>=0)
                {
                    balance=balance-amount;
                    System.out.println("Your new balance is $"+balance);
                }
                else
                {
                    System.out.println("Transaction cannot be completed because there are insufficient funds. Your current balance is $"+balance);
                }
            }
            else if(choice==3)
            {
                //Printing balance
                System.out.println("Your current balance is $"+balance);
            }
            else if(choice==4)
            {
                //System.exit will terminate program
                System.out.println("Thank you. Have a wonderful day!");
                System.exit(0);
            }
        }while(true);
    }
}
Add a comment
Know the answer?
Add Answer to:
Write a complete Java program called "AtmSimDoLoop" (without the quotation marks) according to the following specifications....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following guidelines....

    create a new Java application called "RecursiveTriangle" (without the quotation marks) according to the following guidelines. Modify the example in Horstmann Section 5.9, pp. 228-230 so that the triangle displays “in reverse order” as in the example below, which allows the user to set the number of lines to print and the String used for printing the triangle. Use a method to prompt the user for the number of lines (between 1 and 10) to print. This method should take...

  • create a new Java application called "WeightedAvgWithExceptions" (without the quotation marks), according to the following guidelines...

    create a new Java application called "WeightedAvgWithExceptions" (without the quotation marks), according to the following guidelines and using try-catch-finally blocks in your methods that read from a file and write to a file, as in the examples in the lesson notes for reading and writing text files. Input File The input file - which you need to create and prompt the user for the name of - should be called 'data.txt', and it should be created according to the instructions...

  • How would you write the following program using switch statements instead of if-else statements (in java)...

    How would you write the following program using switch statements instead of if-else statements (in java) import java.util.*; public class ATM { public static void main(String[] args) { Scanner input = new Scanner (System.in); double deposit, withdrawal; double balance = 6985.00; //The initial balance int transaction; System.out.println ("Welcome! Enter the number of your transaction."); System.out.println ("Withdraw cash: 1"); System.out.println ("Make a Deposit: 2"); System.out.println ("Check your balance: 3"); System.out.println ("Exit: 4"); System.out.println ("***************"); System.out.print ("Enter Your Transaction Number "); transaction...

  • Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class...

    Write a program called problem4.cpp to implement an automatic teller machine (ATM) following the BankAccount class the we implemented in class. Your main program should initialize a list of accounts with the following values and store them in an array Account 101 → balance = 100, interest = 10% Account 201 → balance = 50, interest = 20% Account 108 → balance = 200, interest = 11% Account 302 → balance = 10, interest = 5% Account 204 → balance...

  • create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in...

    create a new Java application called "WeightedAvgDataAnalyzer" (without the quotation marks), that modifies the DataAnalyzer.java in Horstmann Section 7.5, pp. 350-351 according to the specifications below. The input file should be called 'data.txt' and should be created according to the highlighted instructions below. Note that even though you know the name of the input file, you should not hard-code this name into your program. Instead, prompt the user for the name of the input file. The input file should contain...

  • You have been hired as a programmer by a major bank. Your first project is a...

    You have been hired as a programmer by a major bank. Your first project is a small banking transaction system. Each account consists of a number and a balance. The user of the program (the teller) can create a new account, as well as perform deposits, withdrawals, and balance inquiries. The application consists of the following functions:  N- New account  W- Withdrawal  D- Deposit  B- Balance  Q- Quit  X- Delete Account Use the following...

  • You are to write a Java program using the following instructions to build a bank-ATM server...

    You are to write a Java program using the following instructions to build a bank-ATM server system with sockets. A bank holds accounts that can have deposits, withdrawals, or retrievals of balance. The bank server provides the account for transactions when a client uses and ATM machine. The ATM asks for the type of transaction and the amount (if needed), then creates a socket connection to the bank to send the transaction for processing. The bank performs the transaction on...

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • You are to write a program name Bank.java that maintains a list of records containing names...

    You are to write a program name Bank.java that maintains a list of records containing names and balance of customers. The program will prompt the user for a command, execute the command, then prompt the user for another command. The commands must be chosen from the following possibilities:           a    Show all records           r     Remove the current record           f     Change the first name in the current record           l     Change the last name in the current record           n    Add a new record           d   ...

  • Write a Java program to convert power in kilowatts (kW) of an electric car motor to...

    Write a Java program to convert power in kilowatts (kW) of an electric car motor to horsepower (hp) as follows: Prompt the user to enter the power in kilowatts (kW) of the electric car motor. Convert the power to horsepower. In a comment, reference your source for the conversion factor (non-wiki source). (As a rough estimate, 1 hp equals ~0.75 kW.) Output the power in horsepower (hp). Print the result with 2 decimal places. Once this is working, add a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT