Question

Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input...

Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input to collect the recipe name and serving size, using the ingredient entry code from Stepping Stone Lab Four to add ingredients to the recipe, and calculating the calories per serving. Additionally, you will build your first custom method to print the recipe to the screen. Specifically, you will need to create the following:  The instance variables for the class (recipeName, serving size, and recipeIngredients)  The methods (the accessors/mutators, the constructors, and the extra print details method) for the class  A custom method to print the recipe out to the console *To test the functionality of your finished code, use the SteppingStone5_RecipeTest.java file *Replace the public static void main(String[] args) with public SteppingStone5_Recipe createNewRecipe()

1. Modify this code to develop a Recipe class: A. Change the void main method createNewRecipe() that returns a Recipe 2. Change the ArrayList type to an Ingredient object. When a user adds an ingredient to the recipe, instead of adding just the ingredient name, you will add the actual ingredient including name, amount, measurement type, and calories. For the Milestone Two submission, the recipeIngredients ArrayList can remain as a string type. 3. Adapt the printRecipe() method to print the amount and measurement type as well as the ingredient name. 4. Create a custom method in the Recipe class. Choose one of the following options: A. Print out a recipe with amounts adjusted for a different number of servings. B. Create an additional list or ArrayList that allows users to insert step-by-step recipe instructions. C. Convert ingredient amounts from English to metric (or vice versa). D. Calculate select nutritional information. E. Calculate recipe cost.

What will be the code? And can you explain step by step on how to enter it.

package SteppingStones;

//Denisse.Carbo
import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;

public class SteppingStone5_Recipe {

private String recipeName;
private int servings;
private List<String> recipeIngredients;
private double totalRecipeCalories;

public String getRecipeName() {
return recipeName;
}
public void setRecipeName (string recipeName){
this.recipeName = recipeName;
}
public int getServings() {
return servings;
}
public void setServings(int servings) {
this.servings = servings;
}
public List<String> getRecipeIngredients() {
return recipeIngredients;
}
public void setRecipeIngredients() {
this.recipeIngredients = recipeIngredients;
}
public double getTotalRecipeCalories() {
return totalRecipeCalories;
}
public void setTotalRecipeCalories(double totalRecipeCalories) {
this.totalRecipeCalories = totalRecipeCalories;
}

public SteppingStone5_Recipe() {
this.recipeName = "";
this.servings = 0;
this.recipeIngredients = new ArrayList<String> ();
this.totalRecipeCalories = 0;

}
public SteppingStone5_Recipe(String recipeName, int servings,
ArrayList<String> recipeIngredients, double totalRecipeCalories)

{
this.recipeName = recipeName;
this.servings = servings;
this.recipeIngredients = recipeIngredients;
this.totalRecipeCalories = totalRecipeCalories;
}

public void printRecipe() {
int singleServingCalories = 0;
singleServingCalories = (int) (this.totalRecipeCalories/this.servings);

System.out.println("Recipes: " + this.recipeName);
System.out.println("Serves: " + this.servings);
System.out.println("Ingredients: ");
for(String ingredients: recipeIngredients){
System.out.println(ingredients);
System.out.println("Each sercing has: " + singleServingCalories + "Calories.");
}
}


public static void main(string[]args ) {
double totalRecipeCalories = 0.0;
ArrayList <String> 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
int servings = 0;


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();
}

private static class string {

public string() {
}
}
}


/**

* 1. Modify this code to develop a Recipe class:
* a. change the void main method createNewRecipe() that returns a Recipe
*
* 2. FOR FINAL SUBMISSION ONLY:Change the ArrayList type to an
* Ingredient object. When a user adds an ingredient to the recipe,
* instead of adding just the ingredient name, you will be adding the
* actual ingredient including name, amount, measurement type, calories.
* For the Milestone Two submission, the recipeIngredients ArrayList can
* remain as a String type.
*
* 3. Adapt the printRecipe() method to print the amount and measurement
* type as well as the ingredient name.
*
* 4. Create a custom method in the Recipe class.
* Choose one of the following options:
*
* a. print out a recipe with amounts adjusted for a different
* number of servings
*
* b. create an additional list or ArrayList that allow users to
* insert step-by-step recipe instructions
*
* c. conversion of ingredient amounts from
* English to metric (or vice versa)
*
* d. calculate select nutritional information
*
* e. calculate recipe cost

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Done. I have used Recipe class only. Dont udnerstand the exact purpose of Loop class. You can ignore it. Please have a look and in case of doubt please leave a comment. I have not removed your comments so that it is easy for you to understand the code. After the code is clear to you , please remove your comments.

/////////////////////////////////////Recipe.java/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import java.util.ArrayList;

import java.util.Scanner;

public class Recipe {

private String recipeName;

private int serving;

private ArrayList<String> recipeIngredients;

private double totalRecipeCalories;

/**

* 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

*

*/

public Recipe() {

this.recipeName = "";

this.serving = 0;// <--- assignment value with appropriate data type

this.recipeIngredients = new ArrayList<String>(); // <-- assignment value for empty ArrayList

this.totalRecipeCalories = 0;

}

/**

* Add mutators and accessors for the class variable. Following are the Getters

* and Setters for all the class Variables

*/

public String getRecipeName() {

return recipeName;

}

public void setRecipeName(String recipeName) {

this.recipeName = recipeName;

}

public int getServing() {

return serving;

}

public void setServing(int serving) {

this.serving = serving;

}

public ArrayList<String> getRecipeIngredients() {

return recipeIngredients;

}

public void setRecipeIngredients(ArrayList<String> recipeIngredients) {

this.recipeIngredients = recipeIngredients;

}

public double getTotalRecipeCalories() {

return totalRecipeCalories;

}

public void setTotalRecipeCalories(double totalRecipeCalories) {

this.totalRecipeCalories = totalRecipeCalories;

}

public Recipe(String recipeName, int servings, ArrayList<String> recipeIngredients, double totalRecipeCalories)

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

{

this.recipeName = recipeName;

this.serving = servings;

this.recipeIngredients = recipeIngredients;

this.totalRecipeCalories = totalRecipeCalories;

}

public void printRecipe() {

/**

* Declare an int variable singleServingCalories. Assign singleServingCalories

* to the totalRecipeCalories divided by the servings

*

*/

int singleServingCalories = (int) totalRecipeCalories / serving;

System.out.println("Recipe:" + recipeName + " Serves: " + serving + " Ingredients: ");

for (int i = 0; i < recipeIngredients.size(); i++) {

System.out.print(recipeIngredients.get(i) + " ");

}

System.out.print(".Each serving has " + singleServingCalories + " calories");

/**

* Print the following recipe information: Recipe: <<recipeName>> Serves:

* <<servings>> Ingredients: <<Ingredient1>> <<Ingredient2>> ... <<Last

* Ingredient>>

*

* Each serving has <<singleServingCalories>> Calories.

*

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

*/

}

public static void main(String[] args) {

double totalRecipeCalories = 200;

ArrayList<String> recipeIngredients = new ArrayList<String>();

boolean addMoreIngredients = true;

String reply = "";

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

int servings = scnr.nextInt();

scnr.nextLine();

do {

System.out

.println("Please enter the ingredient name or type end if you are finished entering ingredients: ");

String ingredientName = scnr.nextLine();

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

addMoreIngredients = false;

} else {

/**

* Add the ingredient name to recipeIngredients

*

*/

recipeIngredients.add(ingredientName);

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

float ingredientAmount = scnr.nextFloat();

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

int ingredientCalories = scnr.nextInt();

scnr.nextLine();

/**

* Add the total Calories from this ingredient (ingredientCalories *

* ingredientAmount) to the totalRecipeCalories

*

*/

totalRecipeCalories = ingredientCalories * ingredientAmount;

System.out.println("Do you want to continue. Y/N");

reply = scnr.nextLine();

}

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

scnr.close();

Recipe recipe1 = new Recipe(recipeName, servings, recipeIngredients, totalRecipeCalories);

recipe1.printRecipe();

}

}

