Question

1. Write a class that represents a Recipe as shown in the UML diagram below. Recipe -name: string -cookTime: int -prepTime: i
0 0
Add a comment Improve this question Transcribed image text
Answer #1

screenshot

import java.util.ArrayList; public class Recipe { private String name; private int cookTime; private int perpTime; private Ar

String getName() { return this.name; } int getTotalRecipeTime() { return this.cookTime+this.perpTime; } String getIngredient(

code

import java.util.ArrayList; public class Recipe { private String name; private int cookTime; private int perpTime; private ArrayList<String> ingredients; public Recipe(String name, int cookTime, int perpTime, ArrayList<String> ingredients) { this.name = name; this.cookTime = cookTime; this.perpTime = perpTime; this.ingredients = ingredients; } public Recipe(String name, int cookTime, int perpTime) { this.name = name; this.cookTime = cookTime; this.perpTime = perpTime; ingredients = new ArrayList<String>(); } int getNumberOfIngredients(){ return ingredients.size(); } void addIngredient(String ingredient){ ingredients.add(ingredient); } String getName(){ return this.name; } int getTotalRecipeTime(){ return this.cookTime+this.perpTime; } String getIngredient(int index){ if(index<0||index>=ingredients.size()){ return "Not valid"; } return ingredients.get(index); } String removeIngredient(String ingredient){ if(ingredients.remove(ingredient)){ return "Successful"; }else{ return "Error"; } } } 
Add a comment
Know the answer?
Add Answer to:
1. Write a class that represents a Recipe as shown in the UML diagram below. Recipe...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to build Java test class? I am supposed to create both a recipe class, and...

    How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...

  • Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input...

    Prompt: In this stepping stone lab assignment, you will build a Recipe class, getting user input to collect the recipe name and serving size, using the ingredient entry code from Stepping Stone Lab Four to add ingredients to the recipe, and calculating the calories per serving. Additionally, you will build your first custom method to print the recipe to the screen. Specifically, you will need to create the following:  The instance variables for the class (recipeName, serving size, and...

  • JAVA PLEASE HELP The following is a UML diagram for a class. Write the code for...

    JAVA PLEASE HELP The following is a UML diagram for a class. Write the code for this class. Cat - breed : String - color : Color - name : String + Cat( name : String) + Cat(name : String, breed : String, color : Color) + getName() : String + getColor() : Color + getBreed() : String setColor(Color) setBreed(Breed) toString()

  • Can someone help me with my code.. I cant get an output. It says I do...

    Can someone help me with my code.. I cant get an output. It says I do not have a main method. HELP PLEASE. The instruction are in bold on the bottom of the code. package SteppingStones; //Denisse.Carbo import java.util.Scanner; import java.util.ArrayList; import java.util.List; public class SteppingStone5_Recipe { private String recipeName; private int servings; private List<String> recipeIngredients; private double totalRecipeCalories; public String getRecipeName() { return recipeName; } public void setRecipeName (string recipeName){ this.recipeName = recipeName; } public int getServings() { return...

  • Write a Java class named Employee to meet the requirements described in the UML Class Diagram...

    Write a Java class named Employee to meet the requirements described in the UML Class Diagram below: Note: Code added in the toString cell are not usually included in a regular UML class diagram. This was added so you can understand what I expect from you. If your code compiles cleanly, is defined correctly and functions exactly as required, the expected output of your program will solve the following problem: “An IT company with four departments and a staff strength...

  • What this Lab Is About: Given a UML diagram, learn to design a class Learn how...

    What this Lab Is About: Given a UML diagram, learn to design a class Learn how to define constructor, accessor, mutator and toStringOmethods, etc Learn how to create an object and call an instance method. Coding Guidelines for All ments You will be graded on this Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. Use upper case for constants. Use title case (first letter is u case)...

  • Draw the UML class diagram in Java and write theequivalent Java code.Exercise 6 Person...

    Draw the UML class diagram in Java and write the equivalent Java code.Exercise 6 Person + name: string + age : int=0 Student + grades: list Professor + listofstudents : list

  • Create a class named Game using the following UML class diagram. GAME -gameName : string +Game()...

    Create a class named Game using the following UML class diagram. GAME -gameName : string +Game() +setGameName(in name : string) : void +getGameName() : string +displayMessage() : void This class has 2 member variables namely playerName and playerScore. The class contain following member functions: Constructor, set function, get functions, display function. Code write in 3 files: Game.h header file, funtion.cpp file and main.cpp file. The output should be: Player John has scored 50 points.

  • Answer the following questions regarding the UML Diagram: Human 998 - name: String - breed: String...

    Answer the following questions regarding the UML Diagram: Human 998 - name: String - breed: String + name: String + phone: Int kitties + Cat(name: String, breed: String) + getName(): String + setName(name: String): void What symbol would i put in front of breed to make it a private attribute of Cat? it is already private none of the above

  • Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditiona...

    Hi. Could you help me with the code below? I need to validate the code below, using expressions that can carry out the actions or that make appropriate changes to the program’s state, using conditional and iterative control structures that repeat actions as needed. The unit measurement is missing from the final output and I need it to offer options to lbs, oz, grams, tbsp, tsp, qt, pt, and gal. & fl. oz. Can this be added? The final output...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT