Advertisement
Marisichka

Main

Dec 2nd, 2022
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. package org.example;
  2. import java.util.ArrayList;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         ArrayList<Person> personArrayList = new ArrayList<Person>();
  9.  
  10.         Person firstPerson = new Person("Mariia", 19);
  11.         Person secondPerson = new Person("Nikolas",24);
  12.         Person thirdPerson = new Person("Vin",20);
  13.  
  14.         Student firstStudent = new Student("Oleh", 20, 3);
  15.         Student secondStudent = new Student("Olena", 10, 4);
  16.         Student thirdStudent = new Student("Toni", 34, 2);
  17.  
  18.         personArrayList.add(firstPerson);
  19.         personArrayList.add(secondPerson);
  20.         personArrayList.add(thirdPerson);
  21.  
  22.         personArrayList.add(firstStudent);
  23.         personArrayList.add(secondStudent);
  24.         personArrayList.add(thirdStudent);
  25.  
  26.         for (int i = 0; i < personArrayList.size(); i++){
  27.             System.out.println(personArrayList.get(i));
  28.         }
  29.  
  30.         System.out.println("Comparing:");
  31.  
  32.         if(persons.get(0).compareTo(persons.get(1)) == 0){
  33.             System.out.println("Ages are the same");
  34.         } else if (persons.get(0).compareTo(persons.get(1)) > 0){
  35.             System.out.println("1st age > 2nd age");
  36.         } else {
  37.             System.out.println("2nd age > 1st age");
  38.     }
  39.   }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement