Menu
Question Index
...


Write a program to get the number of pairs which can be formed such that the man is elder than woman and the pair have the same zodiac sign.
NOTE: While passing the month to the GregorianCalendar, it will start from 0 and go till 11.
NOTE: The Person object passed does not contain the Zodiac sign (it will be null).
Assume that the zodiac sign date ranges 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, List) Output (Integer)
[Krishna-1995/06/18, Ram-1995/06/14, Arun-1991/06/14, Sunil-1996/10/14, Shankar-1999/06/14] and [Mounika-1995/06/14, Madhu-1993/06/18, Archana-1991/05/20, Anusha-1986/10/17, Kavya-1986/06/03] 12
[Sunil-1990/11/23, Anand-1990/12/10, Suman-2000/11/28, Chanti-2013/12/21, Jayanth-2000/02/20, Gopi-2011/12/13] and [Jyothi-1980/11/27, Bindu-1982/12/12, Sindu-1981/12/04, Hema-1982/11/28, Anjali-1980/12/20, Madhu-1980/11/30] 30
[Abhishek-1990/02/13, Vinod-1992/02/18, Sai-1998/01/22, Chandra-1980/01/23] and [Aiswarya-1990/02/13, Bindu-1989/01/24, Sindu-1988/02/13, Hema-1991/01/28] 10
[Jay-1976/09/14, Chaitanya-1998/09/14, Arjun-1990/09/14] and [Padma-1970/09/14, Sandhya-1995/09/14, Chitra-1987/09/14] 6
[Rajiv-1965/08/23, Raja-1998/10/02, Venky-1982/07/30, Vishal-1999/08/23] and [Divya-1972/12/23, Suma-1998/08/19, Navya-1982/07/13, Kavya-1999/02/02] 0

class ManElderThanWomanAndSameZodiacSign

{    public static void main(String s[])
    {
        ArrayList men = new ArrayList();
        men.add(new Person("Krishna", new GregorianCalendar(1995, 5, 18)));
        men.add(new Person("Ram", new GregorianCalendar(1995, 5, 14)));
        men.add(new Person("Arun", new GregorianCalendar(1991, 5, 14)));
        men.add(new Person("Sunil", new GregorianCalendar(1996, 9, 14)));
        men.add(new Person("Shankar", new GregorianCalendar(1999, 5, 14)));
        ArrayList women = new ArrayList();
        women.add(new Person("Mounika", new GregorianCalendar(1990, 5, 14)));
        women.add(new Person("Madhu", new GregorianCalendar(1993, 5, 18)));
        women.add(new Person("Archana", new GregorianCalendar(1991, 4, 20)));
        women.add(new Person("Anusha", new GregorianCalendar(1986, 9, 17)));
        women.add(new Person("Kavya", new GregorianCalendar(1986, 5, 03)));
        System.out.println("Number of pairs where man is elder than woman and they belong to the same zodiac sign : " + pairMenAndWomen(men, women));

    }


private static int pairMenAndWomen(ArrayList<Person> men, ArrayList<Person> women) {
//Write code here to get the number of pairs such that man is elder than the woman and they belong to the same zodiac sign
}

//If required, write any additional methods here
}
class Person {

String name;
Calendar dateOfBirth;
String zodiacSign;

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: 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