-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCard.java
More file actions
30 lines (27 loc) · 855 Bytes
/
Card.java
File metadata and controls
30 lines (27 loc) · 855 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
public class Card implements Comparable<Card>{
private String name;
private String nationality;
private int yearBorn;
private int yearDied;
public Card(String name, String nationality, int yearBorn, int yearDied){
this.name = name;
this.nationality = nationality;
this.yearBorn = yearBorn;
this.yearDied = yearDied;
}
public int compareTo(Card other){
if (this.name.equals(other.name)){
return 0;
} else if (this.name.compareTo(other.name) > 0){
return 1;
} else{
return -1;
}
}
public String toString(){
if(yearDied == -1){
return name + " (" + yearBorn + "-" + "Present) - " + nationality;
}
return name + " (" + yearBorn + "-" + yearDied + ") - " + nationality;
}
}