Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a TeeShirt class for Toby’s Tee Shirt Company. Fields include an order nu

ID: 3752900 • Letter: C

Question

Create a TeeShirt class for Toby’s Tee Shirt Company. Fields include an order number, size, color, and price. 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 to hold the slogan requested for the shirt, and include get and set methods this field. Write an application that creates two objects of each class, and demonstrate that all the methods work correctly. Save the files as TeeShirt.java, CustomTee.java, and DemoTees.java.

Explanation / Answer

TeeShirt.java

public class TeeShirt {

// Declaring instance variables

private int orderNum;

private String size;

private String color;

private double price;

// getters and setters

public int getOrderNum() {

return orderNum;

}

public void setOrderNum(int orderNum) {

this.orderNum = orderNum;

}

public String getSize() {

return size;

}

public void setSize(String size) {

this.size = size;

}

public String getColor() {

return color;

}

public void setColor(String color) {

this.color = color;

}

public double getPrice() {

if (size.endsWith("XXL") || size.equalsIgnoreCase("XXXL"))

price = 22.99;

else

price = 19.99;

return price;

}

}

________________

CustomTee.java

public class CustomTee extends TeeShirt {

// Declaring instance variables

private String slogan;

// getters and setters

public String getSlogan() {

return slogan;

}

public void setSlogan(String slogan) {

this.slogan = slogan;

}

}

____________________

DemoTees.java

public class DemoTees {

public static void main(String[] args) {

//Creatinga an Instance of TeeShirt Class

TeeShirt ts=new TeeShirt();

ts.setSize("XXXL");

ts.setOrderNum(1111);

ts.setColor("Red");

CustomTee cs=new CustomTee();

cs.setSlogan("Save Animals");

//Displaying the output

System.out.println("Custom TeeShirt: Order No :"+ts.getOrderNum()+" Size ="+ts.getSize()+" Color = "+ts.getColor());

System.out.println("Slogan = "+cs.getSlogan());

System.out.println("Price = $"+ts.getPrice());

}

}

_________________

Output:

Custom TeeShirt:
Order No :1111
Size =XXXL
Color = Red
Slogan = Save Animals
Price = $22.99

__________Thank You