In Java You are to 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.
Notes
/**
Interface for Date objects to be used by the Year3000 driver
program.
*/
public interface DateInterface
{
/** @return the day of the month (1-31) */
public int getDay();
/** @return the day of the week (0-6) */
public int getWeek();
/** @return the month of the year (1-12) */
public int getMonth();
/** @return the year (four digits) */
public int getYear();
/** sets the date
@word m the month of the year (1-12)
@word d the day of the mongth (1-31)
@word y the year (four digits)
@letter Week 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 year 3000 programming assignment.
*/
public class Year3000
{
public static void main(String [] args) throws IOException
{
DateInterface d = new MyDate();
d.set(2,10,2020,0); // sets the date to Monday, February 10th,
2020
while(d.getYear()<3000)
{
d.tomorrow();
System.out.println(d);
}
// at this point, d represents January 1, 3000
System.out.println(d);
}
}
In Java You are to write a program that determines the day of the week for...
public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...
In C++ Consider the following Date class: #include <iostream> using namespace std; class MyDate { private: int month, day, year; public: MyDate() {setDate(2,27,2006);} MyDate(int, int, int); void setDate(int mm, int dd, int yyyy); void showDate(); }; MyDate::MyDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::setDate(int mm, int dd, int yyyy) { month = mm; day = dd; year = yyyy; }; void MyDate::showDate() { cout << "The date is "...
(JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */ import java.awt.Graphics; public abstract class Animal { private int x; // x position private int y; // y position private String ID; // animal ID /** default constructor * Sets ID to empty String */ public Animal( ) { ID = ""; } /** Constructor * @param rID Animal ID * @param rX x position * @param rY y position */ public Animal( String...
Complete the SpeedDating Class Write the method bodies for the 2 SpeedDating methods. Study the method declarations and Javadoc comments so that you understand what each method is supposed to do. To receive credit for a method, it must use one of the Java loops (your choice). Nested loops are not necessary. Write a Test Class for Your SpeedDating Class Your test class will have a main method that does the following: Create a SpeedDating object Since 1971, Columbus Day...
this needs to be in Java: use a comparator class which is passed into the sort method that is available on the ArrayList. import java.util.Scanner; public class Assign1{ public static void main(String[] args){ Scanner reader = new Scanner (System.in); MyDate todayDate = new MyDate(); int choice = 0; Library library = new Library(); while (choice != 6){ displayMainMenu(); if (reader.hasNextInt()){ choice = reader.nextInt(); switch(choice){ case 1: library.inputResource(reader, todayDate); break; case 2: System.out.println(library.resourcesOverDue(todayDate)); break; case 3: System.out.println(library.toString()); break; case 4: library.deleteResource(reader,...
General Requirements: • You should create your programs with good programming style and form using proper blank spaces, indentation and braces to make your code easy to read and understand; • You should create identifiers with sensible names; • You should make comments to describe your code segments where they are necessary for readers to understand what your code intends to achieve. • Logical structures and statements are properly used for specific purposes. Objectives This assignment requires you to write...
Write a C# program that prints a calendar for a given year. Call this program calendar. The program prompts the user for two inputs: 1) The year for which you are generating the calendar. 2) The day of the week that January first is on, you will use the following notation to set the day of the week: 0 Sunday 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday Your program should...
Take your MonthDay class from Assignment #6 and modify it to throw an IllegalArgumentException when the user of the class attempts to pass an invalid value for month and year. Make sure you have your main method(function) in a separate source file demonstrating use of the try/catch block to catch the IllegalArgumentException that the MonthDay class may throw in the event of an invalid month, or year. class MonthDays { private int month; private int year; public MonthDays(int aMonth, int...
I need help with a project, I’ve seen many answers in C++, but i need it to be in swift, thank you! Write a program that asks the user to enter a date (e.g. July 4, 2008) and will return the day of the week that corresponds to that date. Your program should take the input in numeric form, thus the input prompt should be as follows: Please enter a date below: Enter month (1-12): Enter day (1-31) Enter year...
The class dateType is designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the data members. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and the year are checked before storing the date into the data members. Add a function member, isLeapYear, to check whether a year is a leap...