Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Java write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must

In Java write a program that determines the day of the week for New Year's Day in the year 3000. To do this, you must create your own date class (MyDate) and use the following interface and main program:

/** Interface for Date objects to be used by the Year3000 driver program. @author Jon Sorenson */ public interface DateInterface { /** @return the day of the month (1-31) */ public int getDay(); /** @return the day of the week (0-6) */ public int getDow(); /** @return the month of the year (1-12) */ public int getMonth(); /** @return the year (four digits) */ public int getYear(); /** sets the date @param m the month of the year (1-12) @param d the day of the mongth (1-31) @param y the year (four digits) @param dow the day of the week (0-6) */ public void set(int m, int d, int y, int dow); /** moves the date forward by exactly one day */ public void tomorrow(); /** @return the date as a String in the format "Monday March 18, 2002" */ public String toString(); /** sets the date to today; make this empty {} unless you do the extra credit. */ public void today(); /** Moves the date backword by exactly one day; make this empty {} unless you do the extra credit. */ public void yesterday(); } 
import java.io.*; /** Driver class for The Dating Game programming assignment. @author Jon Sorenson */ public class Year3000 { public static void main(String [] args) throws IOException { DateInterface d = new MyDate(); d.set(1,27,2019,0); // sets the date to Sunday, January 27th, 2019 while(d.getYear()<3000) { d.tomorrow(); // un-comment the next line to help with debugging // System.out.println(d); } // at this point, d represents January 1, 3000 System.out.println(d); } } 

When the program is compiled and run, it should use your MyDate class to correctly predict the day of the week for January 1st, 3000.

Note that we are using the integers 0-6 for the days of the week, with 0 representing Sunday, 1 for Monday, etc.

  • Implement a yesterday() function which moves the date one day backward. Modify the main program to print the date, including the day of the week, for January 1st, 1800. (Hint: back up to December 31st, 1799, and then call tomorrow() once.)
  • Extend your implementation of yesterday() and tomorrow() to account for the switch between the Julian and Gregorian calendars in the 1500s. You'll have to do a little research to figure this out. Compute the day of the week for January 1st, 1000. Note that both yesterday() and tomorrow() need to still work correctly no matter what date is currently stored.
  • Using the built-in Date class from Java, implement the today() function in your class to set the date to today. Modify your constructor to call this function as well. Modify the main program to print today's date using your class (in addition to what it already does).

Notes

  • Remember to include comments at the top of your program and 1-2 lines for each function/method (for pre- and post-conditions). Remember to use javadoc.
  • For simplicity, you can pretend all months have 30 days and that there are no leap years for early versions of your program. Add the actual month lengths and leap year information later.
  • A leap year is a year when February has 29 days. A year is a leap year if the year is divisible by 4, but not by 100, or if it is divisible by 100, it must also be divisible by 400. So 1900 was not a leap year, but 2000 was.
  • Your tomorrow() function should fit on one page or less. If it is bigger than that, use some helper functions to break it down. The same goes for yesterday()
  • HINT: to check days of the week, try the cal program from the thomas prompt (for example thomas% cal 1 3000)

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

Fundamentals Of Database Systems

Authors: Ramez Elmasri, Sham Navathe

4th Edition

0321122267, 978-0321122261

More Books

Students also viewed these Databases questions