Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I get stuck on adding these requirements: Displaying Output with the print() or println() Functions Comments Variables Reading Input from the Keyboard Performing Calculations String

 I get stuck on adding these requirements: Displaying Output with the print() or println() Functions

  • Comments
  • Variables
  • Reading Input from the Keyboard
  • Performing Calculations
  • String Concatenation
  • Displaying Formatted Output with printf()
  • Named Constants
  • Random class
  • While loops
  • For loops

 These are the instructions for the  Java program using a switch statement for menu choices that will continuously allow a user to select from BeeBe's Donuts menu and display the current receipt after each choice is made (obviously type 4 is not a donut but a way to end the program). The prices are below. Continue to prompt the user until they select Exit.

1) Glazed (0.50)/ea or 5.00/dozen
2) Chocolate (0.99/ea or 9.90/dozen
3) Cake (0.80/ea or 8.25/dozen
4) Exit

When a selection is made, the program should prompt the user for the number of donuts they want. This should be converted to take advantage of the dozen price. For example, if the use selected 13 glazed, then the it should charge 5.50 (5.00 + 0.50). If the user selects glazed again and purchases 11 more, then the total should now be 10.00 (5.00 + 5.00) for the total of 24 glazed donuts.

Here is an example of the program's output:

Sample Run 1:

1) Glazed (0.50)/ea or 5.00/dozen
2) Chocolate (0.99/ea or 9.90/dozen
3) Cake (0.80/ea or 8.25/dozen
4) Exit
Please make your selection: 4
Thank you for your order!
Total Cost: $0.00

Sample Run 2:

1) Glazed (0.50)/ea or 5.00/dozen
2) Chocolate (0.99/ea or 9.90/dozen
3) Cake (0.80/ea or 8.25/dozen
4) Exit
Please make your selection: 1
Enter amount of donuts wanted: 13
Please make your selection: 2
Enter amount of donuts wanted: 9
Please make your selection: 3
Enter amount of donuts wanted: 6
Please make your selection: 4
Thank you for your order!
Total Cost: $19.71

Here is my code: 

 

import java.util.Scanner;


 

public class DonutShop {

    public static void main(String[] args) {


 

        Scanner scanner = new Scanner(System.in);

        int totalCost = 0.0;

        int selection <= 5;

        double totalCost = 0.0;

       


 

        // sample run 1:

        System.out.println("1) Glazed (0.50)/ea or 5.00/dozen");

        System.out.println("2) Chocolate (0.99/ea or 9.90/dozen");

        System.out.println("3) Cake (0.80/ea or 8.25/dozen");

        System.out.println("4) Exit");

        int selection = scanner.nextInt();

        System.out.println("Please make your selection: 4");

        System.out.println("Thank you for your order!");

        System.out.println("Total Cost: $0.00");

        if (choice == 4){

            break;

        }

        double aDonutPrice = 0.0;

        double aDozenPrice = 0.0;


 

    }

}

 

--------------------------------------------------------------------------------------------------------------------------

Also, I need help with breaking down this statement for a java code to work as a slot machine simulation: 

 

A slot machine is a gambling device where the user inserts money into and then pulls a lever (or presses a button). The slot machine then displays a set of random images. If two or more of the images' matches, the user wins an amount of money that the slot machine dispenses back to the user.

Issue with understanding this Java program that simulates a slot machine. When the program runs, it should do the following:

  • Asks the user to enter the amount of money he or she wants to enter into the slot machine.
  • Instead of displaying images, the program will randomly select a word from the following list:

Sevens, Cherries, Bells, Bars, Lemons, Oranges

To select a word, the program can generate a random number in the range of 0 through 5. If the number is 0, the selected word is Sevens; if the number is 1, the selected word is Cherries; and so forth. The program should randomly select a word from this list three times and display all three of the words.

  • If none of the randomly selected words match, the program will inform the user that he or she has won $0. If two of the words match, the program will inform the user that he or she has won three times the amount entered. If three of the words match, the program will inform the user that he or she has won ten times the amount entered.
  • The program will ask whether the user wants to play again. If so, these steps are repeated. If not, the program displays the total amount of money entered into the slot machine and the total amount won.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Solution Here is a breakdown of the Java code for a slot machine simulation import javautilRandom import javautilScanner public class SlotMachine priv... 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

Recommended Textbook for

Control Systems Engineering

Authors: Norman S. Nise

7th Edition

1118170512, 978-1118170519

More Books

Students also viewed these Programming questions

Question

What is your theoretical orientation? (For Applied Programs Only)

Answered: 1 week ago