Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need some help with adding code to the highlighted sections. Code is in Java: package SteppingStones; import java.util.Scanner; import java.util.ArrayList; /** * * @author

I need some help with adding code to the highlighted sections. Code is in Java:

package SteppingStones;

import java.util.Scanner;

import java.util.ArrayList;

/**

*

* @author

*/

public class SteppingStone5_Recipe {

private String recipeName;

/**

* Add three variables:

*

* 1. a variable 'servings' to store how many people the recipe will feed;

*

* 2. an ArrayList variable 'recipeIngredients' to store the text for the

* names (recipeName) each recipe ingredient added

*

* 3. a variable totalRecipeCalories

*

*/

/**

* Add mutators and accessors for the class variable.

*

*/

public SteppingStone5_Recipe() {

this.recipeName = "";

this.servings = ??? //<--- assignment value with appropriate data type

this.recipeIngredients = ???; //<-- assignment value for empty ArrayList

this.totalRecipeCalories = 0;

}

public SteppingStone5_Recipe(String recipeName, ??? servings,

ArrayList<????> recipeIngredients, double totalRecipeCalories)

//<-- use appropriate data type for the ArrayList and the servings arguments

{

this.recipeName = recipeName;

this.servings = servings;

this.recipeIngredients = recipeIngredients

this.totalRecipeCalories = totalRecipeCalories;

}

public void printRecipe() {

/**

* Declare an int variable singleServingCalories.

* Assign singleServingCalories to

* the totalRecipeCalories divided by the servings

*

*/

/**

* Print the following recipe information:

* Recipe: <>

* Serves: <>

* Ingredients:

* <>

* <>

* ...

* <>

*

* Each serving has <> Calories.

*

* HINT --> Use a for loop to iterate through the ingredients

*/

}

public static void main(String[] args) {

??? totalRecipeCalories = ???;

ArrayList recipeIngredients = new ArrayList();

boolean addMoreIngredients = true;

Scanner scnr = new Scanner(System.in);

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

String recipeName = scnr.nextLine();

System.out.println("Please enter the number of servings: ");

//correct data type & Scanner assignment method for servings variable

???? servings = ????

do {

System.out.println("Please enter the ingredient name

or type end if you are finished entering ingredients: ");

String ingredientName = scnr.next();

if (ingredientName.toLowerCase().equals("end")) {

addMoreIngredients = false;

} else {

/**

* Add the ingredient name to recipeIngredients

*

*/

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

float ingredientAmount = scnr.nextFloat();

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

int ingredientCalories = scnr.nextInt();

/**

* Add the total Calories from this ingredient

* (ingredientCalories * ingredientAmount)

* to the totalRecipeCalories

*

*/

}

} while (!reply.equals("n") ;

SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName,

servings, recipeIngredients, totalRecipeCalories);

recipe1.printRecipe();

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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_2

Step: 3

blur-text-image_3

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

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions