I am new to Java and I am trying to work on my first project, it's a card game, called Taki, I created a card object that both the Deck and the Player classes use. Now, I want to sort the cards on the player "hand", I choose to use ArrayList for the cards, in both scenarios, but I am having trouble sorting the cards because I want to sort it first by the color and then by the number.
Here is the basic of the card class.
public class Card {
private String name;
private String color;
private String number;
public Card(String color, String number) {
this.color = color;
this.number = number;
}
public String getColor() {
return color;
}
public String getNumber() {
return number;
}
public String getName() {
if (color.equals("White")) {
name = getNumber();
} else {
name = getColor() + " " + getNumber();
}
return name;
}
I saw this - Sort an ArrayList base on multiple attributes But all they did there is just handing out the solution, I want to know what to do, not just copy paste, so if someone could explain to me I would highly appreciate it.