4.12.4 - Clothing Store
Java (Latte)
Starter and Solution Code
Did you attempt the exercise before looking at the solution?
We strongly suggest that you try the exercise yourself and use the starter code before looking at the solution code.
| ClothingTester.java | |
|---|---|
| Jeans.java | |
|---|---|
Reminder about the this. keyword
The prefix this. can be used to indicate that the instance variable is being used, not the formal parameter.
| Sweatshirt.java | |
|---|---|
Prompt (CodeHS)
In this problem, you’ll design a few classes that represent different pieces of clothing in a clothing store.
You’ll write the classes for TShirt, Jeans, Sweatshirt and Clothing.
The Clothing class should have two instance variables: one for the size of the clothing (a String), and another for the clothing’s color (also a string).
Clothing should have two accessor (getter methods) as well:
The Sweatshirt class should have a private instance variable (or field) to store whether or not it has a hood, and a corresponding getter method
The TShirt class should have a private field to store the fabric and a corresponding getter for that called
The constructors should be of this format: