Problem #3: Clothes (40 Points) For this problem, you will be creating a derived
ID: 3711808 • Letter: P
Question
Problem #3: Clothes (40 Points)
For this problem, you will be creating a derived class, exception class and an interface. No Driver is required, but I have attached one to test with. I have also attached a base class for you to use. A UML diagram for this problem has been provided to assist you.
Jacket Class: Jacket should be its own class and should inherit from Clothing and implement Insulatable. Jacket should have:
Attribute:
Thickness of Jacket
Methods:
get and set methods for attribute
toString(): returns a String describing the Jacket
constructor that takes in the color of the Jacket
constructor that takes in the color of the Jacket and the thickness of the Jacket
insulateRating(): returns 12.3 * thickness of the Jacket
------------------------------------------------------------------
Insulatable Interface: Insulatable should be its own interface which has a:
Method header:
insulateRating(): returns the rating for how well the Insulatable object insulates
------------------------------------------------------------------
NegativeThicknessException: This exception class should:
have a default constructor which set's it own message which relates to the problem the exception is warning us about
have a constructor which takes in a String as input and append that String to the exception's own message (which relates to the problem the exception is warning us about)
be thrown by the method in Jacket where we are trying to set the thickness of the Jacket. The exception should only be thrown if there is an attempt to set the thickness of the Jacket to a negative value
Grading Breakdown:
10 -- Correctly creating your Interface
10 -- Correctly creating your Derived Object
10 -- Correctly creating your Exception
10 -- Correctly throwing your Exception
Explanation / Answer
Jacket.java
public class Jacket{
private double thickness;
private String color;
public Jacket(String color) {
super();
this.color = color;
}
public Jacket(double thickness, String color) {
super();
this.thickness = thickness;
this.color = color;
}
public double getThickness() {
return thickness;
}
public void setThickness(double thickness) throws NegativeThicknessException {
if(thickness < 0)
throw new NegativeThicknessException("No negative value allowed");
this.thickness = thickness;
}
public double insulateRating() {
return 12.3 * thickness;
}
}
Insulatable.java
public interface Insulatable{
public double insulateRating();
}
NegativeThicknessException.java
public class NegativeThicknessException extends Exception{
public NegativeThicknessException(String s) {
super(s);
}
}
**Comment for any further queries.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.