Question: Part la: Creating the Fruit class In Fruit.java add an abstract class called Fruit that implements Cloneable and Copyable. In this class add: The private

Part la: Creating the Fruit class In Fruit.java add an abstract class called Fruit that implements Cloneable and Copyable. In this class add: The private data fields private double mass; private boolean isJuiceRemoved; The protected constructor Fruit (double theMass) which initializes mass to theMass and initializes is JuiceRemoved to false. If theMass is less than or equal to zero, then mass must be set to 1. A protected copy constructor (copy constructors will be talked about in Friday's lecture, February 11). This will be called from subclasses of Fruit. The public get method getMass() for mass. The protected set method setMass (double value) for mass. If value is less than or equal to zero, then mass must be set to 1. The public get method is JuiceExtracted() for is JuiceRemoved. The method protected abstract double juiceRatio(); The method public double extract Juice () { double liquidMass = amount Juice(); if (!is JuiceRemoved) { is JuiceRemoved = true; mass - liquidMass; } return liquidMass; } . The method public double amount Juice() { if (is JuiceRemoved) return 0.0; return mass * juiceRatio(); } Override the equals method to do a deep comparison. Override the hashCode method using the procedure described in lecture. Override the clone method to make a deep copy (we will go over method clone in Friday's lecture, February 11). Override the toString method as follows: @Override public String toString() { return "\tmass = " + mass + " \tis JuiceExtracted -" + is JuiceRemoved + " "; } The abstract method juiceRatio() is to be overridden in subclasses. Its purpose is to return the ratio of mass that can be extracted as juice. For example: if 75% of the fruit can be extracted as juice, then this method would return 0.75. The method extract Juice() extracts the juice from the fruit. The amount of extracted juice is returned as a double. The remaining mass that cannot be extracted as juice is set as the new mass of the fruit. Method amount Juice () returns the amount of juice (rather than the ratio) that can be extracted without actually extracting it. Part la: Creating the Fruit class In Fruit.java add an abstract class called Fruit that implements Cloneable and Copyable. In this class add: The private data fields private double mass; private boolean isJuiceRemoved; The protected constructor Fruit (double theMass) which initializes mass to theMass and initializes is JuiceRemoved to false. If theMass is less than or equal to zero, then mass must be set to 1. A protected copy constructor (copy constructors will be talked about in Friday's lecture, February 11). This will be called from subclasses of Fruit. The public get method getMass() for mass. The protected set method setMass (double value) for mass. If value is less than or equal to zero, then mass must be set to 1. The public get method is JuiceExtracted() for is JuiceRemoved. The method protected abstract double juiceRatio(); The method public double extract Juice () { double liquidMass = amount Juice(); if (!is JuiceRemoved) { is JuiceRemoved = true; mass - liquidMass; } return liquidMass; } . The method public double amount Juice() { if (is JuiceRemoved) return 0.0; return mass * juiceRatio(); } Override the equals method to do a deep comparison. Override the hashCode method using the procedure described in lecture. Override the clone method to make a deep copy (we will go over method clone in Friday's lecture, February 11). Override the toString method as follows: @Override public String toString() { return "\tmass = " + mass + " \tis JuiceExtracted -" + is JuiceRemoved + " "; } The abstract method juiceRatio() is to be overridden in subclasses. Its purpose is to return the ratio of mass that can be extracted as juice. For example: if 75% of the fruit can be extracted as juice, then this method would return 0.75. The method extract Juice() extracts the juice from the fruit. The amount of extracted juice is returned as a double. The remaining mass that cannot be extracted as juice is set as the new mass of the fruit. Method amount Juice () returns the amount of juice (rather than the ratio) that can be extracted without actually extracting it
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
