View the step-by-step solution to:

Need to input the variables with the appropriate data type and value as shown in the table below:

Need help with completing the Java code mentioned below.

 

Need to input the variables with the appropriate data type and value as shown in the table below:

Variable Name                               Type of Value Stored

nameOfIngredient                         Text

numberOfCups                               Decimal numbers (e.g., ½ a cup)

numberOfCaloriesPerCup           Whole numbers

totalCalories                                   Decimal numbers


Include an expression that multiplies the numberOfCups by the numberOfCalories per cup and assign this value to totalCalories.

SteppingStone2_IngredientCalculator.java

package SteppingStones;

import java.util.Scanner;

/**

*

* @author j.leone1

*/

public class SteppingStone2_IngredientCalculator {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

/**

*Assign the following variables with the appropriate data type and value:

*VARIABLE NAME VALUE

*nameOfIngredient ""

*numberCups 0

*numberCaloriesPerCup 0

*totalCalories 0.0

*/

Scanner scnr = new Scanner(System.in);

System.out.println("Please enter the name of the ingredient: ");

nameOfIngredient = scnr.next();

System.out.println("Please enter the number of cups of "

+ nameOfIngredient + " we'll need: ");

numberCups = scnr.nextFloat();

System.out.println("Please enter the number of calories per cup: ");

numberCaloriesPerCup = scnr.nextInt();

/**

* Include an expression that multiplies the number of cups

* by the Calories per cup.

* Assign this value to totalCalories

*/

System.out.println(nameOfIngredient + " uses " + numberCups

+ " cups and has " + totalCalories + " calories.");

}

}

Top Answer

You should declare you variables as below: //Declare your variables with datatypes as below:... View the full answer

216.PNG

Sign up to view the full answer

Other Answers

There are different variable names used to describe different data types in Java. They include int -... View the full answer

Sample output 1: Please enter the name of the ingredient:  BlueBerries Please enter the number of cups of BlueBerries... View the full answer

Sample output.png

'U
|_:
HI
L'1
|"[I
:l
H-
III
1
I'I'
2' IT Ll'l I'II r1 I'II
El
[II
III
|"[I
:l
H-
III
“.I name bf the ingredient: H E
E
H
Um
I"!
'1 the number bF cup: bF Cucumber we'll need: C
p...

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online