generated from ohjelmointi2/gradle-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountry.java
More file actions
42 lines (35 loc) · 1.26 KB
/
Country.java
File metadata and controls
42 lines (35 loc) · 1.26 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
package interfaces.country;
/**
* Improve this class by implementing the Comparable interface. The class should
* be comparable based on the population of the country.
*
* The Comparable interface defines only one method: compareTo. The method
* should compare the population of the "current" country (this) to the
* population of the "other" country (the argument of the method). The method
* should return a negative number if the population of this country is smaller
* than, a positive number if it is larger than, and 0 if it is equal to the
* population of the other country.
*
* Read more at
* https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/Comparable.html
*/
public class Country {
private final String name;
private final int population;
public Country(String name, int population) {
this.name = name;
this.population = population;
}
public String getName() {
return name;
}
public int getPopulation() {
return population;
}
@Override
public String toString() {
return this.name + ", population: " + this.population;
}
// TODO: implement the compareTo method. You also need to use the `implements`
// keyword in the class declaration above.
}