Class Methods - Public and Private
Bunny.java
BunnyTestHarness.java
can of spam ($1.89)In this class, (except inside the accessors and mutators themselves) use the accessors and mutators instead of the bare instance variables every time you need to use an instance var. EVERY TIME. ☑ Add a method cheaper which takes another StoreItem. It returns whichever StoreItem is cheaper, this item or the one passed in. ☑ In a separate class with a main, create three StoreItems: one keeping the default values, one using the parameterized constructor, and one using the default constructor then setting values using the mutators. Check that your cheaper method works. Part B It turns out that a single number is too simple to keep track of all the information about the price of our items It turns out that the price is determined by the base price (that we paid the manufacturer) plus some amount of markup. So, for instance, if the base price is 10 and the markup amount is .10, then the final price with markup is 10 +.10 =10.10. ☑ Back in StoreItem, add instance variables basePrice and markup. Add accessors and mutators and make sure that markup starts as a default of $.10, but leave the rest of the methods as originally written. ☑ In the old accessor for price, return an expression that calculates a final price as described, based on the new variables, and returns this result instead of the old price variable. ☑ In the old mutator for price, use the markup to work backward from the price passed in, and set the basePrice accordingly. We are assuming that if someone tries to set the price rather than the base price, they don't know about the new system and are doing the math for markup themselves (with the default markup) to get the price they pass in, and we need to undo it, removing the markup. So if they give us a price of 11, and we assume the markup is .10, to find the base price... (you figure out the algebra, and make Java do the right math.) ☑ Now remove the old price instance variable, and everything including your main should still work by using your updated "accessor" and "mutator" for price (if not, figure out where you were not using accessors and mutators). ☑ Change the main so that for the StoreItem you previously left with default values, you now set the basePrice and markup through the mutators. (hint: when you made these changes, you should have been using the accessors and mutators for the NEW instance variables everywhere too!)