Write a Clothing class with the following attributes: color (e.g., "blue", "green", "orange") displayName (e.g., "Doctor Who hoodie", "slacks") price (e.g., 19.99, 7) Include only one constructor. It should have parameters for each of the attributes and set their values. Additionally, include getters and setters for each of the attributes. Add a driver, name it Purchases, and create 2 Clothing objects. Finally, print out some information about both objects (i.e., print the information from some or all of the getters). For example, if you created a Clothing object whose color was blue, whose display name was work trousers, for a price of 27.99, you could use the getters to print something like this: These work trousers are blue and cost $27.99. Don't hardcode the print statement for full credit, you must use the getters
Language is Java
Write a Clothing class with the following attributes:
- color (e.g., "blue", "green", "orange")
- displayName (e.g., "Doctor Who hoodie", "slacks")
- price (e.g., 19.99, 7)
Include only one constructor. It should have parameters for each of the attributes and set their values.
Additionally, include getters and setters for each of the attributes.
Add a driver, name it Purchases, and create 2 Clothing objects.
Finally, print out some information about both objects (i.e., print the information from some or all of the getters). For example, if you created a Clothing object whose color was blue, whose display name was work trousers, for a price of 27.99, you could use the getters to print something like this:
These work trousers are blue and cost $27.99.
Don't hardcode the print statement for full credit, you must use the getters
// Code in java is as follows
Clothing{ //clothing class
private String color; //color of clothing
private String displayName; //name of clothing
private float price; //price of clothing
//constructor to initialize variables
public Clothing(String color, String displayName, float price){
this.color = color; //set color
this.displayName = displayName; //set name
this.price = price; //set price
}
public String getColor(){ //getter for color
return color; //return color
}
public String getDisplayName(){ //getter for name
return displayName; //return name
}
public float getPrice(){ //getter for price
return price; //return price
}
public void setColor(String color){ //setter for color
this.color = color; //set color
}
public void setDisplayName(String displayName){ //setter for name
this.displayName = displayName; //set name
}
public void setPrice(float price){ //setter for price
this.price = price; //set price
}
}
//purchases driver class
public class Purchases {
//main method
public static void main(String [] args){
//creating a clothing object
Clothing cloth1 = new Clothing("blue", "Work Trousers", 19.99f);
//creating a clothing object
Clothing cloth2 = new Clothing("orange", "Slacks", 7.0f);
//printing details of first clothing object
System.out.println("These " + cloth1.getDisplayName() +
" are " + cloth1.getColor() + " in color and cost is " +
cloth1.getPrice() + " Dollar.");
//printing details of second clothing object
System.out.println("These " + cloth2.getDisplayName() +
" are " + cloth2.getColor() + " in color and cost is " +
cloth2.getPrice() + " Dollar.");
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images