In: Computer Science
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 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
Write your solution below.
Here is how the Outfit class will look, the question has reference to some diagram, which is not included in the question. I have assumed class - Shoes, Pants and Top also implements the ClothingItem interface. Based on the assumption, here is how the code needs to be implemented. ================================================================================ public class Outfit implements ClothingItem{ private Shoes shoes; private Pants pants; private Top top; public Outfit(Shoes shoes, Pants pants, Top top) { this.shoes = shoes; this.pants = pants; this.top = top; } @Override public String getDescription() { return shoes.getDescription()+"/"+ pants.getDescription()+"/"+ top.getDescription(); ; } @Override public double getPrice() { return shoes.getPrice() + pants.getPrice()+ top.getPrice(); ; } }
====================================================================