Question

In: Computer Science

A clothing store sells shoes, pants, and tops. The store also allows a customer to buy...

A clothing store sells shoes, pants, and tops. The store also allows a customer to buy an “outfit,” which consists of three items: one pair of shoes, one pair of pants, and one top. Each clothing item has a description and a price. The four type of clothing items are represented by the four classes Shoes, Pants, Top, and Outfit. All four classes implement the following ClothingItem interface.

public interface ClothingItem

{
   /** Return the description of the clothing item *//

   String getDescription();

   /** Return the price of the clothing item */

   double getPrice();

}

The following diagram shows the relationship between the ClothingItem interface and the Shoes, Pants, Top, and Outfit classes.

The store allows customers to create Outfit clothing items, each of which includes a pair of shoes, pants, and a top. The description of the outfit consists of the description of the shoes, pants, and top, in the order, separated by “/” and followed by a space and “outfit”. The price of an outfit is calculated as follows. If the sum of the prices of any two items equals or exceeds $100, there is a 25% discount on the sum of the prices of all three items. Otherwise, there is a 10% discount.

For example, an outfit consisting of sneakers ($40), blue jeans ($50), and a T-shit ($10), would have the name “sneakers/blue jeans/T-shirt outfit” and a price of 0.90(40 + 50 +10) = $90.00. An outfit consisting of loafers ($50), cutoffs ($20), and dress-shirt ($60), would have the description “loafers/cutoffs/dress-shirt outfit” and a price of 0.75(50 + 20 + 60) = $97.50

Write the Outfit class the implements the ClothingItem interface. Your implementation must include a constructor that takes three parameters representing a pair of shoes, pants, and a top, in that order.

A client class that uses the Outfit class should be able to create an outfit, and its description, and get its price. Your implementation should be such that the client code has the following behavior:

Shoes shoes;

Pants pants;

Top top;

/* Code to initialize shoes, pants, and top */

ClothingItem outfit =

   new Outfit(shoes, pants, top); //Compiles without error

ClothingItem outfit =

   new Outfit(pants, shoes, top); //Compile-time error

ClothingItem outdit =

   new Outfit(shoes, top, pants); //Compile-time error

Solutions

Expert Solution

Hi,

Please find below code as per your requirement.

I have added ClothingItemDriver.java class to test the functionality.

Let me know if you have any doubt/concerns on this answer via comments.

Hope this answer helps you.

Thanks.

/********************JAVA CODE*********************/

/******************ClothingItem.java*********************/

public interface ClothingItem {

   /** Return the description of the clothing item */

   String getDescription();

   /** Return the price of the clothing item */

   double getPrice();
}

/*******************Shoes.java********************/

public class Shoes implements ClothingItem {

   //instance variables
   private String description;
   private double price;
  
   /**
   * Parameterized constructor which takes 2 parameter to construct shoe object
   * @param description
   * @param price
   */
   public Shoes(String description, double price) {
       this.description = description;
       this.price = price;
   }

   /**
   * Overrides method from interface ClothingItem to return description of Shoes
   */
   @Override
   public String getDescription() {
       return this.description;
   }
  
   /**
   * Overrides method from interface ClothingItem to return price of Shoes
   */
   @Override
   public double getPrice() {
       return this.price;
   }

}

/*******************Pants.java********************/

public class Pants implements ClothingItem {

   //instance variables
   private String description;
   private double price;
  
   /**
   * Parameterized constructor which takes 2 parameter to construct pants object
   * @param description
   * @param price
   */
   public Pants(String description, double price) {
       this.description = description;
       this.price = price;
   }
  
   /**
   * Overrides method from interface ClothingItem to return description of Pants
   */
   @Override
   public String getDescription() {
       return this.description;
   }

   /**
   * Overrides method from interface ClothingItem to return price of Pants
   */
   @Override
   public double getPrice() {
       return this.price;
   }

}

/********************Top.java*******************/

