Menu
Question Index
...


Write a program to update the zodiac signs of the given list of persons.
NOTE: While passing the month to the GregorianCalendar, it will start from 0 and go till 11.
Assume that the date range of the zodiac signs are as listed 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) Output (String)
[Amir(1989-06-25), Rohith(1989-10-25), Rajini(1989-10-23), Krishna(1989-11-10), Jay(1989-09-23), Suma(1977-10-27)] [Amir ~ 1989 - 6 - 25 ~ Cancer, Rani ~ 1989 - 10 - 25 ~ Scorpio,  Swetha ~ 1989 - 10 - 23 ~ Scorpio, Krishna ~ 1989 - 11 - 10 ~ Libra, Krishna ~ 1989 - 9- 23 ~ Scorpio, Suma ~ 1977 - 10- 27 ~Scorpio]
[Mohan(1998-02-15), Rani(1956-03-20), Swetha(1947-03-12), Krishna(1987-09-23)] [Mohan ~ 15-02-1998 ~ Aquarius, Rani ~ 20-03-1956 ~ Pisces, Swetha ~ 12-03-1947 ~ Pisces, Krishna ~ 23-09-1987 ~ Libra]
[Lahari(1987-12-30), Jyothi(1987-03-25), Chaitanya(1988-08-20), Pavan(1988-07-31), Akhil(1988-12-14), Sowjanya(1968-09-26)] [Lahari ~ 28-12-1999 ~ Capricorn, Jyothi ~ 13-10-1988 ~ Libra, Chaitanya ~ 20-08-1988 ~ Leo, Pavan ~ 19-04-1991 ~ Aries, Akhil ~ 22-03-1990 ~ Aries, Sowjanya ~ 21-04-1990 ~ Taurus]
[Padma(1998-08-23), Rani(1999-07-20), Sandhya(1999-06-01), Kumar(1997-02-20)] [Padma ~ 23-08-1998 ~ Virgo, Rani ~ 20-07-1999 ~ Cancer, Sandhya ~ 01-06-1999 ~ Gemini, Kumar ~ 20-02-1997 ~ Pisces]

class UpdateZodiacSigns

{    public static void main(String s[])
    {
        ArrayList persons = new ArrayList();
        persons.add(new Person("Amir", new GregorianCalendar(1989, 5, 25)));
        persons.add(new Person("Rohith", new GregorianCalendar(1989, 9, 25)));
        persons.add(new Person("Rajini", new GregorianCalendar(1989, 9, 23)));
        persons.add(new Person("Krishna", new GregorianCalendar(1989, 10, 10)));
        persons.add(new Person("Jay", new GregorianCalendar(1989, 8, 23)));
        persons.add(new Person("Suma", new GregorianCalendar(1977, 9, 27)));
        System.out.println("After updating the zodiac signs : ");
        updateZodiacSigns(persons);
        for (Person person : persons)
        System.out.println(person);

    }


public static void updateZodiacSigns(ArrayList<Person> input) {
//Write code here to update the zodiac sign the persons in the input list
}
}
class Person {

String name;
Calendar dateOfBirth;
String zodiacSign;

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()) + " ~ " + zodiacSign;
}
}

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