-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
37 lines (31 loc) · 910 Bytes
/
Card.java
File metadata and controls
37 lines (31 loc) · 910 Bytes
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
public class Card {
private String name;
private int rank;
public Card(String name, int rank){
//in war cards only require rank
this.name = name;
this.rank = rank;
}
public int getRank(){
return rank;
}
public String getName(){
return name;
}
//returns true if first card is higher rank than param card
public boolean compare(Card other){
return getRank()>other.getRank();
}
//@param Card 1, Card 2
//return the number of the card with the highest rank, or 3 if they are equal, and -1 as an error
public static int compare(Card c1, Card c2){
if(c1.getRank()>c2.getRank())
return 1;
else if(c2.getRank()>c1.getRank())
return 2;
else if(c2.getRank()==c1.getRank())
return 3;
else
return -1;
}
}