Menu

[Solved]Could Explain Steppingstone5recipe Works Steppingstone5recipetest Ve Gotten Help Program S Q37204668

Could you explain to me how steppingstone5_recipe works withsteppingstone5_recipetest..I’ve gotten help but my program stillseem to have errors and will not run for me.

package ingredient;
import java.util.Scanner;
import java.util.ArrayList;

/**
*
* @author
*/
public class SteppingStone5_Recipe {

private String recipeName;
private int servings;
ArrayList<String> recipeIngredients;
private int totalRecipeCalories;

/**
* Add three variables:
*
* 1. a variable ‘servings’ to store how many people the recipe willfeed;
*
* 2. an ArrayList variable ‘recipeIngredients’ to store the textfor 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 = 1; //<— assignment value with appropriate datatype
this.recipeIngredients = new ArrayList(); //<– assignment valuefor empty ArrayList
this.totalRecipeCalories = 0;

}

public SteppingStone5_Recipe(String recipeName, intservings,
ArrayList recipeIngredients, int totalRecipeCalories) //<– useappropriate data type for the ArrayList and the servingsarguments
{
this.recipeName = recipeName;
this.servings = servings;
this.recipeIngredients = recipeIngredients;
this.totalRecipeCalories = totalRecipeCalories;
}

SteppingStone5_Recipe(String pizza, int i,ArrayList<Ingredient> recipeIngredients) {
throw new UnsupportedOperationException(“Not supported yet.”); //Tochange body of generated methods, choose Tools | Templates.
}

public void printRecipe() {
/**
* Declare an int variable singleServingCalories. Assign
* singleServingCalories to the totalRecipeCalories divided bythe
* servings
*
*/
float singleServingCalories = (float) totalRecipeCalories /servings;
/**
* 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 theingredients
*/
System.out.println(“nRecipe: ” + recipeName);
System.out.println(“Serves: ” + servings);
System.out.println(“Ingredients:”);
for (int i = 0; i < recipeIngredients.size(); i++) {
System.out.println(“t” + recipeIngredients.get(i));
}
System.out.println(“Each serving has ” + singleServingCalories + “Calories.”);
}

public static void main(String[] args) {
int totalRecipeCalories = 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 servingsvariable
int servings = scnr.nextInt();

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
*
*/
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();

/**
* Add the total Calories from this ingredient
* (ingredientCalories * ingredientAmount) to the
* totalRecipeCalories
*
*/
totalRecipeCalories += ingredientCalories * ingredientAmount;
}
} while (addMoreIngredients == true);

SteppingStone5_Recipe recipe1 = newSteppingStone5_Recipe(recipeName,
servings, recipeIngredients, totalRecipeCalories);
recipe1.printRecipe();
}

void setRecipeName(String ramen) {
throw new UnsupportedOperationException(“Not supported yet.”); //Tochange body of generated methods, choose Tools | Templates.
}

void setServings(int i) {
throw new UnsupportedOperationException(“Not supported yet.”); //Tochange body of generated methods, choose Tools | Templates.
}

void setRecipeIngredients(ArrayList<Ingredient>recipeIngredientsTwo) {
throw new UnsupportedOperationException(“Not supported yet.”); //Tochange body of generated methods, choose Tools | Templates.
}

void setTotalRecipeCalories(int i) {
throw new UnsupportedOperationException(“Not supported yet.”); //Tochange body of generated methods, choose Tools | Templates.
}
}

Steppingstone5_recipetest

package ingredient;
import java.util.ArrayList;

/*
* To change this license header, choose License Headers in ProjectProperties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ksamuel
*/
public class SteppingStone5_RecipeTest {

   /**
    * @param args the command line arguments
    */
   public static void main(String[] args) {
       // Create two recipe objectsfirst
       SteppingStone5_Recipe myFirstRecipe= new SteppingStone5_Recipe();
       ArrayList<Ingredient>recipeIngredients = new ArrayList();
       ArrayList<Ingredient>recipeIngredientsTwo = new ArrayList();
       String ingredientName =”Anchovies”;
       Ingredient tempIngredient = newIngredient().addNewIngredient(ingredientName);
      recipeIngredients.add(tempIngredient);
  
   SteppingStone5_Recipe mySecondRecipe = newSteppingStone5_Recipe(“Pizza”, 2, recipeIngredients, 300);
      
   // Initialize first recipe
       String ingredientNameTwo =”Noodles”;
       Ingredient tempIngredientTwo = newIngredient().addNewIngredient(ingredientNameTwo);
      recipeIngredientsTwo.add(tempIngredientTwo);

   myFirstRecipe.setRecipeName(“Ramen”);
   myFirstRecipe.setServings(2);
  myFirstRecipe.setRecipeIngredients(recipeIngredientsTwo);
   myFirstRecipe.setTotalRecipeCalories(150);
      
   // Print details of both recipes
//  System.out.println(myFirstRecipe.printRecipe());
//  System.out.println(mySecondRecipe.printRecipe());
   }
  
}

Expert Answer


Answer to Could you explain to me how steppingstone5_recipe works with steppingstone5_recipetest..I’ve gotten help but my program … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *