-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardTest.java
More file actions
executable file
·87 lines (81 loc) · 2.59 KB
/
Copy pathCardTest.java
File metadata and controls
executable file
·87 lines (81 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* CardTest defines a number of behaviors for the Card class
* HINT: use comments to block out the tests so that you can do
* them one at a time without getting compiler errors.
*
* @author ace
* @version 3 April 2010
*/
public class CardTest
{
/**
* Constructor for objects of class CardTest
*/
public CardTest(){
}
/**
* Create a getter and a setter for the card suit.
*/
public void testSuit(){
Card card = new Card();
card.setSuit("hearts");
String hearts = card.getSuit();
if(hearts.equals("hearts")){
System.out.println("test set/getSuit passed");
} else {
System.out.println("test set/getSuit failed");
}
}
/**
* Create a getter and a setter for the card value.
*/
public void testValue(){
Card card = new Card();
card.setValue("six");
String six = card.getValue();
if(six.equals("six")){
System.out.println("test set/getValue passed");
} else{
System.out.println("test set/getValue failed");
}
}
/**
* Create a getter for the rank. Do not create a field
* for the rank, and do not create a setter for the rank.
* Use the ArrayList rankValue to determine the rank.
* HINT: read the documentation of the ArrayList class to
* find a method you can use.
*/
public void testRank(){
Card card = new Card();
card.setSuit("hearts");
card.setValue("six");
int rank = card.getRank();
if(rank == 4){
System.out.println("test getRank passed");
} else {
System.out.println("test getRank failed");
}
//HINT: What happens if you call your new getRank method without
//setting the value? Can you fix this?
}
/**
* Make a new constructor for Card which allows you to construct
* a card with the value and suit as parameters. Keep the default
* constructor as well. Be sure to set the card's rank at an appropriate
* point.
*/
public void testCardValueSuitConstructor(){
Card card1 = new Card();
card1.setValue("king");
card1.setSuit("hearts");
Card card2 = new Card("king", "hearts");
if(card1.getSuit().equals(card2.getSuit())
&& card1.getValue().equals(card2.getValue())
&& card1.getRank()==card2.getRank()){
System.out.println("test CardValueSuitConstructor passed");
} else {
System.out.println("test CardValueSuitConstructor failed");
}
}
}