Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The overall goal is to create a set of classes that are capable of managing and displaying dates by the Gregorian and Julian calendars. The

The overall goal is to create a set of classes that are capable of managing and displaying dates by the Gregorian and Julian calendars. The first in the series takes a naive view of creating classes, resulting in a program that has a lot of duplicated code. Then, in the second part, you'll clean up all of the duplication through the use of the Java programming language features, making a big improvement of the first assignment in the series.For the purposes of this assignment, we are mostly interested in the difference in how leap years are determined, and using that, want to represent dates using both calendars. For example, today (when I'm writing this) on the Gregorian calendar is February 15th, 2018, but on the Julian calendar is February 3rd, 2018.

The following details the requirements for the assignment:

Create two classes, GregorianDate and JulianDate.

The two date classes must expose only the following public instance methods and constructors, and provides an implementation that is appropriate for the calendar:

Default constructor that sets the date to the current date. See notes below about dates to help you figure out how to do this appropriately for each calendar.

Overloaded constructor that takes year, month, and date values and sets the date to that date: GregorianDate(int year, int month, int day) and JulianDate(int year, int month, int day)

A method that adds a specified number of days to the date: void addDays(int days)

Remember to track when the month and years change.

A method that subtracts a specified number of days to the date: void subtractDays(int days)

Remember to track when the month and years change.

A method that returns true/false if the date is part of a leap year: boolean isLeapYear()

A method that prints the date (without a carriage return) in mm/dd/yyyy format: void printShortDate()

A method that prints the date (without a carriage return) in Monthname dd, yyyy format: void printLongDate()

The following 'get' accessor methods. These aren't used by the sample driver code, but would normally be part of a class like this. These accessor methods, however, are used by the unit tests.

String getCurrentMonthName()

int getCurrentMonth()

int getCurrentYear()

int getCurrentDayOfMonth()

Store the year, month, and day values as private instance (non-static) data members of the class.

The two date classes must provide only the following private methods, which you'll use in support of the other public instance methods:

A method that returns true/false if a a specified year is a leap year: boolean isLeapYear(int year)

A method that returns the number of days in a month (for a year): int getNumberOfDaysInMonth(int year, int month)

A method that returns the name of a month: String getMonthName(int month)

Use System.currentTimeMillis() to obtain the number of milliseconds that have occurred since January 1, 1970.

The number returned from this method does not account for the time zone of the computer it is running on, you need to account for that. To get the time zone offset to correct for local time you can call java.util.TimeZone.getDefault().getRawOffset()This gives the number of milliseconds to "add" to the current time. I say "add" because it is a negative number, it is the offset you need.

For a Gregorian date, you can use this knowledge to start by initializing a date to 1/1/1970, then adding the number of days the number of milliseconds since then have taken place; remember to account for the time zone as described above.

For a Julian date, you have to set the starting date to January 1, 1 (1/1/1), then add in the number of days until (Gregorian) January 1, 1970, then, update the date with the number of milliseconds since 1/1/1970; of course, remember to account for the time zone as described above. The number of Julian days from 1/1/1 to 1/1/1970 is 719164. Here is a handy reference to compute the number of days between two dates

You can't use the built-in Date, Calendar, or GregorianCalendar classes as part of the code you write.

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

Practical Database Programming With Visual C# .NET

Authors: Ying Bai

1st Edition

0470467274, 978-0470467275

More Books

Students also viewed these Databases questions

Question

A service window closes just as they get to the front of the line.

Answered: 1 week ago

Question

LO4 Provide an overview of four challenges facing HR today.

Answered: 1 week ago