Question

In: Computer Science

Create a TeeShirt class for Toby’s Tee Shirt Company. Fields include: orderNumber - of type int...

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!

Solutions

Expert Solution

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 ******************************************************


Related Solutions

create a class matrix.Let U and V be the two matrices of type Int and number...
create a class matrix.Let U and V be the two matrices of type Int and number of rows and columns are user defined. Write the following member functions of the class a) Add Add the two matrices U and V. For this, add the corresponding entries, and place their sum in the corresponding index of the result matrix. b) Subtract Subtract the two matrices U and V. For this, subtract the corresponding entries, and place this answer in the corresponding...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color,...
Create an Automobile class for a dealership. Include fields for an ID number, make, model, color, year, vin number, miles per gallon, and speed. Include get and set methods for each field. Do not allow the ID to be negative or more than 9999; if it is, set the ID to 0. Do not allow the year to be earlier than 2000 or later than 2017; if it is, set the year to 0. Do not allow the miles per...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a...
Create a class named Salesperson. Data fields for Salesperson include an integer ID number and a doubleannual sales amount. Methods include a constructor that requires values for both data fields, as well as get and set methods for each of the data fields. Write an application named DemoSalesperson that declares an array of 10 Salesperson objects. Set each ID number to 9999 and each sales value to zero. Display the 10 Salesperson objects. public class DemoSalesperson { public static void...
Create a class named Horse that contains the following data fields: name - of type String...
Create a class named Horse that contains the following data fields: name - of type String color - of type String birthYear - of type int Include get and set methods for these fields. Next, create a subclass named RaceHorse, which contains an additional field, races (of type int), that holds the number of races in which the horse has competed and additional methods to get and set the new field. ------------------------------------ DemoHorses.java public class DemoHorses {     public static void...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String...
Create a class named Sandwich that contains the following data fields: MainIngredient - of type String Bread - of type String Price - of type Double Include get and set methods for these fields. The methods should be prefixed with 'get' or 'set' respectively, followed by the field name using camel case. For example, setMainIngredient. Use the application named TestSandwich that instantiates one Sandwich object and demonstrates the use of the set and get methods to test your class. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------...
Make a LandTract class with the following fields: • length - an int containing the tract's...
Make a LandTract class with the following fields: • length - an int containing the tract's length • width - an int containing the tract's width The class should also have the following methods: • area - returns an int representing the tract's area • equals - takes another LandTract object as a parameter and returns a boolean saying whether or not the two tracts have the same dimensions (This applies regardless of whether the dimensions match up. i.e., if...
Make a LandTract class with the following fields: • length - an int containing the tract's...
Make a LandTract class with the following fields: • length - an int containing the tract's length • width - an int containing the tract's width The class should also have the following methods: • area - returns an int representing the tract's area • equals - takes another LandTract object as a parameter and returns a boolean saying whether or not the two tracts have the same dimensions (This applies regardless of whether the dimensions match up. i.e., if...
#include #include #include int reverse(int); // Stack ADT Type Defintions typedef struct node { void* dataPtr;...
#include #include #include int reverse(int); // Stack ADT Type Defintions typedef struct node { void* dataPtr; struct node* link; } STACK_NODE; typedef struct { int count; STACK_NODE* top; } STACK; /* =============== createStack ============== This algorithm creates an empty stack. Pre Nothing Post Returns pointer to a null stack -or- NULL if overflow */ STACK* createStack(void) { // Local Definitions STACK* stack; // Statements stack = (STACK*)malloc(sizeof(STACK)); if (stack) { stack->count = 0; stack->top = NULL; } // if return...
Create a class named “Car” which has the following fields. The fields correspond to the columns...
Create a class named “Car” which has the following fields. The fields correspond to the columns in the text file except the last one. i. Vehicle_Name : String ii. Engine_Number : String iii. Vehicle_Price : double iv. Profit : double v. Total_Price : double (Total_Price = Vehicle_Price + Vehicle_Price* Profit/100) 2. Write a Java program to read the content of the text file. Each row has the attributes of one Car Object (except Total_Price). 3. After reading the instances of...
convert this string type   program into interger data type #include "stdafx.h" #include #include unsigned int putIntoHashTable(char...
convert this string type   program into interger data type #include "stdafx.h" #include #include unsigned int putIntoHashTable(char *ptrInputData, unsigned int bufferLength); // function to add to hash table unsigned int getFromHashTable(char *ptrOutputData, unsigned int bufferLength); // function to retrieve data from hash table #define INPUT_BUFFER_SIZE 200 // local buffer used for adding data to the hash table (there is no reason in this assignment to change this value) #define HASH_SIZE 100 // size of hash table to be used (for testing...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT