Menu
Question Index
...


Write a program to get the number of pairs which can be formed such that the woman is elder than man and the pair does not 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/14, Ram-1988/06/14, Arun-1991/05/14, Sunil-1986/03/14, Shankar-1980/06/14] and [Mounika-1995/06/18, Madhu-1993/06/18, Archana-1991/08/20, Anusha-1988/10/17, Kavya-1986/12/03] 6
[Abhishek-1998/12/12, Vinod-1998/12/11, Sai-1991/04/03, Chandra-1987/08/06] and [Aiswarya-1980/04/03, Bindu-1999/08/07, Sindu-1945/08/15, Hema-1980/11/10] 10
[Sunil-1989/09/10, Anand-1976/08/06, Suman-1980/12/03, Jayanth-1988/03/20, Gopi-1980/04/13] and [Jyothi-1945/04/23, Bindu-1970/11/10, Sindu-1968/05/04, Hema-1972/10/18, Anjali-1980/06/11, Madhu-1980/06/15] 26
[Nagarjuna-1972/08/23, Pramod-1991/08/25, Arun-1985/02/14] and [Amala-1985/02/16, Akhila-1990/08/23, Siri-1996/07/28] 1
[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] 9

class WomanElderThanManAndNotSameZodiacSign

{    public static void main(String s[])
    {
        ArrayList men = new ArrayList();
        men.add(new Person("Krishna", new GregorianCalendar(1995, 5, 14)));
        men.add(new Person("Ram", new GregorianCalendar(1988, 5, 14)));
        men.add(new Person("Arun", new GregorianCalendar(1991, 4, 14)));
        men.add(new Person("Sunil", new GregorianCalendar(1986, 2, 14)));
        men.add(new Person("Shankar", new GregorianCalendar(1980, 5, 14)));
        ArrayList women = new ArrayList();
        women.add(new Person("Mounika", new GregorianCalendar(1995, 5, 18)));
        women.add(new Person("Madhu", new GregorianCalendar(1993, 5, 18)));
        women.add(new Person("Archana", new GregorianCalendar(1991, 7, 20)));
        women.add(new Person("Anusha", new GregorianCalendar(1988, 9, 17)));
        women.add(new Person("Kavya", new GregorianCalendar(1986, 11, 03)));
        System.out.println("Number of pairs where woman is elder than the man, but they are not of 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 woman is elder than the man and the pair does not have 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