n Milestone Two, you will focus your skills finalizing your final project code by submitting a class complete with accessor/mutator, constructor, and “custom” programmer-defined methods.To complete this assignment, review the Milestone Two Guidelines and Rubric document.
steppingstone5_recipetest.docx
steppingstone5_recipe_.docx
Unformatted Attachment Preview
import java.util.ArrayList;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
public class SteppingStone5_RecipeTest {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// Create two recipe objects first
SteppingStone5_Recipe myFirstRecipe = new SteppingStone5_Recipe();
ArrayList recipeIngredients = new ArrayList();
ArrayList recipeIngredientsTwo = new ArrayList();
String ingredientName = “Anchovies”;
Ingredient tempIngredient = new
Ingredient().addNewIngredient(ingredientName);
recipeIngredients.add(tempIngredient);
SteppingStone5_Recipe mySecondRecipe = new SteppingStone5_Recipe(“Pizza”,
2, recipeIngredients, 300);
// Initialize first recipe
String ingredientNameTwo = “Noodles”;
Ingredient tempIngredientTwo = new
Ingredient().addNewIngredient(ingredientNameTwo);
recipeIngredientsTwo.add(tempIngredientTwo);
myFirstRecipe.setRecipeName(“Ramen”);
myFirstRecipe.setServings(2);
myFirstRecipe.setRecipeIngredients(recipeIngredientsTwo);
myFirstRecipe.setTotalRecipeCalories(150);
}
}
// Print details of both recipes
myFirstRecipe.printRecipe();
mySecondRecipe.printRecipe();
import SteppingStones.Ingredient;
import java.util.ArrayList;
import java.util.Scanner;
/**
* @author snhu.edu
*/
public class SteppingStone5_Recipe {
/*
* Set up the variables with their mutators and constructors.
*
*/
private String recipeName;
private int servings;
private ArrayList recipeIngredients = new ArrayList();
private double totalRecipeCalories;
public SteppingStone5_Recipe() {
this.recipeName = “”;
this.servings = 0; // <--- assignment value with appropriate data type this.recipeIngredients = new ArrayList<>(); // <-- assignment value for empty ArrayList this.totalRecipeCalories = 0; } public SteppingStone5_Recipe(String recipeName, int 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; } /** * The following outputs have been created to generate the recipe name, * servings, and the total calories. * * @param createNewRecipe */ public static void main(String[] createNewRecipe) { double totalRecipeCalories = 0; ArrayList recipeIngredients = new ArrayList(); String ingredientName = "", unitMeasurement = ""; boolean addMoreIngredients = true; Scanner scnr = new Scanner(System.in); System.out.println("Please enter the recipe name: "); // correct data tup and Scanner assignment method used for recipeName variable. 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(); /** * The following loop has been constructed to generate the list of ingredients * that will be put in the recipeIngredients array. */ do { System.out .println("Please enter the ingredient name or type end if you are finished entering ingredients: "); ingredientName = scnr.next(); if (ingredientName.toLowerCase().equals("end")) { addMoreIngredients = false; } else { /** * Add the ingredient name to recipeIngredients * */ recipeIngredients.add(new Ingredient().addNewIngredient(ingredientName)); System.out.println("Please enter the ingredient amount: "); float ingredientAmount = scnr.nextFloat(); System.out.println("Please enter a unit of measurement: "); unitMeasurement = scnr.next(); System.out.println("Please enter the ingredient Calories: "); int ingredientCalories = scnr.nextInt(); /** * Add the total Calories from this ingredient (ingredientCalories * * ingredientAmount) to the totalRecipeCalories * */ totalRecipeCalories += (ingredientCalories * ingredientAmount); System.out.println("Total recipe calories are: " + totalRecipeCalories); } } while (addMoreIngredients); SteppingStone5_Recipe recipe1 = new SteppingStone5_Recipe(recipeName, servings, recipeIngredients, totalRecipeCalories); recipe1.printRecipe(); } public String getrecipeName() { return recipeName; } public int getServings() { return servings; } public void setServings(int servings) { this.servings = servings; } public ArrayList getRecipeIngredients() { return recipeIngredients; } public void setRecipeIngredients(ArrayList recipeIngredients) { this.recipeIngredients = recipeIngredients; } public double getTotalRecipeCalories() { return totalRecipeCalories; } /* * Below the print recipe method has been added. It will print hte recipe name, * servings, and recipe ingredients. */ public void setTotalRecipeCalories(int i) { this.totalRecipeCalories = i; } public void printRecipe() { int singleServingCalories = (int) (totalRecipeCalories / servings); /** * Print the following recipe information: Recipe: <> Serves:
* <> Ingredients: <> <> … <>
*
* Each serving has <> Calories.
*
* HINT –> Use a for loop to iterate through the ingredients
*/
System.out.println(“Recipe ” + recipeName);
System.out.println(“Serves ” + servings);
}
System.out.print(“Ingredients:”);
for (int i = 0; i < recipeIngredients.size(); i++) { System.out.print(" " + recipeIngredients.get(i)); } System.out.println(); System.out.println("Each serving has " + singleServingCalories + " calories."); /** * @return the recipeName */ public String getRecipeName() { return recipeName; } public void setRecipeName(String recipeName) { this.recipeName = recipeName; } } ... Purchase answer to see full attachment

Are you having trouble with the above assignment or one similar?

We offers 100% original papers that are written from scratch.We also have a team of editors who check each paper for plagiarism before it is sent to you.
!-- End of Footer -->