Add a comment
Know the answer?
Add Answer to:
Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to build Java test class? I am supposed to create both a recipe class, and...

    How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...

  • Can someone help me with my code.. I cant get an output. It says I do...

    Can someone help me with my code.. I cant get an output. It says I do not have a main method. HELP PLEASE. The instruction are in bold on the bottom of the code. package SteppingStones; //Denisse.Carbo import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class SteppingStone5_Recipe { private String recipeName; private int servings; private List<String> recipeIngredients; private double totalRecipeCalories; public String getRecipeName() { return recipeName; } public void setRecipeName (string recipeName){ this.recipeName = recipeName; } public int getServings() { return...

  • Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditiona...

    Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditional and iterative control structures that repeat actions as needed. The unit measurement is missing from the final output and I need it to offer options to lbs, oz, grams, tbsp, tsp, qt, pt, and gal. & fl. oz. Can this be added? The final output...

  • I cannot submit my entire project due to the word count limit. I think my project...

    I cannot submit my entire project due to the word count limit. I think my project looks ok, but my recipe box class and recipe test class is running errors and it may have something to do with the menu portion of the recipe box. Please take a look: "You will create a program that will help you manage a collection of recipes. You will implement three classes: one for the main recipe items, one for the ingredients that are...

  • *Please Add Inline Comments Directed toward software engineers about design decisions to facilitate the programs ongoing...

    *Please Add Inline Comments Directed toward software engineers about design decisions to facilitate the programs ongoing maintenance* import java.util.ArrayList; import java.util.Scanner; /** * * @author Eli Mishkit */ public class SteppingStone6_RecipeBox { /** * Declare instance variables: * a private ArrayList of the type SteppingStone5_Recipe named listOfRecipes * */ private ArrayList<SteppingStone5_Recipe> listOfRecipes; /** * Add accessor and mutator for listOfRecipes * */ public ArrayList<SteppingStone5_Recipe> getListOfRecipes() { return listOfRecipes; } public void setListOfRecipes(ArrayList<SteppingStone5_Recipe> listOfRecipes) { this.listOfRecipes = listOfRecipes; } /** *...

  • 1. Write a class that represents a Recipe as shown in the UML diagram below. Recipe...

    1. Write a class that represents a Recipe as shown in the UML diagram below. Recipe -name: string -cookTime: int -prepTime: int - ingredients: ArrayList<String> +Recipe(String name, int cTime, int pTime, String... ingredients) +Recipe(String name, int cTime, int pTime) +getNumberOfIngredients(): int +addIngredient(String ingredient): void +getName(): String +getTotalRecipeTime(): int +get Ingredient(int index): String +remove Ingredient(String ingredient): String

  • Below are the Car class and Dealership class that I created In the previous lab import...

    Below are the Car class and Dealership class that I created In the previous lab import java.util.ArrayList; class Car { private String make; private String model; private int year; private double transmission; private int seats; private int maxSpeed; private int wheels; private String type; public Car() { } public Car(String make, String model, int year, double transmission, int seats, int maxSpeed, int wheels, String type) { this.make = make; this.model = model; this.year = year; this.transmission = transmission; this.seats =...

  • Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a...

    Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a new method called displayAll, that takes an ArrayList (of your base class) as a parameter, and doesn't return anything [25 pts] The displayAll method will loop through the ArrayList, and call the display (or toString) method on each object   [25 pts] In the main method, create an ArrayList containing objects of both your base class and subclass. (You should have at least 4 objects)  [25...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • LAB: Plant information (ArrayList)

    10.16 LAB: Plant information (ArrayList)Given a base Plant class and a derived Flower class, complete main() to create an ArrayList called myGarden. The ArrayList should be able to store objects that belong to the Plant class or the Flower class. Create a method called printArrayList(), that uses the printInfo() methods defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), adding each Plant or Flower to the myGarden ArrayList, and output each element in myGarden using the printInfo() method.Ex. If the input is:plant Spirea 10  flower Hydrangea 30 false lilac  flower Rose 6 false white plant Mint 4...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT