Hello, two JAVA files have been created based on the following requirements: THE PROGRAM DOES NOT RUN AND HAVE SOME ERRORS PLEASE HELP:
A Recipe class should include the following items:
Instance variables: recipeName, servings, recipeIngredients, and totalRecipeCalories
Accessors and mutators for the instance variables
Constructors
A printRecipe() method
A-createNewRecipe() method to build a recipe from user input
Pseudocode for the custom method selected from the list in Stepping Stone Lab Five:
See file below:
package milestone.two.recipe.pkgclass;
import java.util.Scanner;
import java.util.ArrayList;
public class MilestoneTwoRecipeClass {
private String recipeName; private int servings; ArrayList recipeIngredients = new ArrayList(); private int totalRecipeCalories; public void setRecipeName(String recipeName){ this.recipeName = recipeName; } public String getRecipeName(){ return recipeName; } public void setServings(int servings){ this.servings = servings; } public int getServings(){ return servings; } public void setRecipeIngredients(ArrayList recipeIngredients){ this.recipeIngredients = recipeIngredients; } public ArrayList getRecipeIngredients(){ return recipeIngredients; } public void setTotalRecipeCalories(int totalRecipeCalories){ this.totalRecipeCalories = totalRecipeCalories; } public int getTotalRecipeCalories(){ return totalRecipeCalories; } //constructor public MilestoneTwoRecipeClass() { this.recipeName = ""; this.servings = 0; this.recipeIngredients = new ArrayList<>(); this.totalRecipeCalories = 0; } public MilestoneTwoRecipeClass(String recipeName, int servings, ArrayList recipeIngredients, double totalRecipeCalories) { this.recipeName = recipeName; this.servings = servings; this.recipeIngredients = recipeIngredients; this.totalRecipeCalories = (int) totalRecipeCalories; } public void printRecipe() { int singleServingCalories = (totalRecipeCalories / servings); System.out.println("Recipe: " + recipeName); System.out.println("Serves: " + servings); System.out.println("Ingredients: "); for (int i = 0; i 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: "); 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; break; } else { recipeIngredients.add(ingredientName); addMoreIngredients = true; 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 = (int) (ingredientCalories * ingredientAmount); } } while (addMoreIngredients == true) ; MilestoneTwoRecipeClass recipe1 = new MilestoneTwoRecipeClass(recipeName, servings, recipeIngredients, totalRecipeCalories); recipe1.printRecipe(); return recipe1; } }
A Recipe_Test.java file containing a main() method that:
Uses a constructor to create a new recipe
Accesses the printRecipe() method to print the formatted recipe
Invokes the createNewRecipe() method to accept user input
see file below:
package milestone.two.recipe.pkgclass;
public class RecipeTest {
/** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here final milestone.two.recipe.pkgclass newmilestone.two.recipe.pkgclass = new milestone.two.recipe.pkgclass(); milestone.two.recipe.pkgclass addNewmilestone.two.recipe.pkgclass = newmilestone.two.recipe.pkgclass.addNewmilestone.two.recipe.pkgclass(); newmilestone.two.recipe.pkgclass.printmilestone.two.recipe.pkgclass(); } }