Question: In this activity, you will create the Celebrity subclass you designed earlier in the CustomCelebrity class. Define the instance variables for the CustomCelebrity subclass. Write
In this activity, you will create the Celebrity subclass you designed earlier in the CustomCelebrity class.
- Define the instance variables for the CustomCelebrity subclass.
- Write the constructor for your class.
- Override the getClue and/or the getAnswer method(s).
- Override the toString method.
- Write any other methods that your design has indicated will be required. Look over your design plan and make sure that you have implemented all required components. Check that your code compiles, making sure to test any methods you write.
public class Celebrity { public class Celebrity { /** * The clue to determine the celebrity */ private String clue; /** * The answer or name of the celebrity. */ private String answer; /** * Creates a Celebrity instance with the supplied answer and clue * @param answer * @param clue */ public Celebrity(String answer, String clue) { this.clue = clue; this.answer = answer; } /** * Supplies the clue for the celebrity * @return */ public String getClue() { return clue; } /** * Supplies the answer for the celebrity. * @return */ public String getAnswer() { return answer; } /** * Updates the clue to the provided String. * @param clue The new clue. */ public void setClue(String clue) { this.clue = clue; } /** * Updates the answer to the provided String. * @param answer The new answer. */ public void setAnswer(String answer) { this.answer = answer; } /** * Provides a String representation of the Celebrity. */ @Override public String toString() { String description = "The Celebrity's name is: " + answer + ". The clue for this celebrity is: " + clue; return description; } }
}
public class CustomCelebrityTester { public static void main(String[] args) { //Test that your CustomCelebity class works here! } }
public class CustomCelebrity extends Celebrity { }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
