Skip to content

Stage 1

Jegors Čemisovs edited this page Aug 23, 2021 · 50 revisions

Stage 1/8. How old are you?

Description

At the beginning of the last century, Dr. Wilhelm Fliess noticed identical rhythms in the case histories of his patients. He observed active and passive phases in the physical, emotional, and mental aspects of humans. From these observations, he derived the principle of the biorhythms: The physical curve with its cycle of 23 days, the emotional curve with 28 days, and the mental curve with 33 days.

By the 60s, 70s, and 80s biorhythms had gained more popularity. From books to biorhythm calculators, many people had prescribed to the idea. Articles about biorhythms are found in scientific journals, but most of the studies (99 of 134) indicate that biorhythms are not valid and they are no better at predictions than random chance.

In this project, we will help you create a human biological rhythm calculator and you can conduct your own research on this theory.

Objectives

The biorhythm cycles begin at birth and upon launching the program should ask the user for the date of birth. This date must not be later than today's date, and we add a limit for the earliest date at 1900-01-01. Date input must be in ISO format (YYYY-MM-DD). In case the user enters a date in the wrong format or the date is not in the valid range, the program should print an error message and ask for the date again.

After specifying the correct date, the program should calculate the person's age to date and print the following information: birthday, today, days lived, age. Dates must be printed in full format, including the name of the day of the week. Age should be printed in human-readable format where value 1 replaced by word one, and if any time unit is missing (value is 0) then it should be omitted. If the date of birth entered is the same as today, then just born for the age should be printed.

   Birthday: Thursday, January 01, 1970
      Today: Tuesday, August 17, 2021
       Days: 18,856
        Age: 51 years, 7 months and 16 days

Since printing only the age is too boring, we will add the zodiac sign information as well. The program should calculate the zodiac sign for the entered birthday, prints its name, symbol, period and lucky day of the week.

Zodiac Sign: Capricorn
     Symbol: The Sea-Goat
      Dates: December 22nd - January 19th
  Lucky Day: Saturday

Of course, if today is a lucky day for this sign, we should be happy to announce it!

  Today is a lucky day for Pisces!

In order not to search for information about the signs of the zodiac, all the necessary data was collected in the following table. Just copy all this data into your program.

Zodiac Sign Symbol Starts Ends Lucky Day
Aries The Ram March, 21 April, 19 Tuesday
Taurus The Bull April, 20 May, 20 Friday
Gemini The Twin May, 21 June, 20 Wednesday
Cancer The Crab June, 21 July, 22 Sunday
Leo Lion July, 23 August, 22 Sunday
Virgo The Maiden August, 23 September, 22 Wednesday
Libra The Scales September, 23 October, 22 Friday
Scorpio Scorpion October, 23 November, 21 Tuesday
Sagittarius Archer November, 22 December, 21 Thursday
Capricorn The Sea-Goat December, 22 January, 19 Saturday
Aquarius The Water-Bearer January, 20 February, 18 Saturday
Pisces Two Fish February, 19 March, 20 Saturday

Next, we will tell you which classes from the Java standard library are useful for you to solve this stage.

Theory

In this project, we will look at such an important topic as dates. In Java, the java.time package is responsible for working with dates and times. Classes such as LocalDate, LocalTime and LocalDateTime are the best known classes in this package. However, there are much more classes intended for work, and in this project we will introduce you to some of them.

This stage uses the ISO standard to enter the date, so you can use the LocalDate::parse method to get the date without any formatter. If the user makes a mistake when entering a date, a DateTimeParseException exception will be thrown and you need to add handling.

There are several options for formatting the date. You can use the DateTimeFormatter class and the FormatStyle.FULL style, or you can use the rich formatting capabilities of the Formatter class. Both of these approaches will output a localized date, which is fine. The tests for this project will set Locale.ENGLISH at startup, so even if your program displays the date in your language but is written correctly, it should pass the tests.

Use the ChronoUnit.DAYS to calculate the number of days lived. The enum class ChronoUnit supports the TemporalUnit interface and you can use the TemporalUnit::between method to calculate the number of days between two dates. Calculating age could be a difficult task, but fortunately, you can use a class Period which does all the calculations for you.

For the signs of the zodiac, we need to store the month and day of the beginning and end of the period, without specifying the year. And for this case, the java.time package has a special class MonthDay. Also use the Month class for the month, and the DayOfWeek class for the lucky day.

Of course, you cannot directly compare objects of classes LocalDate and MonthDay but you can use method MonthDay::from to obtain only month and day information from birthday. Then you can use the methods MonthDay::isAfter and MonthDay::isBefore to determine the zodiac sign for the birthday.

As you can see, the built-in Java classes do almost all the work. At this point, you just need to think about how to format the class Period to display the age, and add ordinal numbers for the dates in the zodiac sign information.

Examples

Example 1

> Task :Stage1.main()

Welcome to the Biorhythm Calculator!

Please specify a date of birth in format YYYY-MM-DD.
The birthday shall be in the range of 1900-01-01 to 2021-08-17 inclusive.

Please enter a birthday >1987-0617

Text '1987-0617' could not be parsed at index 7.
Please use ISO format YYYY-MM-DD.

Please enter a birthday >1897-06-17

The date 1897-06-17 is before the minimum date 1900-01-01.

Please enter a birthday >2021-08-19

The date 2021-08-19 is after today 2021-08-17.

Please enter a birthday >1970-01-01

   Birthday: Thursday, January 01, 1970
      Today: Tuesday, August 17, 2021
       Days: 18,856
        Age: 51 years, 7 months and 16 days

Zodiac Sign: Capricorn
     Symbol: The Sea-Goat
      Dates: December 22nd - January 19th
  Lucky Day: Saturday

Example 2

   Birthday: Friday, March 14, 2003
      Today: Saturday, January 10, 2032
       Days: 10,529
        Age: 28 years, 9 months and 27 days

Zodiac Sign: Pisces
     Symbol: Two Fish
      Dates: February 19th - March 20th
  Lucky Day: Saturday

  Today is a lucky day for Pisces!

Example 3

Welcome to the Biorhythm Calculator!

Please specify a date of birth in format YYYY-MM-DD.
It shall be in the range of 1900-01-01 to 2021-08-18.

Please enter a birthday >1970-06-07

   Birthday: Sunday, June 7, 1970
      Today: Wednesday, August 18, 2021
       Days: 18,700
        Age: 51 years, 2 months and 11 days

Zodiac Sign: Gemini
     Symbol: The Twin
      Dates: May 21st - June 20th
  Lucky Day: Wednesday

  Today is a lucky day for Gemini!

What you’ll do and what you’ll learn

Clone this wiki locally