Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Comparator;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class Main {
- public static class Peoples {
- private String name;
- private String ID;
- private Integer age;
- public Peoples(String name, String ID, int age) {
- this.name = name;
- this.ID = ID;
- this.age = age;
- }
- public String getName() {
- return this.name;
- }
- public String getID() {
- return this.ID;
- }
- public Integer getAge() {
- return this.age;
- }
- @Override
- public String toString() {
- return String.format("%s with ID: %s is %d years old.", this.getName(), this.getID(), this.getAge());
- }
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- ArrayList<Peoples> peoples = new ArrayList<>();
- while (!input.equalsIgnoreCase("End")) {
- String[] data = input.split("\\s+");
- String name = data[0];
- String ID = data[1];
- int age = Integer.parseInt(data[2]);
- Peoples people = new Peoples(name, ID, age);
- peoples.add(people);
- input= sc.nextLine();
- }
- peoples = peoples.stream().collect(Collectors.toCollection(ArrayList::new));
- peoples.sort(Comparator.comparingInt(Peoples::getAge));
- peoples.stream().forEach(people -> System.out.println(people.toString()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement