Question: How do I write pseudocode for this? I am confused. I started writing pseudocode but i'm not sure if it is correct. Also, the code

How do I write pseudocode for this? I am confused. I started writing pseudocode but i'm not sure if it is correct. Also, the code I received help for is below starting with *****recipe****.

*****WritePseudocode****

Create and initialize new String "recipeName"

Arraylist String "recipeIngredients"

Private int "totalRecipeCalories"

Do

Prompts the user to "enter the recipe name"

Add input to Arraylist

Prompts user to "enter number of servings"

It will then ask if the user wants to enter more information or type "end" if you are finished.

Loop to be used if to add more ingredients

***********Recipe***********

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; } }

*******RecipeTest****

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() } } **************************************

Create and initialize new String "recipeName"

Arraylist String "recipeIngredients"

Private int "totalRecipeCalories"

Do

Prompts the user to "enter the recipe name"

Add input to Arraylist

Prompts user to "enter number of servings"

It will then ask if the user wants to enter more information or type "end" if you are finished.

Loop to be used if to add more ingredients

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!