Answer:
public class UNOCard {
//class variables
int value; //stores value of the card.
String color; //stores color of the card
//method returns value of the card
public int getValue() {
return value;
}
//method sets the value of the card to the passed argument
public void setValue(int value) {
this.value = value;
}
//method returns color of the card
public String getColor() {
return color;
}
//method sets the color of the card to the passed argument
public void setColor(String color) {
this.color = color;
}
//constructor
UnoCard(int value, String color)
{
setValue(value);
setColor(color);
}
//mrthod to compare if cards are equal or not
public boolean isMatch(UnoCard card)
this.getValue() == card.getValue())
return true;
return false;
}
public class UnoCardTest {
public static void main(String[] args) {
UnoCard card1 = new UnoCard(10, "Red");
UnoCard card2 = new UnoCard(10, "Black");
UnoCard card3 = new UnoCard(9, "Black");
System.out.println("Card-1: Value: " + card1.getValue() +"\tColor: " + card1.getColor());
System.out.println("Card-2: Value: " + card2.getValue() +"\tColor: " + card2.getColor());
System.out.println("Card-3: Value: " + card3.getValue() +"\tColor: " + card3.getColor());
System.out.println("\\\\Matching card-1 with card-2: " +card1.isMatch(card2));
System.out.println("Matching card-1 with card-3: " +card1.isMatch(card3));
}
}
Step-by-step explanation:
the discussion of the selection of properties and methods can be seen along with code.