I am looking for some java help for my final project \"Collection Manager Progra
ID: 3920767 • Letter: I
Question
I am looking for some java help for my final project "Collection Manager Program". I had completed all the milestones but I am new to java so don't know how to everything together and also need help in the highlighed part below. It is based on the SteppingStones labs and milestones For this project I am looking for "Ingredient Class" , "Recipe Class" , "RecipeBox" and "Applcation Programming Interface Documentation".... In this final project, you will create a basic program that will help you manage a collection of items that needs to be organized and managed. Your program must meet the requirements of the provided scenario. The creation of this program demonstrates your competency in the use of fundamental data types and more complex data structures and the creation of methods that utilize typical algorithmic control structures, object instantiation, and class definition. In order to make your program enduring, you will be adding inline comments directed toward software engineers about design decisions to facilitate the program’s ongoing maintenance, along with generating application programming interface (API) documentation for your programmatic solution that will be directed toward other software developers Scenario: You will create a program that will help you manage a collection of recipes. You will implement three classes: one for the main recipe items, one for the ingredients that are part of the recipe, and one for the entire collection of recipes. The collection should use a list data structure to store the individual items. Your collection class should include methods like addItem(), printItem(), and deleteItem() that allow you to add, print, or delete items from your collection of items. Your Ingredient class will model the items that will be stored in each recipe in your collection. You will give it some basic attributes (of numeric or string types) and some basic methods (accessors/mutators, printItemDetails(), etc.). (Variables: ingredientName, ingredientAmount, unitMeasurement, totalCalories, and ArrayList ingredientList) Your Recipe class will start off similar to your Ingredient class, but you will increase its functionality by modifying it to accept the Ingredient objects, containing all the details stored in an Ingredient class object. You will also expand the Recipe class by adding recipe-specific methods to your Recipe class. /** * Final Project * * For your Final Project: * * 1. Modify this code to develop a Recipe class: * a. change the void main method createNewRecipe() that returns a Recipe * * 2. FOR FINAL SUBMISSION ONLY:Change the ArrayList type to an * Ingredient object. When a user adds an ingredient to the recipe, * instead of adding just the ingredient name, you will be adding the * actual ingredient including name, amount, measurement type, calories. * For the Milestone Two submission, the recipeIngredients ArrayList can * remain as a String type. * * 3. Adapt the printRecipe() method to print the amount and measurement * type as well as the ingredient name. * * 4. Create a custom method in the Recipe class. * Choose one of the following options: * * a. print out a recipe with amounts adjusted for a different * number of servings * * b. create an additional list or ArrayList that allow users to * insert step-by-step recipe instructions * * c. conversion of ingredient amounts from * English to metric (or vice versa) * * d. calculate select nutritional information * * e. calculate recipe cost * * f. propose a suitable alternative to your instructor * */ Finally, you will also write an application driver class that should allow the user to create a new recipe and add it to the collection. In addition, it should allow the user to see a list of items in the collection and then give the user an option to either see more information about a particular item (by retrieving it from the collection) or edit an item that is already in the collection. Finally, your program should allow the user to delete an item from the collection. Moreover, you will add documentation to the application that will contain inline comments explaining your design decisions as well as documentation comments that will be used to generate API documentation for your programmatic solution for other software developers. To prepare for the final project, you will complete a series of six stepping stone assignments and two final project milestones that will help you learn the coding skills required for the project. Separate documentation for these assignments is included in the course resources. You have been tasked with developing a complete, modular, object-oriented program that will allow for the management of a collection. The scenario provided to you outlines all of the program’s requirements. Refer to the provided scenario to make the determinations for all data types, algorithms and control structures, methods, and classes used in your program. Your final submission should be a self-contained, fully functional program that includes all necessary supporting classes. Furthermore, you must provide inline comments in your program design that software engineers would be able to utilize for the ongoing maintenance of your program. Your programmatic solution should also be communicated through application programming interface (API) documentation to other programmers Specifically, the following critical elements must be addressed: I. Data Types: Your final program should properly employ each of the following data types that meet the scenario’s requirements where necessary: A. Utilize numerical data types that represent quantitative values for variables and attributes in your program. B. Utilize strings that represent a sequence of characters needed as a value in your program. C. Populate a list or array that allows the management of a set of values as a single unit in your program. D. Utilize inline comments directed toward software engineers for the ongoing maintenance of your program that explain your choices of data types you selected for your program. II. Algorithms and Control Structure: Your final program 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 program’s state as represented in your program’s 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 program’s goal. D. Utilize inline comments directed toward software engineers for the ongoing maintenance of your program that explain how your use of algorithms and control structures appropriately addresses the scenario’s information management problem III. Methods: Your final program should properly employ each of the following aspects of method definition as determined by the scenario’s requirements where necessary: A. Use formal parameters that provide local variables in a function’s 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. Create unit tests that ensure validity of the methods. E. Invoke methods that access the services provided by an object. F. Employ user-defined methods that provide custom services for an object. G. Utilize inline comments directed toward software engineers for the ongoing maintenance of your program that explain the purpose of the methods you implemented in your program 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 object’s behaviors. C. Create a driver class that instantiates objects for testing the constructed classes. D. 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. V. Produce reference documentation that communicates your application programming interface (API) to other programmers, using a documentation generator (Javadoc, Doxygen, etc.) - Inline comments directed toward software engineers about design decisions to facilitate the program's ongoing maintenance - Application programming interface (API) documentation for your programmatic solution directed toward other software developers Thanks
Explanation / Answer
let me know in case any query -
in limited time its not possible to cover all scenarios, you can apply your own requirments for your better uderstanding
/**********************************************************************************************/
import java.util.*;
public class Recipe {
private String name = "New Recipe";
private String instruct = "Insert your recipe here."; //instructions
private Measurement servSize = new Measurement(1.0, "unit");
private double servings = 1.0;
private List<RecipeIngredient> ingredients = new ArrayList<RecipeIngredient>();
public Recipe(Recipe recipe) {
this.name = recipe.name;
this.instruct = recipe.instruct;
this.servSize = recipe.servSize;
this.servings = recipe.servings;
this.ingredients = recipe.ingredients;
}
public Recipe() {
}
public Recipe(String name,
String instruct,
Measurement servSize,
double servings,
double rating,
List<RecipeIngredient> ingredients
){
this.name = name;
this.instruct = instruct;
this.servSize = servSize;
this.servings = servings;
this.ingredients = ingredients;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setInstructions(String instruct) {
this.instruct = instruct;
}
public String getInstructions() {
return instruct;
}
public Measurement getServingSize() {
return servSize;
}
public void setServingSize(Measurement servingSize) {
this.servSize = servingSize;
}
public double getServings() {
return servings;
}
public void setServings(double servings) {
this.servings = servings;
}
protected void setIngredients(List<RecipeIngredient> ingredients) {
this.ingredients = ingredients;
}
public List<RecipeIngredient> getIngredients() {
return ingredients;
}
@Override
public String toString()
{
return this.getName();
}
public static Recipe scaleRecipe(Recipe recipe, double scaleFactor)
{
//rebuild and scale ingredients
ArrayList<RecipeIngredient> newIngredientsList = new ArrayList<RecipeIngredient>();
for (RecipeIngredient ingredient: recipe.getIngredients())
{
if (ingredient.getAmount() == null)
newIngredientsList.add(ingredient);
else
newIngredientsList.add(ingredient.scale(scaleFactor));
}
//build the new Recipe and return
return new Recipe(
recipe.getName(),
recipe.getInstructions(),
recipe.getServingSize().scale(scaleFactor),
recipe.getServings(),
scaleFactor, newIngredientsList);
}
public Recipe scale(double scaleFactor)
{
return Recipe.scaleRecipe(this, scaleFactor);
}
public static Recipe scaleRecipeToServings(Recipe recipe, double toServings)
{
//get the scale factor, which is (fromServings / toServings)
double scaleFactor = recipe.getServings() / toServings;
//scale it
Recipe newRecipe = recipe.scale(scaleFactor);
//then fix the serving size back, it was servings count that we were tampering
newRecipe.servSize = recipe.servSize;
newRecipe.servings = toServings;
//return adjusted Recipe
return newRecipe;
}
public Recipe scaleToServings(int toServings)
{
return Recipe.scaleRecipeToServings(this, toServings);
}
@Override
public boolean equals(Object object)
{
Recipe recipe = (Recipe)object;
if (this.name.equals(recipe.name)
&& this.instruct.equals(recipe.instruct)
&& this.servings == recipe.servings
&& this.servSize.equals(recipe.servSize)
&& this.ingredients.size() == recipe.ingredients.size())
{
for (int ingredient = 0; ingredient < this.ingredients.size(); ingredient++)
{
if (!this.ingredients.get(ingredient).equals(recipe.ingredients.get(ingredient)))
return false;
}
return true;
}
return false;
}
public static Recipe addRecipes(Recipe recipeLeft, Recipe recipeRight)
{
//copy the left recipe to a new container object
Recipe newRecipe = new Recipe(recipeLeft);
//add servings from both
newRecipe.servings += recipeRight.servings;
//assemble new ingredients
newRecipe.ingredients = new ArrayList<RecipeIngredient>();
//step one: add known ingredients together
for (RecipeIngredient ingredientLeft: recipeLeft.ingredients)
//get the ingredient on the right that matches the one on the left
for (RecipeIngredient ingredientRight: recipeRight.ingredients)
//if the two ingredients have matching names
if (ingredientLeft.getName().equals(ingredientRight.getName()))
//then add them together on the newIngredients list
newRecipe.ingredients.add(ingredientLeft.add(ingredientRight));
//step two: add unknown ingredients from right to left as is
for (RecipeIngredient ingredientRight: recipeRight.ingredients)
//if the ingredient is unknown
if (!newRecipe.ingredients.contains(ingredientRight))
//then add it
newRecipe.ingredients.add(ingredientRight);
//return new recipe
return newRecipe;
}
public Recipe add(Recipe recipe)
{
return Recipe.addRecipes(this, recipe);
}
}
/*******************************************************************************************************/
public class RecipeIngredient extends Ingredient{
private Measurement amount;
public RecipeIngredient(String name) {
super(name);
}
public RecipeIngredient(String name, Measurement amount) {
super(name);
this.amount = amount;
}
public RecipeIngredient(String name, double quantity, String unit) {
super(name);
this.amount = new Measurement(quantity, unit);
}
public RecipeIngredient(String name, String measureableUnitString) {
super(name);
this.amount = new Measurement(measureableUnitString);
}
public Measurement getAmount() {
return this.amount;
}
public void setAmount(Measurement amount) {
this.amount = amount;
}
public String toString()
{
if (this.getName() != null && this.getAmount() != null)
return this.getAmount() + " " + this.getName();
else if (this.getName() != null)
return this.getAmount().toString();
else if (this.getAmount() != null)
return this.getName();
else
return "";
}
public static RecipeIngredient scaleRecipeIngredient(RecipeIngredient recipeIngredient, double scaleFactor)
{
if (recipeIngredient.getAmount() == null)
return recipeIngredient;
else
return new RecipeIngredient(recipeIngredient.getName(), recipeIngredient.getAmount().scale(scaleFactor));
}
public RecipeIngredient scale(double scaleFactor)
{
return RecipeIngredient.scaleRecipeIngredient(this, scaleFactor);
}
@Override
public boolean equals(Object object)
{
RecipeIngredient recipeIngredient = (RecipeIngredient)object;
if (super.equals(object)
&& this.amount.equals(recipeIngredient.amount))
return true;
return false;
}
public static RecipeIngredient addRecipeIngredients(RecipeIngredient recipeIngredientLeft, RecipeIngredient recipeIngredientRight)
{
return new RecipeIngredient(recipeIngredientLeft.getName(), recipeIngredientLeft.amount.add(recipeIngredientRight.amount));
}
public RecipeIngredient add(RecipeIngredient recipeIngredient)
{
//put this on the left
return RecipeIngredient.addRecipeIngredients(this, recipeIngredient);
}
}
/*******************************************************************************************/
public class Ingredient{
private String name;
public Ingredient(String name){
this.setName(name);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object object)
{
Ingredient ingredient = (Ingredient)object;
if (Application.isEquals(this.name,ingredient.name))
return true;
return false;
}
}
/**************************************************************************************/
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Arrays;
public class Measurement implements Comparable<Measurement> {
private double quantity = 0.0;
private String unit = "";
public Measurement(double quantity, String unit) {
this.quantity = quantity;
this.unit = unit;
}
public Measurement(String measurableUnitString) {
if (!measurableUnitString.trim().isEmpty())
{
try
{
//grab amount quantity
this.quantity = Double.parseDouble(measurableUnitString.replaceAll("[A-Z,a-z, ]", ""));
}
catch (Exception e)
{
}
}
//grab amount unit
this.unit = measurableUnitString.replaceAll("\.|[0-9]", "").trim();
}
public double getQuantity() {
return quantity;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public void setQuantity(double quantity) {
this.quantity = quantity;
}
@Override
public String toString()
{
if (this.getUnit() != null)
return this.getQuantity() + " " + this.getUnit();
else
return new Double(this.getQuantity()).toString();
}
public int compareTo(Measurement o)
{
if (this.getUnit() != o.getUnit())
{
System.err.println("compareTo() hit on MeasurableUnit with different units specified. You shouldn't compare apples and oranges if you expect a similar result. Will supply mathematical differenc, but fix your units.");
}
return Double.compare(this.getQuantity(), o.getQuantity());
}
public static Measurement scaleMeasurableUnit(Measurement measurement, double scaleFactor)
{
Measurement newMeasurement = null;
try {
newMeasurement = (Measurement)measurement.clone();
newMeasurement.quantity *= scaleFactor;
} catch (CloneNotSupportedException ex) {
Application.dumpException("The was a problem cloning the Measurable Unit object. Clone is not supported.", ex);
}
return newMeasurement;
}
public Measurement scale(double scaleFactor)
{
return Measurement.scaleMeasurableUnit(this, scaleFactor);
}
public static Measurement measurementToOunces(Measurement measurement)
{
//TODO: Update whether this is dry or fluid ounces.
return new Measurement(measurementToOunces(measurement.getQuantity(), measurement.getUnit()), "ounces");
}
public static double measurementToOunces(double quantity, String unit)
{
double ounces = quantity;
if (unit.equals(USAUnits.POUNDS) || unit.equals(USAUnits.PINTS))
ounces *= 16.0;
else if (unit.equals(USAUnits.GALLONS))
ounces *= 128.0;
else if (unit.equals(USAUnits.QUARTS))
ounces *= 32.0;
else if (unit.equals(USAUnits.CUPS))
ounces *= 8.0;
else if (unit.equals(USAUnits.TABLESPOONS))
ounces *= .5;
else if (unit.equals(USAUnits.TEASPOONS))
ounces *= .167;
else if (unit.equals(USAUnits.LIQUID_OUNCES) || unit.equals(USAUnits.DRY_OUNCES))
{
//ounces = ounces;
//so do nothing
}
else
{
ounces = 0.0;
System.err.println("Error: Unknown measurement unit provided for conversion.");
}
return ounces;
}
public Measurement toOunces()
{
return Measurement.measurementToOunces(this);
}
@Override
public boolean equals(Object obj)
{
if (obj == null)
return false;
Measurement measurement = (Measurement)obj;
if (this.unit != null && measurement.unit != null && !this.unit.equals(measurement.unit))
return false;
else if (this.quantity != measurement.quantity)
return false;
return true;
}
public static Measurement addMeasurements(Measurement measurementLeft, Measurement measurementRight)
{
return new Measurement(measurementLeft.quantity+measurementRight.quantity,
measurementLeft.unit);
}
public Measurement add(Measurement measurement)
{
//put this on the left
return Measurement.addMeasurements(this, measurement);
}
public static class USAUnits
{
//USA units
public static final String POUNDS = "pounds";
public static final String GALLONS = "gallons";
public static final String QUARTS = "quarts";
public static final String PINTS = "pints";
public static final String CUPS = "cups";
public static final String LIQUID_OUNCES = "fluid ounces"; // Volume
public static final String DRY_OUNCES = "ounces (dry)"; // Weight
public static final String TABLESPOONS = "tablespoons";
public static final String TEASPOONS = "teaspoons";
/**
* All US Customary measurement units.
*/
public static final String[] ALL_UNITS = new String[] {
POUNDS,
GALLONS,
QUARTS,
PINTS,
CUPS,
LIQUID_OUNCES,
DRY_OUNCES,
TABLESPOONS,
TEASPOONS
};
public static String[] getAllUSAUnits()
{
ArrayList<String> fields = new ArrayList<String>();
USAUnits usaUnits = new USAUnits();
for (Field field : usaUnits.getClass().getDeclaredFields())
{
if (field.getType().getName().equals(new String().getClass().getName()))
try {
fields.add((String)field.get(new USAUnits()));
} catch (IllegalAccessException ex) {
Application.dumpException("Error getting unit from USAUnits.", ex);
} catch (IllegalArgumentException ex) {
Application.dumpException("Error getting unit from USAUnits.", ex);
}
}
return fields.toArray(new String[] {});
}
}
public static class MetricUnits
{
//metric units
public static final String GRAMS = "grams";
public static final String MILLIGRAMS = "milligrams";
/**
* All Metric units.
*/
public static final String[] ALL_UNITS = new String[] {
GRAMS,
MILLIGRAMS
};
public static String[] getAllMetricUnits()
{
ArrayList<String> fields = new ArrayList<String>();
MetricUnits metricUnits = new MetricUnits();
for (Field field : metricUnits.getClass().getFields())
{
if (field.getType().getName().equals(new String().getClass().getName()))
try {
fields.add((String)field.get(new MetricUnits()));
} catch (IllegalAccessException ex) {
Application.dumpException("Error getting unit from MetricUnits.", ex);
} catch (IllegalArgumentException ex) {
Application.dumpException("Error getting unit from MetricUnits.", ex);
}
}
return fields.toArray(new String[] {});
}
}
public static class FoodUnits
{
public static final String CALORIES = "Calories"; //capitalize, because calories != Calories, sometimes also called kCals.
public static final String[] ALL_UNITS = new String[] {
CALORIES
};
public static String[] getAllFoodUnits()
{
ArrayList<String> fields = new ArrayList<String>();
FoodUnits foodUnits = new FoodUnits();
for (Field field : foodUnits.getClass().getDeclaredFields())
{
if (field.getType().getName().equals(new String().getClass().getName()))
try {
fields.add((String)field.get(new FoodUnits()));
} catch (IllegalAccessException ex) {
Application.dumpException("Error getting unit from FoodUnits.", ex);
} catch (IllegalArgumentException ex) {
Application.dumpException("Error getting unit from FoodUnits.", ex);
}
}
return fields.toArray(new String[] {});
}
}
public static String[] getAllUnits()
{
ArrayList<String> allUnits = new ArrayList<String>();
allUnits.addAll(Arrays.asList(USAUnits.getAllUSAUnits()));
allUnits.addAll(Arrays.asList(MetricUnits.getAllMetricUnits()));
allUnits.addAll(Arrays.asList(FoodUnits.getAllFoodUnits()));
return allUnits.toArray(new String[] {});
}
public static String[] getAllMeasurementUnits()
{
ArrayList<String> allUnits = new ArrayList<String>();
allUnits.addAll(Arrays.asList(USAUnits.getAllUSAUnits()));
allUnits.addAll(Arrays.asList(MetricUnits.getAllMetricUnits()));
return allUnits.toArray(new String[] {});
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.