Question: Im not sure what wrong here. i need help Question 1 Unlimited tries A cookie recipe calls for the following ingredients: 1.5 cups of sugar

Im not sure what wrong here. i need help

Question 1

Unlimited tries

A cookie recipe calls for the following ingredients:

1.5 cups of sugar

1 cup of butter

2.75 cups of flour

The recipe produces 48 cookies with this amount of ingredients. Write a program that asks the user how many cookies they want to make and then displays the number of cups of each ingredient needed for the specified number of cookies.

When the program asks the user for the number of cookies, it should display the following string as a prompt:

'Enter number of cookies:'

When the program displays the number of cups of ingredients, it should display a message in the following format:

You need

x

cups of sugar,

y

cups of butter, and

z

cups of flour.

Where

x

is the number of cups of sugar,

y

is the number of cups of butter, and

z

is the number of cups of flour. Dont worry about formatting the numbers in the output.

The following sample run shows an example of the program's output. The user's input is shown in bold.

Sample Run

Enter number of cookies:48

You need 1.5 cups of sugar, 1.0 cups of butter, and 2.75 cups of flour.

code:

public class CookieRecipe { public static void main(String[] args) { // Create a Scanner object to read input from the user Scanner input = new Scanner(System.in);

// Get the number of cookies from the user System.out.print("Enter number of cookies: "); int numCookies = input.nextInt();

// Calculate the number of cups of each ingredient needed double sugarCups = 1.5 * (numCookies / 48.0); double butterCups = 1 * (numCookies / 48.0); double flourCups = 2.75 * (numCookies / 48.0);

// Display the number of cups of each ingredient needed System.out.println("You need " + sugarCups + " cups of sugar, " + butterCups + " cups of butter, and " + flourCups + " cups of flour."); } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!