A personal data processing system uses a class called Age instead of a primitive value to store a person's age. Change this class so that it is possible to compare Age objects.
Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClass hierarchiesInterfaces and abstract classes
Comparable
Value class
Report a typo
Write a program in Java 17
import java.util.*;
import java.util.stream.Collectors;
class Age {
private final int value;
public Age(int value) {
this.value = value;
}
public int getValue() {
return value;
}
}
// do not change the code below
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Age> list = Arrays.stream(sc.nextLine().split(" "))
.mapToInt(Integer::parseInt)
.mapToObj(Age::new)
.sorted()
.collect(Collectors.toList());
Checker.check(list);
}
}
class Checker {
static void check(List<Age> list) {
for (int i = 1; i < list.size(); i++) {
var curr = list.get(i);
var prev = list.get(i - 1);
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.