public class Top implements ClothingItem {

   //instance variables
   private String description;
   private double price;
  
   /**
   * Parameterized constructor which takes 2 parameter to construct top object
   * @param description
   * @param price
   */
   public Top(String description, double price) {
       this.description = description;
       this.price = price;
   }
  
   /**
   * Overrides method from interface ClothingItem to return description of Top
   */
   @Override
   public String getDescription() {
       return description;
   }

   /**
   * Overrides method from interface ClothingItem to return price of Top
   */
   @Override
   public double getPrice() {
       return this.price;
   }

}

/********************Outfit.java*******************/

public class Outfit implements ClothingItem {

   //instance variables
   private Shoes shoes;
   private Pants pants;
   private Top top;
  
   /**
   * Parameterized constructor which takes 3 parameter to construct Outfit object
   * @param shoes
   * @param pants
   * @param top
   */
   public Outfit(Shoes shoes, Pants pants, Top top) {
       this.shoes = shoes;
       this.pants = pants;
       this.top = top;
   }

   /**
   * Overrides method from interface ClothingItem to return description of Shoes,Pants and Top
   */
   @Override
   public String getDescription() {
       return shoes.getDescription() + "/"+pants.getDescription()+"/"+top.getDescription()+" outfit";
   }

   /**
   * Overrides method from interface ClothingItem to return price of all outfits with discount
   */
   @Override
   public double getPrice() {
       //calculating prices of 2 product to identify discount
       double price1 = shoes.getPrice() + pants.getPrice();
       double price2 =shoes.getPrice() + top.getPrice();
       double price3 = pants.getPrice() + top.getPrice();
       double totalPrice = shoes.getPrice() + pants.getPrice() + top.getPrice();
      
       //if two item prices exceeds or equals to 100 then 25% discount otherwise 10%
       if(price1 >= 100 || price2 >= 100 || price3 >= 100) {
           totalPrice = 0.75 * (totalPrice);
       } else {
           totalPrice = 0.90 * totalPrice;
       }
      
       return totalPrice;
   }

}

/*******************ClothingItemDriver.java********************/

/**
* This is driver class to test Outfit class
*
*/
public class ClothingItemDriver {

   public static void main(String[] args) {
       //Creating outfits which not exceed $100 for 2 outfits
       Shoes shoes = new Shoes("sneakers", 40);
       Pants pants = new Pants("blue jeans", 50);
       Top top = new Top("T-shirt", 10);
      
       ClothingItem outfit = new Outfit(shoes, pants, top);
       System.out.println(outfit.getDescription());
       //This will print price with 10% discount
       System.out.println("Total Price : $"+outfit.getPrice());
      
       //uncomment this you will get compile time error
       //ClothingItem outfit1 = new Outfit(pants, shoes, top);
       //ClothingItem outfit2 = new Outfit(top, pants, shoes);
      
       //Creating outfits which exceed $100 for 2 outfits
       Shoes shoes1 = new Shoes("loafers", 50);
       Pants pants1 = new Pants("cutoffs", 20);
       Top top1 = new Top("dress-shirt", 60);
      
       ClothingItem outfit1 = new Outfit(shoes1, pants1, top1);
       System.out.println(outfit1.getDescription());
       //This will print price with 25% discount
       System.out.println("Total Price : $"+outfit1.getPrice());
      
      
      
   }
}


Related Solutions

