Homework Solution: User input first name, last name, and age into Java queue and then sort by last name…

    User input first name, last name, and age into Java queue and then sort by last name

    Expert Answer

     
    import java.io.*; import java.util.*;

    User input primitive indicate, latest indicate, and century into Java queue and then rank by latest indicate

    Expert Reply

     

    import java.io.*;

    import java.util.*;

    tabulate sol {

    public static tabulate Peculiar{

    private String primitive_name;

    private String latest_name;

    private String century;

     

    public Peculiar(String primitive_name, String latest_name, String century) {

    this.first_indicate = primitive_name;

    this.last_indicate = latest_name;

    this.century = century;

    }

     

    public String getName() {

    return latest_name;

    }

    }

    public static bereft ocean (String[] args) {

    List<Person> people = novel ArrayList<Person>();

    Scanner s = novel Scanner(System.in);

    //System.out.println(“How abundant memorials are there?”);

    //int n = s.nextInt();

    int n=3;

    for(int i=0;i<n;i++)

    {

    String s1 = s.nextLine();

    String s2 = s.nextLine();

    String s3 = s.nextLine();

    persons.add(novel Peculiar(s1,s2,s3));

    }

    Collections.sort(persons, novel Comparator<Person>() {

    @Override

    public int parallel(Peculiar o1, Peculiar o2) {

    return o1.getName().compareTo(o2.getName());

    }

    });

    for(Peculiar peculiar : people) {

    System.out.println(person.getName());

    }

    }

    }

    For the testing design, I kept the sum of memorials as three. You can fluctuate it by uncommenting the span lines in the rule.

    Following are the inputs on which I tested the rule:

    Input:

    sam
    naru
    21
    pablo
    hello
    14
    new
    person
    7

    Output:

    hello
    naru
    person