# 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
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);

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

String firstIngredient = input.nextLine();

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

String secondIngredient = input.nextLine();

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

Step 1

The java program obeys the following rubrics: -

• 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

#### 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