Question
OOP, Class Hierarchies and Interfaces. 4. Create three abstract classes Fresh, Soft and Firm that extends Cheese These classes have: A protected constructor with three
OOP, Class Hierarchies and Interfaces.
4. Create three abstract classes Fresh, Soft and Firm that extends Cheese
These classes have:
- A protected constructor with three parameters: name, type, and fat percentage.
5. Create the Mozzarella, Brie, Parmesan and Cheddar classes
Class Mozzarella extends Fresh, Brie extends Soft and Parmesan and Cheddar extend Firm all have:
- A constructor with two parameters: name, and fatPercentage. Be sure to set the CheeseType correctly.
- A constructor with one parameter: name. This constructor should set the fatPercentage to a random value between 5% and 60%. Be sure to set the CheeseType correctly.
6. Create the ManoaCheeseFromager class
Create a ManoaCheeseFromager singleton class that can create Mozzarella, Brie, Parmesan and Cheddar Cheeses. Singleton classes have a static method getInstance() that returns the one and only one instance of the class. The class must implement the CheeseFromager interface.
Heres a screen shot of my ManoaCheeseFromager class.
Notice there are no Problems in my project. That means that there are no compile or checkstyle errors.
Implement the CheeseFromager methods. The makeCheese method should check the CheeseType then bake a random Cheese of that type.
At this point you can test your code with ManoaCheeseFromagerTest.java. We are going to use the JUnit tests to evaluate your homework for correctness.
7. (Optional) Create some Comparators
Next weeks homework is sorting an array of Cheese. You will need to create two comparators to do the sorting, so you can get a head start on next weeks homework by:
-
Creating a FatComparator that implements Comparator
deciding based upon the Cheeses fat percentage values. -
Creating an TypeComparator that implements Comparator
deciding based upon the type of the Cheeses.
You can test your comparators using CheeseComparatorTest.java.
package edu.ics211.h02;
/**
* Represents a Cheese.
*
* @author .
*
*/
public abstract class Cheese implements Comparable
private String name;
private CheeseType type;
private Double fatPercentage;
/**
* Creates a new Cheese.
*
* @param name the name of this cheese.
* @param type the type of this cheese.
* @param fatPercentage the fate percentage of this cheese.
*/
protected Cheese(String name, CheeseType type, Double fatPercentage) {
super();
this.name = name;
this.type = type;
this.fatPercentage = fatPercentage;
}
/**
* Returns the name.
*
* @return the name.
*/
public String getName() {
return name;
}
package edu.ics211.h02;
/**
* Represents a CheeseFromager.
*
* @author .
*
*/
public interface CheeseFromager {
/**
* Makes a Cheese with the given name, type and fat percentage.
*
* @param name the name of the cheese.
* @param type the type of the cheese.
* @param fatPercentage the fat percentage of the cheese.
* @return a new instance of Cheese.
*/
Cheese makeCheese(String name, CheeseType type, Double fatPercentage);
/**
* Makes a Cheese with the given name, type and a random fat percentage.
*
* @param name the name of the cheese.
* @param type the type of the cheese.
* @return a new instance of Cheese.
*/
Cheese makeCheese(String name, CheeseType type);
/**
* Makes a Mozzarella with the given name and fat percentage.
*
* @param name the name of the mozzarella.
* @param fatPercentage the fat percentage
* @return a new instance of Mozzarella.
*/
Cheese makeMozzarella(String name, Double fatPercentage);
/**
* Makes a Mozzarella with the given name and random fat percentage.
*
* @param name the name of the mozzarella.
* @return a new instance of Mozzarella.
*/
Cheese makeMozzarella(String name);
/**
* Makes a Brie with the given name and fat percentage.
*
* @param name the name of the brie.
* @param fatPercentage the fat percentage
* @return a new instance of Brie.
*/
Cheese makeBrie(String name, Double fatPercentage);
/**
* Makes a Brie with the given name and random fat percentage.
*
* @param name the name of the brie.
* @return a new instance of Brie.
*/
Cheese makeBrie(String name);
/**
* Makes a Cheddar with the given name and fat percentage.
*
* @param name the name of the cheddar.
* @param fatPercentage the fat percentage
* @return a new instance of Cheddar.
*/
Cheese makeCheddar(String name, Double fatPercentage);
/**
* Makes a Cheddar with the given name and random fat percentage.
*
* @param name the name of the cheddar.
* @return a new instance of Cheddar.
*/
Cheese makeCheddar(String name);
/**
* Makes a Parmesan with the given name and fat percentage.
*
* @param name the name of the parmesan.
* @param fatPercentage the fat percentage
* @return a new instance of Parmesan.
*/
Cheese makeParmesan(String name, Double fatPercentage);
/**
* Makes a Parmesan with the given name and random fat percentage.
*
* @param name the name of the parmesan.
* @return a new instance of Parmesan.
*/
Cheese makeParmesan(String name);
}
package edu.ics211.h02;
import java.util.Random;
/**
* Represents a CheeseType.
*
* @author .
*
*/
public enum CheeseType {
FRESH, SOFT, FIRM;
/**
* Returns a random CheeseType.
*
* @return a random CheeseType.
*/
public static CheeseType getRandomCheeseType() {
Random random = new Random();
return values()[random.nextInt(values().length)];
}
}
here's what have to implement =>
package edu.ics211.h02;
/**
* Represents a CheeseFromager.
*
* @author .
*
*/
public interface ManoaCheeseFromager {
/**
* Makes a Cheese with the given name, type and fat percentage.
*
* @param name the name of the cheese.
* @param type the type of the cheese.
* @param fatPercentage the fat percentage of the cheese.
* @return a new instance of Cheese.
*/
Cheese makeCheese(String name, CheeseType type, Double fatPercentage);
/**
* Makes a Cheese with the given name, type and a random fat percentage.
*
* @param name the name of the cheese.
* @param type the type of the cheese.
* @return a new instance of Cheese.
*/
Cheese makeCheese(String name, CheeseType type);
/**
* Makes a Mozzarella with the given name and fat percentage.
*
* @param name the name of the mozzarella.
* @param fatPercentage the fat percentage
* @return a new instance of Mozzarella.
*/
Cheese makeMozzarella(String name, Double fatPercentage);
/**
* Makes a Mozzarella with the given name and random fat percentage.
*
* @param name the name of the mozzarella.
* @return a new instance of Mozzarella.
*/
Cheese makeMozzarella(String name);
/**
* Makes a Brie with the given name and fat percentage.
*
* @param name the name of the brie.
* @param fatPercentage the fat percentage
* @return a new instance of Brie.
*/
Cheese makeBrie(String name, Double fatPercentage);
/**
* Makes a Brie with the given name and random fat percentage.
*
* @param name the name of the brie.
* @return a new instance of Brie.
*/
Cheese makeBrie(String name);
/**
* Makes a Cheddar with the given name and fat percentage.
*
* @param name the name of the cheddar.
* @param fatPercentage the fat percentage
* @return a new instance of Cheddar.
*/
Cheese makeCheddar(String name, Double fatPercentage);
/**
* Makes a Cheddar with the given name and random fat percentage.
*
* @param name the name of the cheddar.
* @return a new instance of Cheddar.
*/
Cheese makeCheddar(String name);
/**
* Makes a Parmesan with the given name and fat percentage.
*
* @param name the name of the parmesan.
* @param fatPercentage the fat percentage
* @return a new instance of Parmesan.
*/
Cheese makeParmesan(String name, Double fatPercentage);
/**
* Makes a Parmesan with the given name and random fat percentage.
*
* @param name the name of the parmesan.
* @return a new instance of Parmesan.
*/
Cheese makeParmesan(String name);
}
please please please....not the step..show me the code.
Q Task List Be Outline X 5 7 211f20-workspace - cmoore/src/edu/ics211/02/ManoaCheeseFromager.java - Eclipse IDE - PRES$8-9 #9 Package Explorer x gif JUnit e % 8 - CheeseType.java Cheese.java CheeseFromager.java D ManoaCheeseFromager.java X Olomoore 1 package edu.ics211.he2: JRE System Library JavaSE-10) 2 src 30/ 4 edu.ics 211.601 * Represents a Manca CheeseFromager. 5 BitReader.java 6 * gauthor Can Merre Translate.java 7 Translator.java 8 Translator Test.java 9 public class ManoaCheeseFromager implements CheeseFromager { 10 private static MangaCheeseFromager instance; edu.ics 211.02 11 Cheese.java 12e ** U CheeseFromager.java 13 Returns the singleton instance. Cheeselypeava 14 15 MancaCheeseFromager.java @return the singleton instance, 16 */ JUnit 4 17e public static ManoaCheeseFronager getInstance() { 18 if (instance == null) { instance = new MandaCheeseFromager(); 20 1 21 return instance; 22 > 22 24 25e ** 26 Creates a new ManoaCheeseFromager. 27 28 */ 29e private Manoa CheeseFromager() { 30 // hidden since is singleton. 31 32 33 34e @Override A 35 public Cheese makeCheese(String name, CheeseType type, Double tatPercentage) { 36 // TODO Auto-generated method stub 37 return null; 38 > edu.ica 211.02 MangaCheeseFromager instance: MancaCheese Fromager getinstance): MangaCheese Froma ManoaCheeseFromager) makeCheese(String, CheeseType, D makeCheese (String, CheeseType: make Mozzarella(String, Double):CH makeMozzarella (String) Cheese A makeBrie/String, Double): Cheese makeBrie/String]: Cheese makeCheddar(String, Double) : Cher makeCheddar(string) Cheese A makeParmesan/String, Double): Ch makeParmesaniStringl: Cheese 19 2. Problems Javadoc Declaration 0 items Description A Resource Path Location Type Writable Smart Insert 15:37:291Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started