52.3k views
2 votes
The goal for me is that I need to identify the objects needed for the UNO card game and the actions that those objects perform, rather than how the objects are suppose to actually be represented. Write a document that includes an ADT (abstract data type) for each object needed in my program. This is a partial ADT for the UnoCard class.

//get the color of the car
+getColor(): String
//set the color of the card
+setColor(color : String):void
//get the value of the card
+getValue(): int
//set the value of the card
+getValue(val : int): void
//return true if card has same value or
//same color as the card
//return false otherwise
+isMatch(card: UnoCard): boolean
The standard UNO card must be able to report both its color and value, and, when given another card, tell whether or not it is a "match.

1 Answer

2 votes

Answer:

Step-by-step explanation:

//Java program

class UnoCard{

private String color;

private int value;

public UnoCard(String color , int val) {

this.color = color;

value = val;

}

public String getColor() {

return color;

}

//set the color of the card

public void setColor(String color ) {

this.color = color;

}

//get the value of the card

public int getValue() {

return value;

}

//set the value of the card

public void setValue(int val) {

value = val;

}

//return true if card has same value or

//same color as the card

//return false otherwise

public boolean isMatch(UnoCard card)

return (this.value==card.value)

}

public class Card {

public static void main(String args[]) {

UnoCard card1 = new UnoCard("Red",10);

UnoCard card2 = new UnoCard("Green",10);

UnoCard card3 = new UnoCard("Blue",15);

if(card1.isMatch(card2))System.out.println("Match");

else System.out.println("No Match");

if(card2.isMatch(card3))System.out.println("Match");

else System.out.println("No Match");

}

}

User Giorgia
by
3.7k points