4) A clothing store sells shoes, pants, and tops. The store also allows a customer to...
4) A clothing store sells shoes, pants, and tops. The store also allows a customer to buy an “outfit,” which consists of three items: one pair of shoes, one pair of pants, and one top. Each clothing item has a description and a price. The four type of clothing items are represented by the four classes Shoes, Pants, Top, and Outfit. All four classes implement the following ClothingItem interface. public interface ClothingItem {    /** Return the description of the...
If a clothing store customer takes a pair of pants from the rack, removes all of...
If a clothing store customer takes a pair of pants from the rack, removes all of the external sales tags, and then approaches the sales clerk for a refund, what crime may be charged? Theft Criminal mischief Embezzlement None of the above
Smokey and the Bandit produces outdoor activity clothing. The product line consists of pants, jackets, tops,...
Smokey and the Bandit produces outdoor activity clothing. The product line consists of pants, jackets, tops, and accessories. Data has been collected related to direct materials and direct labor for the four product lines. Smokey and the Bandit has also collected information on four possible cost drivers (units, batches, machine hours, labor hours). All this information is listed below. Construct a spreadsheet that will allocate overhead for each of these alternative drivers and will calculate the total per unit cost...
Smokey and the Bandit produces outdoor activity clothing. The product line consists of pants, jackets, tops,...
Smokey and the Bandit produces outdoor activity clothing. The product line consists of pants, jackets, tops, and accessories. Data has been collected related to direct materials and direct labor for the four product lines. Smokey and the Bandit has also collected information on four possible cost drivers (units, batches, machine hours, labor hours). All this information is listed below. Construct a spreadsheet that will allocate overhead for each of these alternative drivers and will calculate the total per unit cost...
To better understand customer satisfaction with the service in the store a local clothing store decides...
To better understand customer satisfaction with the service in the store a local clothing store decides to conduct a survey. An employee of the store is asked to approach the first ten customers as they enter the store on three randomly selected Mondays in April, May, and June. The employee asks each customer, "How satisfied are you with the customer service in this store on a scale of 1-5 with 1 being not satisfied and 5 being very satisfied?" Identify...
A customer service manager at a retail clothing store has collected numerous customer complaints from the...
A customer service manager at a retail clothing store has collected numerous customer complaints from the forms they fill out on merchandise returns. To analyze trends or patterns in these returns, she has organized these complaints into a small number of sources or factors. en mensen e n de les emociona com a refer torse This is most closely related to the tool of TQM. A. scatter diagram B. histogram C. process control chart D. quality loss function E. cause-and-effect...
Ajax Company is a large retail company that sells clothing, shoes, and other apparel. It has...
Ajax Company is a large retail company that sells clothing, shoes, and other apparel. It has 40 retail outlets located in 22 states. All of the merchandise if purchased by a centralized procurement organization located at the company’s corporate headquarters. There are six purchasing agents with each agent assigned to purchase different types of goods. Each agent works independently with suppliers to get the best deals for the company. The six agents report to the purchasing director. The director oversees...
Midstate Industries is a retail clothing store. Marilyn Mounds knows that customer satisfaction is key to...
Midstate Industries is a retail clothing store. Marilyn Mounds knows that customer satisfaction is key to the success of her store. Indicate by placing an “X” in the appropriate column whether the following measures are leading or lagging and qualitative or quantitative. Each item may classify as more than one measure. 10 points Leading Lagging Qualitative Quantitative Attractive display of clothing items Dollars invested in display cases Overtime pay during sale days Quality of clothing Earnings per share Number of...
11. Running On Carla Gomez is the owner of Running On—a retail store that sells shoes...
11. Running On Carla Gomez is the owner of Running On—a retail store that sells shoes and accessories to runners. Carla is trying to decide what she should do with her retail business and how committed she should be to her current target market. Carla started Running On retail store in 1994 when she was only 24 years old. At that time, she was a nationally ranked runner and felt that the growing interest in jogging offered real potential for...
You are the owner of a clothing retail store in Manhattan that sells brand name clothes,...
You are the owner of a clothing retail store in Manhattan that sells brand name clothes, including high-end clothing brands. Your retail salespersons are paid a mean hourly wage of $15. Over the last several months, your sales have significantly declined and customer satisfaction surveys indicate that your customers are increasingly dissatisfied with the quality of service. You just took a course in microeconomics for business decisions in which you learned about the concept of principal-agent problem. To what extent...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT