Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Oracle Fusion Applications Installation And Administration

Authors: Tushar Thakker

1st Edition

1484209834, 9781484209837

More Books

Students also viewed these Databases questions

Question

Why is it important to pre-test message executions?

Answered: 1 week ago