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.List;
- import java.util.Scanner;
- public class Main {
- static class Person {
- private String name;
- private String id;
- private int age;
- public Person(String name, String id, int age) {
- this.name = name;
- this.id = id;
- this.age = age;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- @Override
- public String toString() {
- return String.format("%s with ID: %s is %d years old.", getName(), getId(), getAge());
- }
- }
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String line = scanner.nextLine();
- List<Person> people = new ArrayList<>();
- while (!line.equals("End")) {
- String[] elements = line.split(" +");
- String name = elements[0];
- String id = elements[1];
- int age = Integer.parseInt(elements[2]);
- Person person = new Person(name, id, age);
- people.add(person);
- line = scanner.nextLine();
- }
- people.sort((f, s) -> f.getAge() - s.getAge());
- for (Person person : people) {
- System.out.println(person);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement