Menu
Question Index
...


Write a program to get the list of persons belonging to the given zodiac sign.
NOTE: While passing the month to the GregorianCalendar, it will start from 0 and go till 11.
Assume that the date ranges of the zodiac signs are as shown below.

Aries[Mar 21–Apr 19], Taurus[Apr 20–May 20], Gemini[May 21–June 20], Cancer[June 21–July 22], Leo[July 23–Aug 22], Virgo[Aug 23–Sept 22], Libra[Sept 23–Oct 22], Scorpio[Oct 23–Nov 21], Sagittarius[Nov 22–Dec 21], Capricorn[Dec 22–Jan 19], Aquarius[Jan 20–Feb 18],Pisces[Feb 19–Mar 20]

Input (List, String) Output (List)
[Amir(1989-06-25), Rohith(1989-10-25), Rajini(1989-10-23), Krishna(1989-11-10), Jay(1989-09-23), Suma(1977-10-27)], Scorpio [Rohith ~ 25-10-1989, Rajini ~ 23-10-1989, Krishna ~ 10-11-1989, Suma ~ 27-10-1977]
[Mohan(1998-02-15), Rani(1956-03-20), Swetha(1947-03-12), Krishna(1987-09-23)], Pisces [Rani ~ 20-03-1956, Swetha ~ 12-03-1947]
[Padma(1998-05-25), Rani(1999-07-20), Sandhya(1999-06-01), Kumar(1997-02-20)], Gemini [Padma ~ 25-05-1998, Sandhya ~ 01-06-1999]
[Lahari(1987-07-23), Jyothi(1987-07-28), Chaitanya(1988-08-18), Pavan(1988-08-21), Akhil(1988-07-25), Sowjanya(1968-08-02)], Leo [Lahari ~ 23-07-1987, Jyothi ~ 28-07-1987, Chaitanya ~ 18-08-1988, Pavan ~ 21-08-1988, Akhil ~ 25-07-1988, Sowjanya ~ 02-08-1968]
[Lahari(1999-12-28), Jyothi(1988-10-23), Chaitanya(1988-08-20), Pavan(1991-04-19), Akhil(1990-03-22), Sowjanya(1990-04-21)], Libra []

class GetPersonsWithZodiacSign

{    public static void main(String s[])
    {
        ArrayList list = new ArrayList();
        list.add(new Person("Amir", new GregorianCalendar(1989, 5, 25)));
        list.add(new Person("Rohith", new GregorianCalendar(1989, 9, 25)));
        list.add(new Person("Rajini", new GregorianCalendar(1989, 9, 23)));
        list.add(new Person("Krishna", new GregorianCalendar(1989, 10, 10)));
        list.add(new Person("Jay", new GregorianCalendar(1989, 8, 23)));
        list.add(new Person("Suma", new GregorianCalendar(1977, 9, 27)));
        System.out.println("List of persons with 'Scorpio' zodiac sign : ");
        ArrayList output = getPersonsWithZodiacSign(list, "Scorpio");
        for (Person person : output)
        System.out.println(person);

    }


public static ArrayList<Person> getPersonsWithZodiacSign(ArrayList<Person> input, String searchZodiacSign) {
//Write code here to get the list of persons of same zodiac sign and return it.
}

//If required, write any additional methods here and return it.
}
class Person {

String name;
Calendar dateOfBirth;

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

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

Doubts

Problems

Topic: Locale Class In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App