Question
In this program you will be implementing an Artisans class hierarchy. There are bakers, pastry chefs, and potters. They have basic artisan functionality to buy
In this program you will be implementing an Artisans class hierarchy. There are bakers, pastry chefs, and potters. They have basic artisan functionality to buy materials and make goods. While artisans in general may not want to sell their goods, in our class hierarchy the bakers and potters implement the interface Selling which contains the sellGoods() method.
Tester class
This class is given to you and contains the main method. Do not modify it in your submission.
Artisan Superclass
This class is given to you. Do not modify it in your submission. It has a constructor with a String parameter name, a method String getName(), and two abstract methods:
- void buyMaterials()
- void makeGoods(int number)
Interface Selling
This interface contains a single public method signature for void sellGoods() which does not return anything.
Subclasses Baker, PastryChef, and Potter
Potter and Baker are direct subclasses of Artisan. Both of these classes also implement the interface Selling. The class PastryChef is a subclass of Baker.
Subclass Potter
- This is a subclass of Artisan and implements the Selling interface.
- The constructor should take the Potter's name (a String) and its initial money (an integer). Money is an integer and always >= 0. Initially the Potter has no clay and no plates.
- Please override buyMaterials(). Each pound of clay costs $10. In this method the Potter repeatedly buys one pound of clay until they run out of money.
- Please override void makeGoods(int number). The Potter will attempt to make number many plates. Each plate takes 0.5 pounds of clay. The Potter only makes as many plates as they have clay available.
- Please override 'void sellGoods()'. The Potter sells all their plates for $15 each.
- Please override 'String toString()'. For a Potter with name "Harry" who has 2.5 pounds of clay, 3 plates and $10, the returned String would be:
I am Harry and have 2.5 pounds of clay, 3 plates and $10.
Note: We are not going to worry about distinguishing between plural (pounds, plates) and singular (pound, plate).
Subclass Baker
- This is a subclass of Artisan and implements the Selling interface.
- The constructor should take the Baker's name (a String) and its initial money (an integer). Money is an integer and always >= 0. Initially the Baker has no ingredients and no baked goods.
- Please override buyMaterials(). Each cup of flour costs $1, and each cup of butter costs $3. In this method the Baker repeatedly buys one cup of flour followed by one cup of butter, until they run out of money.
- Please add a protected method void bakeBread(). The Baker bakes one bread, as long as ingredients are available. The recipe is a bit simplified: Each bread takes 3 cups of flour.
- Please add a protected method void bakeCake(). The Baker bakes one cake, as long as ingredients are available. The recipe is a bit simplified: Each cake takes 2 cups of flour and 1 cup of butter.
- Please override void makeGoods(int number). The Baker will attempt to bake 'number/2' (rounded down) many breads, and the remaining number of cakes (so that in total number goods have been baked), as long as ingredients are available. Call the methods bakeBread() and bakeCake() for this.
- Please override 'void sellGoods()'. The Baker sells all their breads and cakes. Each cake is worth $10, each bread is worth $5.
- Please override 'String toString()'. For a Baker with name "Anna" who has 4 pounds of flour, 3 pounds of butter, 2 breads, 1 cake, and $105 the returned String would be:
I am Anna and have 4.0 pounds of flour, 3.0 pounds of butter, 2 breads, 1 cakes and $15.
Note: We are not going to worry about distinguishing between plural (pounds, breads, cakes) and singular (pound, bread, cake).
Subclass PastryChef
- This is a subclass of Baker.
- The constructor should take the PastryChef's name (a String) and its initial money (an integer). Money is an integer and always >= 0. Initially the PastryChef has no ingredients and no baked goods.
- Please override void makeGoods(int number). The PastryChef will attempt to bake 'number' many cakes, as long as ingredients are available. Call the method bakeCake() for this.
- Don't override any of the other methods. In particular the sales price for the cake is the same as for the Baker.
GIVEN CODE
public class Tester{
public static void printInventories(Artisan a1, Artisan a2, Artisan a3){ System.out.println(" Inventories:"); System.out.println(a1); System.out.println(a2); System.out.println(a3); System.out.println();
}
public static void main(String[] args){ Baker baker = new Baker("Anna",25); PastryChef pastryChef = new PastryChef("John",25); Potter potter = new Potter("Harry",25);
System.out.println("Created baker "+baker.getName() + ", pastry chef "+pastryChef.getName() + ", and potter "+potter.getName()+".");
printInventories(baker, pastryChef, potter);
System.out.println(".....Buying materials."); baker.buyMaterials(); pastryChef.buyMaterials(); potter.buyMaterials();
printInventories(baker, pastryChef, potter);
System.out.println(".....Making 5 goods each."); baker.makeGoods(5); pastryChef.makeGoods(5); potter.makeGoods(5);
printInventories(baker, pastryChef, potter); System.out.println(".....Selling goods."); baker.sellGoods(); pastryChef.sellGoods(); potter.sellGoods();
printInventories(baker, pastryChef, potter); } }
-------------------------------------------------------
public abstract class Artisan{ private String name;
public Artisan(String name){ this.name = name; }
public String getName(){ return name; }
public abstract void buyMaterials();
public abstract void makeGoods(int number);
}
---------------------------------------------------
Baker.java
//Add code here
-----------------------------------------------------
PastryChef.java
//Add code here
------------------------------------------------------
Selling.java
//Add code here
----------------------------------------------------
Potter.java
//Add code here
Step 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