Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Good morning - can I have a tutor check my work based off of the instructions below? I am not sure if I have done

Good morning - can I have a tutor check my work based off of the instructions below? I am not sure if I have done it correctly or not. And if I have not, can someone please assist with my code? I think the requirements states I need a print function as well? I would greatly appreciate it!!! I will post my code output results below after it has been ran. I am not sure if my code needs cleaned up or is missing anything.

IT 511 Milestone Two Guidelines and Rubric The Recipe Class

****************************************Instructions*******************************************

"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"

Code -

***************************Ingredient****************************

package Recipe;

import java.util.Scanner;

import java.util.ArrayList;

/** * * @author rbell */ class Recipe {

private String recipeName; private int servings; ArrayList recipeIngredients = new ArrayList(); private int totalRecipeCalories; //Accessors and Mutators for the Instance Variables

/** * * @param recipeName */ public void setRecipeName(String recipeName) { this.recipeName = recipeName; }

/** * * @return */ public String getRecipeName() { return recipeName; }

/** * * @param servings */ public void setServings(int servings) { this.servings = servings; }

/** * * @return */ public int getServings() { return servings; }

/** * * @param recipeIngredients */ public void setRecipeIngredients(ArrayList recipeIngredients) { this.recipeIngredients = recipeIngredients; }

/** * * @return */ public ArrayList getRecipeIngredients() { return recipeIngredients; }

/** * * @param totalRecipeCalories */ public void setTotalRecipeCalories(int totalRecipeCalories) { this.totalRecipeCalories = totalRecipeCalories; }

/** * * @return */ public int getTotalRecipeCalories() { return totalRecipeCalories; }

/* Constructors to use for preset fields */

public Recipe() { this.recipeName = ""; this.servings = 0; this.recipeIngredients = new ArrayList(); this.totalRecipeCalories = 0; } //Overloaded Constructor

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

/* Method used to Print the Recipe Details */

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.size(); i++) { String ingredient = recipeIngredients.get(i); System.out.println(ingredient); } System.out.println("Each Serving Has " + singleServingCalories + " Calories."); } //Method to create a New Recipe so that you can Build Recipes Based on the User's Input

/** * * @param args * @return */

public Recipe addNewRecipe() { //bint totalRecipeCalories = 0; ArrayList recipeIngredients = new ArrayList(); boolean addMoreIngredients = false; Scanner scnr = new Scanner(System.in); System.out.print("Please enter the recipe name: "); String recipeName = scnr.nextLine(); System.out.print("Please enter the number of servings: "); servings = scnr.nextInt(); scnr.nextLine(); //do loop function to be used to add more ingredients. do { System.out.print("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; break; } else { recipeIngredients.add(ingredientName); addMoreIngredients = true; System.out.print("Please enter the number of units of the ingredient to be used: "); int ingredientAmount = scnr.nextInt(); System.out.print("Please enter the ingredient Calories per unit: "); int ingredientCalories = scnr.nextInt(); scnr.nextLine(); totalRecipeCalories = (ingredientCalories * ingredientAmount); } } while (addMoreIngredients == true); Recipe newRecipe; newRecipe = new Recipe(recipeName, servings, recipeIngredients, totalRecipeCalories); newRecipe.printRecipe(); return newRecipe; } }

***************************IngredientTest*********************************

package Recipe;

/** * * @author rbell */ public class RecipeTest {

/** * @param args the command line arguments */ public static void main(String[] args) { final Recipe newRecipe = new Recipe(); //Constructor used to create the new Recipe newRecipe.addNewRecipe(); //Invoke function to addNewRecipe() newRecipe.printRecipe(); //Access used to printRecipe() } }

****Code after it is ran****

run: Please enter the recipe name: pizza Please enter the number of servings: 2 Please enter the ingredient name or type 'end' if you are finished entering ingredients: flour Please enter the number of units of the ingredient to be used: 3 Please enter the ingredient Calories per unit: 44 Please enter the ingredient name or type 'end' if you are finished entering ingredients: end

Recipe: pizza Serves: 2 Ingredients: flour Each Serving Has 66 Calories.

Recipe: Serves: 2 Ingredients: Each Serving Has 66 Calories. BUILD SUCCESSFUL (total time: 17 seconds)

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

How does the concept of hegemony relate to culture?

Answered: 1 week ago