Question
The following class contains code to de?ne a Nintendo character - where characters have a name and a primary out?t color. The main method creates
public class NintendoCharacter implements Comparable{
private Color color;
private String name;
public NintendoCharacter( Color outfitColor, String characterName ){
this.color = outfitColor;
this.name = characterName; }
@Override
public int compareTo(Object o) {
return color.toString().compareTo( ((NintendoCharacter)o).color.toString() ); }
public String toString(){ return name + : + color.toString(); }
public static void main(String[] args) {
NintendoCharacter m = new NintendoCharacter(Color.red, Mario);
NintendoCharacter l = new NintendoCharacter(Color.green, Luigi);
NintendoCharacter p = new NintendoCharacter(Color.magenta, Princess Peach);
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started