Menu
Question Index
...

Write a program to get the eldest person from the given list of persons.

Input (List) Output (String)
[Amir(1989-06-26), Rohith(1990-06-18), Rajini(1989-01-26), Krishna(1989-08-26)] Rajini
[Radha(1990-08-31), Kalyan(1986-01-21), Teja(1986-01-20), Vasavi(1999-12-25), Anand(1991-02-11), Himesh(1992-10-25)] Teja
[Lahari(1988-11-30), Jyothi(1988-11-21), Chaitanya(1988-08-20), Pavan(1979-03-18), Sowjanya(1966-09-17), Akhil(1966-09-18)] Sowjanya
[Lahari(1988-11-30), Jyothi(1988-11-21), Chaitanya(1988-08-20), Pavan(1979-03-18), Akhil(1978-02-27), Sowjanya(1988-10-26)] Akhil


import java.util.*;
import java.text.*;
class GetTheEldestPerson
{
    public static void main(String s[])
    {
        ArrayList<Person> list = new ArrayList<Person>();
        list.add(new Person("Amir", new GregorianCalendar(1989, 5, 26)));
        list.add(new Person("Rohith", new GregorianCalendar(1990, 5, 18)));
        list.add(new Person("Rajini", new GregorianCalendar(1989, 0, 26)));
        list.add(new Person("Krishna", new GregorianCalendar(1989, 7, 26)));
        System.out.println("The Eldest person is " + getTheEldestPerson(list));

    }


    public static String getTheEldestPerson(ArrayList<Person> input) {
    }

}
class Person {

String name;
Calendar dateOfBirth;

Person(String name, Calendar dateOfBirth) {
this.name = name;
this.dateOfBirth = dateOfBirth;
}

@Override
public String toString() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return name + "(" + sdf.format(dateOfBirth.getTime()) + ")";
}
}

Doubts

Problems

Topic: Java GregorianCalendar

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App