Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***Need some help with a java program*** Create a class called Conversion and add three fields: first - which stores the name of a unit

***Need some help with a java program***

Create a class called Conversion and add three fields: first - which stores the name of a unit of measure (cups, pints, oz., etc.). second - which stores the name of another unit of measure. factor - which stores the amount that you must multiply a quantity of the first unit by to get a quantity of the second unit. For example, if the first unit was cups and the second pints, the factor would be 0.5. Or if the first unit was cups and the second ounces, the factor would be 8. Add a constructor with parameters for each field and then add accessors for each of the fields in the Conversion class.

Create another class called Cookbook with three fields, name - for the name of the cookbook. recipes - for a flexibly-sized collection of recipes, in alphabetical order. conversions - stores a flexibly-sized collection of conversions, in no particular order. Add a constructor for the Cookbook class with one parameter for the new cookbook's name and a new recipe has no recipes or conversions. Also add an accessor for the name field of cookbook..... Add a method called addConversion to the Cookbook class. It should one parameter, which is a Conversion object to add to the collection..... Add another method named addConversion to the Cookbook class thas has three parameters: two units of measure and a conversion factor, and should construct a Conversion instance and add it to the collection.....Add a method named removeConversions to the Cookbook class that has two parameters, both of which are units of measure. It should remove from the collection any conversions between those units of measure (there may be more than one).....Add a method named convert to the Cookbook class that has three parameters: two units of measure and a quantity. It should look for a conversion in the collection that is between the two units of measure, apply the conversion factor to the quantity, and return the result. If the first unit of measure in the parameters is also the first in the conversion, you will multiply by the factor. But if the first unit of measure in the parameters is the second in the conversion, you will divide by the factor. If there are no known conversion between the units of measure, just return the original quantity......Add a method named addRecipe to the Cookbook class that has one parameter, which is an object from an outside class called Recipe, add it to the collection. This method will need to insert it at the correct location to ensure that the collection of recipes stays in alphabetical order by recipe name....Add a method named getRecipe to the Cookbook class with one parameter, which is the name of the recipe. It should return the recipe with that name, or null if no recipe exists with that name. If there is more than one recipe with that name, just return one of them....Add a method named removeRecipe to the Cookbook class that has one parameter, which is the name of a recipe. It should remove all recipes with that name from the collection.....

Create a method called canMake in the Cookbook class with two parameters: a recipe, and a collection of ingredients that represents all the unique ingredients that represents all the food you have in your home (order does not matter). It should return true if you have enough of every ingredient required by the recipe. Otherwise, it should return false. (You can assume no type of ingredient appears twice.) (This could require some conversions, ex) get a recipe that requires 2 cups of sugar and 3 tablespoons of butter, and we have 5 cups of sugar and 1 stick of butter. We also have a conversion that 1 stick = 8 tablespoons. We can make this recipe, because 5 cups of sugar is at least 2 cups of sugar, and 1 stick of butter is the same as 8 tablespoons of butter, which is at least 3 tablespoons of butter. ) ...... Create a method called getMakeable in the Cookbook class with one parameter, a collection of unique ingredients that represents all the food you have in your home (order does not matter). It should return a collection of all recipes that you can make with those ingredients, in alphabetical order by recipe name...... Add a static method named getGroceryList to the Cookbook class with one parameter, a collection of recipes that you intend to prepare during the week. It should return a collection of all the unique ingredients that will be needed to make those recipes. If two recipes require the same ingredient, with the same unit of measure, they should be combined. (example: make a recipe that require 3 cups of sugar and another that requires 4 cups of sugar, your collection should contain one entry of 7 cups of sugar. However, if one recipe requires 3 cups of sugar and another requires 3 tablespoons of sugar, you can leave that as two different entries.)

Lastly, write some early exits for your loops in previous methods and write a main method to test all of the methods you created....

***Note***:: This program references an outside class called Recipe with fields of: A String name, A String category, A HashSet..Set ingredients, and an ArrayList: LinkedList instructions; (if needed, i can post the whole class, but I don't think it's necessary) ***Also note: if you need reference to the code of the previous two classes, they are here: https://www.chegg.com/homework-help/questions-and-answers/need-help-java-program-given-two-premade-classes-listed-create-class-called-conversion-add-q25345939

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions