Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with ensuring my code meets the requirements listed in this prompt Also need help building a test class for this code: Overview:

I need help with ensuring my code meets the requirements listed in this prompt Also need help building a test class for this code: Overview: In your final project, you will create a program that will help you manage a collection of recipes. The Recipe class you build for this milestone will hold all the details of the recipe, the methods to create a new recipe, and a method to print a recipe. In your final project submission, this class will also contain a custom method to add a new feature. In your submission for Milestone Two, you will include commented out pseudocode for this method. Prompt: In this milestone, you submit the final project version of your Recipe class.

Your submission should include the Recipe.java file and a Recipe_Test.java file.

Your 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 Your 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 Specifically, the following critical elements of the final project are addressed: I. Data Types: Your Recipe class should properly employ each of the following data types that meet the scenarios requirements where necessary: A. Utilize appropriate numerical and string data types to represent values for variables and attributes in your program. B. Populate a list or array that allows the management of a set of values as a single unit in your program. II. Algorithms and Control Structure: Your Recipe class should properly employ each of the following control structures as required or defined by the scenario where necessary: A. Utilize expressions or statements that carry out appropriate actions or that make appropriate changes to your programs state as represented in your programs variables. B. Employ the appropriate conditional control structures that enable choosing between options in your program. C. Utilize iterative control structures that repeat actions as needed to achieve the programs goal. III. Methods: Your Recipe class should properly employ each of the following aspects of method definition as determined by the scenarios requirements where necessary: A. Use formal parameters that provide local variables in a functions definition. B. Use actual parameters that send data as arguments in function calls. C. Create both value-returning and void functions to be parts of expressions or stand-alone statements in your program. D. Invoke methods that access the services provided by an object. E. Describe a user-defined method that provides custom services for an object. F. Create unit tests that ensure validity of the methods. IV. Classes: Construct classes for your program that include the following as required by the scenario where necessary: A. Include attributes that allow for encapsulation and information hiding in your program. B. Include appropriate methods that provide an objects behaviors. V. Documentation: Utilize inline comments directed toward software engineers for the ongoing maintenance of your program that explain the decisions you made in the construction of the classes in your program.

public class Recipe { private String recipeName; private int servings; private List recipeIngredients; private double totalRecipeCalories;

/** * */ private List listofRecipes = new ArrayList<>(); /** * * @return the recipeName */ //accessors and mutators public String getRecipeName() { return recipeName; }

/** * * @param recipeName */ public void setRecipeName(String recipeName) { this.recipeName = recipeName; } /** * * @return */ public int getServings() { return servings; } /** * * @param servings */ public void setServings(int servings) { this.servings = servings; } /** * * @return */ public List getRecipeIngredients() { return recipeIngredients; } /** * * @param recipeIngredients */ public void setRecipeIngredients(List recipeIngredients) { this.recipeIngredients = recipeIngredients; } /** * * @return the total recipe calories */ public double getTotalRecipeCalories() { return totalRecipeCalories; } /** * * @param totalRecipeCalories */ public void setTotalRecipeCalories(double totalRecipeCalories) { this.totalRecipeCalories = totalRecipeCalories; }

/** * default constructor */ public Recipe() { this.recipeName = ""; this.servings = 0; this.recipeIngredients = new ArrayList <>(); this.totalRecipeCalories = 0; } //overloaded constructor to create custom recipe

/** * * @param recipeName * @param servings * @param recipeIngredients * @param totalRecipeCalories */ public Recipe(String recipeName, int servings, ArrayList recipeIngredients, double totalRecipeCalories) { this.recipeName = recipeName; this.servings = servings; this.recipeIngredients = recipeIngredients; this.totalRecipeCalories = totalRecipeCalories; }

/** * method to print recipe */ public void printRecipe() { int singleServingCalories = 0; singleServingCalories = (int) (this.getTotalRecipeCalories()/this.getServings()); System.out.println("Recipe: " + this.getRecipeName()); System.out.println("Serves: " + this.getServings()); System.out.println("Ingredients: "); for(Ingredient ingredients : getRecipeIngredients()) { System.out.println("Ingredient name: " + ingredients.getnameOfIngredient() ); System.out.println("Ingredient Amount: " + ingredients.getingredientAmount() ); System.out.println(" Calories with measurement: " + ingredients.unitMeasurement + "Each serving has " + singleServingCalories); } } /** * * @return add new recipe per user inputs */

public Recipe addNewRecipe() { double totalRecipeCalories = 0.0; 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 { Ingredient thisIngredient = new Ingredient(); 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; // "end" discomtinues the loop } else { thisIngredient.setnameOfIngredient(ingredientName); //adding ingredient to recipe list System.out.println("Please enter the ingredient amount: "); //prompt to enter the ingredient amount float ingredientAmount = scnr.nextFloat(); thisIngredient.setIngredientAmount(ingredientAmount); System.out.println("Please enter the ingredient Calories: "); //prompt to enter the ingredient calories int ingredientCalories = scnr.nextInt(); thisIngredient.setNumberOfCaloriesPerIngredient(ingredientCalories); //Add the total Calories from this ingredient totalRecipeCalories = totalRecipeCalories + (ingredientCalories * ingredientAmount); getRecipeIngredients().add(thisIngredient); } } while (addMoreIngredients); //looping to add ingredients from user unless "end" //create new recipe with user inputs Recipe recipe; recipe = new Recipe(recipeName,servings, (ArrayList) getRecipeIngredients(), totalRecipeCalories); recipe.printRecipe(); return recipe; }

/** * @return the listofRecipes */ public List getListofRecipes() { return listofRecipes; }

/** * @param listofRecipes the listofRecipes to set */ public void setListofRecipes(List listofRecipes) { this.listofRecipes = listofRecipes; }

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

Step: 3

blur-text-image

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

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

Students also viewed these Databases questions

Question

=+Do you want to work from home?

Answered: 1 week ago

Question

=+ What skills and competencies will enable someone

Answered: 1 week ago

Question

=+to live and work wherever he or she wants?

Answered: 1 week ago