I have an assignment below:
1. Create a class called Furniture with the following attributes:
furnitureType – a String
modelNumber – a String
price – double
quantitySold – int
totalCharge - double.
Provide the following:
1. A non-default constructor for Furniture
2. Settors and gettors for price and furnitureType (don’t worry about settors and gettors for the others.
3. A method called calculateCharge() that calculates the total charge as quantitySold times price.
4. A toString() method that displays all the attributes and the total charge.
Furniture has two children: HandMade and MachineMade.
HandMade has an additional attribute, process, which refers to the type of process used in making the furniture. Note that process is of type String.
MachineMade has two additional attributes: one for manufacturer (String ) and one for country (also a String).
HandMade adds an extra 10% to the total charge if furnitureType is “wood” and the process is “wash”.
MachineMade gives a discount of 15% if the total charge is over $1500.
Write a Java application that includes the following:
1. Write the nondefault constructor for HandMade.
2. Write the nondefault constructor for MachineMade.
3. Write the calculateCharge for HandMade.
4. Write the calculateCharge for MachineMade.
5. toString() method for both HandMade and MachineMade.
6. Create a test class called FurnitureTest. Declare an array, furnitureArray, that can hold five instances of Furniture (either HandMade furniture or MachineMade furniture).
7. Insert in the 4th cell of the array the HandMade piece of furniture with process “paint”, type “plastic”, price $175.50, model E2302, quantity sold 7.
8. Insert in the 1st cell of the array the MachineMade piece of furniture with type “laminate”, model “KX225”, price $249.95, quantity sold 12, country “USA”, and manufacturer “Bassett”.
9. Populate the remaining cells furnitureArray with some Furniture objects of your choice and write the code necessary to polymorphically calculate and print/display each instance’s information to the system prompt or to a message dialog.
Here's what I have so far:
Furniture.java
public class Furniture
{
private String furnitureType;
private String modelNumber;
private double price;
private int quantitySold;
private double totalCharge;
public Furniture()
{
}
public void setFurnitureType(String furnitureType)
{
this.furnitureType = furnitureType;
}
public String getFurnitureType()
{
return furnitureType;
}
public void setPrice(double price)
{
this.price = price;
}
public double getPrice()
{
return price;
}
public String toString()
{
return "Furniture Type: " + furnitureType +
"\nModel Number: " + modelNumber +
"\nPrice: " + price +
"\nQuantity Sold: " + quantitySold +
"\nTotal Charge: " + totalCharge;
}
}
HandMade.java
public class HandMade extends Furniture
{
private Sting process;
public HandMade()
{
}
public double calculateCharge()
{
if(process == wash) && (furnitureType == wood)
return quantitySold * price + (price * 0.10);
else
return quantitySold * price;
}
public String toString()
{
return "Furniture Type: " + furnitureType +
"\nModel Number: " + modelNumber +
"\nPrice: " + price +
"\nQuantity Sold: " + quantitySold +
"\nTotal Charge: " + totalCharge;
}
}
}
FurnitureTest.java
public class FurnitureTest
{
public static void main(String[] args)
{
Furniture[] furnitureArray = new Furniture[5];
}
}
How can I populate the array and assign the test information to furniture type, model, etc?
Also, i'm not sure if my code is complete, am I missing anything?
Thanks guys!!