Value class

Report a typo

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.

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);
___

Create a free account to access the full topic