182k views
1 vote
The goal of this milestone is to identify the objects needed for the UNO card game and the actions that those objects perform, rather than how the objects are actually represented. For example, a 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." When specifying operations, think simplicity. "It's better to have a few, simple operations that can be combined in powerful ways, rather than lots of complex operations." (MIT, n.d.) 1. Review the rubric for this assignment before beginning work. Be sure you are familiar with the criteria for successful completion. The rubric link can be found in LoudCloud under the assignment. 2. Activity Directions: Prepare a document that includes an ADT (abstract data type) for each object needed in your program. Create a LOOM video in which you explain your class design. Discuss your selection of properties and methods for each object.

User Vouze
by
5.2k points

1 Answer

3 votes

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.

User Atirag
by
5.8k points