Advertisement
desislava_topuzakova

05. Comparing Objects - Main

Oct 16th, 2020
1,639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.03 KB | None | 0 0
  1. package ComparingObjects_05;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         ArrayList<Person> people = new ArrayList<>();
  11.  
  12.         String input = scanner.nextLine();
  13.  
  14.         while (!input.equals("END")){
  15.  
  16.             String[] tokens = input.split("\\s+");
  17.  
  18.             Person p = new Person(tokens[0], Integer.parseInt(tokens[1]), tokens[2]);
  19.             people.add(p);
  20.  
  21.             input = scanner.nextLine();
  22.         }
  23.  
  24.         int index = Integer.parseInt(scanner.nextLine());
  25.  
  26.         int equal = 0;
  27.  
  28.         Person p = people.get(index - 1);
  29.  
  30.         for (Person person : people) {
  31.             if(person.compareTo(p) == 0){
  32.                 equal++;
  33.             }
  34.         }
  35.  
  36.         if(equal == 1){
  37.             System.out.println("No matches");
  38.         }else{
  39.             System.out.println(equal + " " + (people.size() - equal) + " " + people.size());
  40.         }
  41.     }
  42. }
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement