Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

he project name of this exercise is EraDate . The purpose of this assignment is to learn how to do comparisons using the if statement.

he project name of this exercise is EraDate.

The purpose of this assignment is to learn how to do comparisons using the if statement. Additionally, you get more practice on how to write all of your own code and Javadoc comments.

Problem Description

In Japan, years are referred to using the Gregorian Calendar.. like we do here and also by the name of the Era (called nengou). The Era is related to the reign of the emperor and to specify a year you use the Era name combined with the year when the Era started. For example, 2014 is referred to as Heisei 26 because the current emperor of Japan's Era is called Heisei (hey-say) and it has been 26 years since the Era started.

The table below shows the last four Eras and when they started and ended*.

Era Name Start End
Meiji 1/25/1868 7/30/1912
Taisho 8/1/1912 12/25/1926
Showa 12/26/1926 1/7/1989
Heisei 1/8/1989 present

You are to write a program that will take a date and then print out the Japanese Era name (using a print) or it will return a String in ISO 8601 date format. ISO 8601 date format looks like the following:

YYYY-MM-DD

Where YYYY is the year, MM is the month, and DD is the day. Note that MM and DD must always have two digits and for one digit values a zero is prepended (e.g. January is 01). The complete string for an ISO 8601 formatted day of January 25, 2011 is:

2011-01-25

The object to implement this is referred to as EraDate and consists of the following public methods:

public EraDate(int year, int month, int day) - This Constructor takes a four digit year, a month (1-12), and a day (1-31).

public String getIso8601Date() - Returns a String corresponding to the date specified in the constructor.

public void printJapaneseEraName() - Prints the Japanese Era name according to the table shown above. Notice that it doesn't return a string, it prints just the Era name. The names used must match the table exactly.

Your Program.java should contain code to test your EraDate object. Be sure to test the cases where one day is one Era and the next day is another (i.e. the edge cases).

Requirements (you must incorporate these items):

  • You must use only if statements and compound conditional expressions to implement public void printJapaneseEraName(). You cannot use if/else or if/else if statements.
  • If you want to pass the unit test, its very picky about string comparisons, it wants the era string to have a new line on end like: era = "Heisei " and then use System.out.print(era);

    Hints:

  • You might want to use the GregorianCalendar object to hold your date representation.
  • The GregorianCalendar object uses months from 0 to 11 rather than from 1 to 12 so adjust accordingly. (won't pass unit test if you don't do this)
  • The GregorianCalendar object defines the fields: Calendar.YEAR, Calendar.MONTH, and Calendar.DAY_OF_MONTH to be used with the get method.
  • The GregorianCalendar object also has a getTimeInMillis method that returns the number of millisecond of the object. This simplifies date comparisons.
  • String.format is a static method called by specifying the class name (String) then the method name (format). It returns a custom string using the same format string as the printf method.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions