I am working in eclipse to find 3 ingredients from user, how many cups per ingredient and then add them all together to find the total ounces. Here is what I have so far but I think its wrong double cups;double ounces; //Create ScannerScanner input = new Scanner(System.in); //ask and receive users 1st ingredientSystem.out.print("Enter the first ingredient: ");String firstIngredient = input.nextLine(); //ask and receive users 2nd ingredientSystem.out.print("Enter the second ingredient: ");String secondIngredient = input.nextLine(); //ask and receive users 3rd ingredientSystem.out.print("Enter the third ingredient: ");String thirdIngredient = input.nextLine();//ounces = cups * 8;System.out.print("Enter the number of cups for the first ingredient: ");firstCup = input.nextDouble(); System.out.print("Enter the number of cups for the second ingredient: ");secondCup = input.nextDouble(); System.out.print("Enter the number of cups for the third ingredient: ");thirdCup = input.nextDouble();  totalOunces = (firstCup + secondCup + thirdCup); System.out.println("The recipe uses " + firstIngredient + ", " + secondIngredient + ", and " + thirdIngredient  );//System.out.print("The total amount of the recipe in ounces is " + totalOunces);

Question
Asked Oct 14, 2019
1 views

I am working in eclipse to find 3 ingredients from user, how many cups per ingredient and then add them all together to find the total ounces. Here is what I have so far but I think its wrong

 

double cups;

double ounces;

 

//Create Scanner

Scanner input = new Scanner(System.in);

 

//ask and receive users 1st ingredient

System.out.print("Enter the first ingredient: ");

String firstIngredient = input.nextLine();

 

//ask and receive users 2nd ingredient

System.out.print("Enter the second ingredient: ");

String secondIngredient = input.nextLine();

 

//ask and receive users 3rd ingredient

System.out.print("Enter the third ingredient: ");

String thirdIngredient = input.nextLine();

//ounces = cups * 8;

System.out.print("Enter the number of cups for the first ingredient: ");

firstCup = input.nextDouble();

 

System.out.print("Enter the number of cups for the second ingredient: ");

secondCup = input.nextDouble();

 

System.out.print("Enter the number of cups for the third ingredient: ");

thirdCup = input.nextDouble();

 

 

totalOunces = (firstCup + secondCup + thirdCup);

 

System.out.println("The recipe uses " + firstIngredient + ", " + secondIngredient + ", and " + thirdIngredient  );

//System.out.print("The total amount of the recipe in ounces is " + totalOunces);

 

check_circle

Expert Answer

Step 1

The java program obeys the following rubrics: -

  • Importing the essential headers.
  • In main method – Declaring and initializing the variables according to their requirements
  • Declaring the two variables cups and ounces of double datatype.
  • Displaying message to user to enter the name of 3 ingredients.
  • Taking input of name of 3 ingredients from user.
  • Displaying message to user to enter the number of cups of 3 ingredients.
  • Taking input of number of cups of 3 ingredients by user.
  • Calculating the number of ounces from the number of cups, by multiplying the total number of cups by 8.
  • Displaying all the 3 ingredients to user.
  • Displaying total number of ounces of the 3 ingredients to user.
Step 2

In the given program code some variables like firstCup, secondCup, thirdCup and totalOunces are not declared with their data types. So, to rectify the error in program firstly, declaring all the given variables with the double data type. Second major error in the given program code is that it is not displaying the total ounce to user.

Correct program code is given below:

 

import java.util.Scanner;

//main class

public class Main

{

//declaring main method

public static void main(String[] args)

{

//declaring variables with double data type

double cups;

double ounces;

//Creating object of Scanner class to take input from the user

Scanner input = new Scanner(System.in);

//displaying message to user to enter the name of 1st ingredient

System.out.print("Enter the name of first ingredient: ");

//taking input of name of 1st ingredient from user

String firstIngredient = input.nextLine();

//displaying message to user to enter the name of 2nd ingredient

System.out.print("Enter the name of second ingredient: ");

//taking input of name of 2nd ingredient from user

String secondIngredient = input.nextLine();

//displaying message to user to enter the name of 3rd ingredient

System.out.print("Enter the name of third ingredient: ");

//taking input of name of 3rd ingredient from user

String thirdIngredient = input.nextLine();

//displaying message to user to enter the number of cups of 1st ingredient

System.out.print("Enter the number of cups for the first ingredient: ");

//taking input of number of cups of 1st ingredient from user

//declaring variab...

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

Related Computer Science Q&A

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

Q: How do I solve this 3 step problem dealing with fitness and calorie tracking in java? thnks  and ple...

A: Hello. Since you have posted multiple questions and not specified which question needs to be solved,...

question_answer

Q: In C++   Create a function called SuperRandomNumber. It should accept a number called top as the arg...

A: Note:The following program creates a function “SuperRandomNumber()” which accepts “top” as argument ...

question_answer

Q: Write a C++ console application that allows your user to enter the total rainfall for each of 12 mon...

A: To write a C++ program that asks the user to enter total rainfall for 12 months into an array of dou...

question_answer

Q: Using the following truth table, write the equivalent Boolean equations in Sum of Product and Produc...

A: Simplification of Sum Of Products (SOP):The truth table of the SOP is as follows

question_answer

Q: First, launch NetBeans and close any previous projects that may be open (at the top menu go to File ...

A: Create a JAVA class of name AtmSimulator. Import DecimalFormat class to display balance up to 2 deci...

question_answer

Q: What are the Windows 2016 "flavors"?

A: Windows Server 2016 comes in 3 flavors, which are, Server Core (no GUI), Server with Desktop Experie...

question_answer

Q: Boolean Logic Draw the truth table for the following functions: F(A,B)=AB+(A+B) F(A,B,C)=AB+BC+...

A: Hey, since there are multiple questions posted, we will answer first question. If you want any speci...

question_answer

Q: Write a program in Java Eclipse that does the following:a) create a 2D Ragged array with columns and...

A: Create a Main class and all required methods to print Ragged array elements. And create all methods ...

question_answer

Q: In C++ Create a program that rolls two dice. It should roll these dice multiple times to find the pr...

A: Note:The following program rolls the two dices multiple times and it uses the loop iteration to roll...