In: Computer Science
Create a TeeShirt class for Toby’s Tee Shirt Company. Fields include: orderNumber - of type int size - of type String color - of type String price - of type double Create set methods for the order number, size, and color and get methods for all four fields. The price is determined by the size: $22.99 for XXL or XXXL, and $19.99 for all other sizes. Create a subclass named CustomTee that descends from TeeShirt and includes a field named slogan (of type String) to hold the slogan requested for the shirt, and include get and set methods for this field.
//TeeShirt.java
class TeeShirt
{
//instance variables
private int orderNumber;
private String size;
private String color;
private double price;
//setter methods for the instance variables
public void setOrderNumber(int num)
{
orderNumber=num;
}
public void setSize(String sz)
{
size=sz;
}
public void setColor(String color)
{
this.color=color;
}
//getter methods for the instance variables
public int getOrderNumber()
{
return orderNumber;
}
public String getSize()
{
return size;
}
public String getColor()
{
return color;
}
public double getPrice()
{
if(size.compareTo("XXL")==0 || size.compareTo("XXXL")==0)
price=22.99;
else
price=19.99;
return price;
}
}
It does not work.... It says it is missing something!! Please help!
TeeShirt.java
public class TeeShirt {
private int orderNumber;
private String size;
private String color;
private double price;
public TeeShirt()
{
this.orderNumber = 0;
this.size = "";
this.color = "";
this.price = 0.0;
}
public TeeShirt(int orderNumber, String size, String
color)
{
this.orderNumber = orderNumber;
this.size = size;
this.color = color;
if(this.size.equals("XXL") || this.size.equals("XXXL"))
this.price = 22.99;
else
this.price = 19.99;
}
// set methods
public void setOrderNumber(int orderNumber) {
this.orderNumber = orderNumber;
}
public void setSize(String size) {
this.size = size;
}
public void setColor(String color) {
this.color = color;
}
// get methods
public int getOrderNumber() {
return orderNumber;
}
public String getSize() {
return size;
}
public String getColor() {
return color;
}
public double getPrice() {
return price;
}
@Override
public String toString()
{
return("Order #: " + this.orderNumber + ", Size: " + this.size + ",
Color: "
+ this.color + ", Price: $" + String.format("%.2f",
this.price));
}
}
CustomTee.java
public class CustomTee extends TeeShirt{
private String slogan;
public CustomTee()
{
super();
this.slogan = "";
}
public CustomTee(int orderNumber, String size, String color, String
slogan)
{
super(orderNumber, size, color);
this.slogan = slogan;
}
// copy constructor
public CustomTee(TeeShirt tee, String slogan)
{
super(tee.getOrderNumber(), tee.getSize(), tee.getColor());
this.slogan = slogan;
}
public String getSlogan() {
return slogan;
}
public void setSlogan(String slogan) {
this.slogan = slogan;
}
@Override
public String toString()
{
return (super.toString() + ", Slogan: " + this.slogan);
}
}
TeeShirtApp.java (Main class)
public class TeeShirtApp {
public static void main(String[]args)
{
// create an object of CustomTee using copy constructor
TeeShirt teeShirt1 = new TeeShirt(45, "XXL", "Blue");
CustomTee customTee1 = new CustomTee(teeShirt1, "We are
one!");
// create an object of CustomTee using the overloaded
constructor
CustomTee customTee2 = new CustomTee(12, "XL", "Black", "Save
Planet Earth");
// print the details of the 2 objects
System.out.println("Tee Shirt 1:\n" + customTee1.toString());
System.out.println("\nTee Shirt 2:\n" + customTee2.toString() +
"\n");
}
}
********************************************************************* SCREENSHOT ******************************************************