Assignment 6: Customizing Constructors
Goals: Practice overloading constructors, checking for data constraints, and utilizing static methods and constants.
You should submit one .java file containing the solution to this problem.
Be sure to properly test your code and write purpose statements for your methods. A lack of tests and documentation will result in a lower grade! Remember that testing requires you to make some examples of data in an examples class.
Bagels
A BagelRecipe can be represented as the amount of flour, water, yeast, salt, and malt in the recipe. A perfect bagel results when the ratios of the weights are right:
all weights should be greater than 0
the weight of the flour should be equal to the weight of the water
the weight of the yeast should be equal the weight of the malt
the weight of the salt + yeast should be 1/20th the weight of the flour
Design the BagelRecipe class. The fields should be of type double and represent the weight of the ingredients as ounces. Provide two constructors for this class:
Given that we are working with doubles, we need to be careful about number comparison. For this assignment, any two doubles within 0.001 of each other are considered equal. Math.abs will likely prove helpful.
Your main constructor should take in all of the fields and enforce all above constraints to ensure a perfect bagel recipe.
Provide another constructor that only requires the weights of flour and yeast, and produces a perfect bagel recipe.
Implement the method boolean sameRecipe(BagelRecipe other) which returns true if the same ingredients have the same weights and test is.
Consolidate as much duplicate code as possible into appropriate static methods. If you have time, write explicit tests for these, but their thorough usage in other methods can count for test coverage if you don’t.