Question
**MUST BE IN JAVA** In the previous exercise, you created a Clothing object with attributes for the color, display name, and price. For this exercise,
**MUST BE IN JAVA**
In the previous exercise, you created a Clothing object with attributes for the color, display name, and price.
For this exercise, you'll be adding a toString method and an equals method.
Have your toString method return a receipt/purchase order style string of the Clothing object. Here are some examples to give some inspiration or you can simply pick one of these (i.e., it doesn't need to do all of these). The examples assume a Clothing object with color = orange, displayName = T-shirt and price = 19.87:
T-shirt: orange, 19.87 Orange T-Shirt $19.87 T-shirt, orange $19.87
Clothing objects are the same if they have the same color, display name, and price. Write an equals method to represent this.
**PLEASE READ**
HERE IS PREVIOUS CODE TO BUILD ON
class 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."); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started