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

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 3 instances of this, each different characters in the game. Update the main method to add these three characters to a collection (of any type), then iterate through the collection and print each character. Next, sort the collection and print each character again.

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!