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 a program in Java that
calculates the day of week and the week of month for a given date,
as well as to print the calendar of the month where the given date
exists. Please note, you are not allowed to use any date based
classes predefined in Java JDK.
Background
For a given date, we can use the Gregorian calendar to find the
corresponding the day of the week, and the week of the month. For
example, May 25 2019 is a Saturday and locates in the fourth week
of May 2019. In general, we can use the following formula (Zeller’s
congruence) to calculate the day of a week for any given date after
October 15 1582.
where
• h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday,
3=Tuesday, 4=Wednesday, 5=Thursday, 6 = Friday)
• q is the day of the month
• m is the month (3 = March, 4 = April, 5 = May, 6=June, 7=July, 8=August, 9=September, 10=October, 11=November, 12=December, 13=January, 14 = February)
• K is the year of the century (year mod 100).
• J is the zero-based century (year/100). For example, the
zero-based centuries for 1995 and 2000 are 19 and 20
respectively.
For example, For 1 January 2000, the date would be treated as the
13th month of 1999, so the values would be: q=1, m=13, K=99, J=19,
so the formula is
h = (1+[13*(13+1)/5]+99+[99/4]+[19/4]+5*19) mod 7 =
(1+[182/5]+99+[99/4]+[19/4]+95) mod 7 =
(1+[36.4]+99+[24.75]+[4.75]+95) mod 7 = (1+36+99+24+4+95) mod 7 = 0
= Saturday
However, for 1 March 2000, the date is treated as the 3rd month of
2000, so the values become q=1, m=3, K=00, J=20, so the formula
is
h = (1+[13*(3+1)/5]+00+[00/4]+[20/4]+5*20] mod 7 =
(1+[10.4]+0+0+5+100) mod 7 = (1+10+5+100) mod 7 = 4 =
Wednesday
Tasks You will create one program called MyCalendar.java. You
should first implement the MyCalendar and MyDate classes from the
following UML class diagrams. You can add extra attributes and
methods, but the attributes and methods shown in the UML diagrams
can’t be modified.
MyCalendar - myDate: MyDate - day: Day + Main(String[] args) +
MyCalendar(MyDate myDate) + dayOfWeek(): Day + weekOfMonth(): int +
printCalendar(): void
• Day is an enumeration data type which contains the days of the
week, i.e., Monday, Tuesday, Wednesday, Thursday, Friday, Saturday,
and Sunday. • MyCalendar(MyDate myDate)is the construction method
of the class MyCalendar. • dayOfWeek() method will return the day
of the week for myDate. • weekOfMonth() method will return the week
of the month for myDate. • printCalendar() method will print the
calendar of the month for myDate. • Main(String[] args) method will
read a given date from the command line, the format of the given
date is dd/mm/yyyy. You can assume the date input format is always
correct, but the input date may be invalid. For example, 31/02/2017
is not a valid date. If the input date is not a valid date, the
program will ask user to input another valid date through keyboard.
This process will be repeated until a valid date is input by the
user. The valid input date will be used to create the object
(myDate) of class MyDate, then the object (myCalendar) of class
MyCalendar. The dayOfWeek() method, weekOfMonth() method, and
printCalendar() method of myCalendar object will be called to
display the day of the week, the week of the month, and the
calendar of the month for the input date by the user.
MyDate
- day: int - month: int - year: int + MyDate(int day, int month,
int year) + getDay(): int + getMonth(): int + getYear(): int +
isDateValid(): boolean
• MyDate(int day, int month, int year) is the constructor of the
class MyDate. • getDay() method returns the day of myDate object. •
getMonth() method returns the month of myDate object. • getYear()
method returns the year of myDate object. • isDateValid() method
returns a Boolean value, i.e., a true when the myDate object is
valid, and a false otherwise (notes: January, March, May, July,
August, October, December has 31 days. April, June, September,
November has 30 days. February has 29 days in a leap year, and 28
days in a common year.).
Your program must have the exact same output as the following
example. Example of the program output:
java MyCalendar 29/02/2019 29/02/2019 in not a valid date, please
re-input a valid date: 25/05/2019 25/05/2019 is a Saturday and
located in the fourth week of May 2019 The calendar of May 2019
is:
SUN MON TUE WED THU FRI SAT 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
(Note: Each column indicates a day and the column width are fixed
to 3 characters. The distance between two adjacent columns is fixed
to three characters as well.)
//MyDate.java
public class MyDate
{
int day,month,year;
boolean isvaliDate=true;
public MyDate(int day,int month,int year)
{
this.day=day;
this.month=month;
this.year=year;
if(month>12) //day and month validation
{
isvaliDate=false;
}
else if(month==1 || month==3 || month==5 || month==7 || month==9 || month==12)
{
if(day<=31)
{
isvaliDate=true;
}
else if(day>=31)
{
isvaliDate=false;
}
}
else if(month==2 || month==4 || month==6 || month==8 || month=10 || month==12)
{
if(day<=30)
{
isvaliDate=true;
}
else if(day>=30)
{
isvaliDate=false;
}
}
else if(month==2) //Feb month and leap year validation
{
if(year%4==0)
{
if(day<=29)
{
isvaliDate=true;
}
else if(day>=29)
{
isvaliDate=false;
}
}
else if(year%4!==0)
{
if(day<=28)
{
isvaliDate=true;
}
else if(day>=28)
{
isvaliDate=false;
}
}
}
}
boolean isvalidDate()
{
if(isvalidDate)
{
System.out.println("is a Valid Date");
return true;
}
if( ! isvalidDate)
{
System.out.println("is not a Valid Date,please re-input Date");
return false;
}
return isvalidDate;
}
public int getDay()
{
return day;
}
public int getMonth()
{
return month;
}
public int getYear()
{
return year;
}
public static void main(String[] args)
{
MyDate d=new MyDate(29, 02, 2019);
System.out.println("Date"+d.getDay()+"/"+d.getMonth()+"/"+d.getYear());
d.isvalidDate();
MyDate d1=new MyDate(25, 02, 2019);
System.out.println("Date"+d1.getDay()+"/"+d1.getMonth()+"/"+d1.getYear());
d1.isvalidDate();
}
}
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 sho...
Why isnt my MyCalender.java working? class MyCalender.java : package calenderapp; import java.util.Scanner; public class MyCalender { MyDate myDate; Day day; enum Day { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday } public static void main(String[] args) { Scanner sc= new Scanner(System.in); System.out.println("Enter date below :"); System.out.println("Enter day :"); int day = sc.nextInt(); System.out.println("Enter Month :"); int month = sc.nextInt(); System.out.println("Enter year :"); int year = sc.nextInt(); MyDate md = new MyDate(day, month, year); if(!md.isDateValid()){ System.out.println("\n Invalid date . Try...
Please create a C++ class called myDate. It should have the following operations: myDate() – default constructor. This will set the date to May 10, 1959. myDate(int M, int D, int Y) – overloaded constructor. This will set the date to the values passed in through the parameter list represented by Month, Day and Year. void display() – display the date in the following format (May 11, 1959) Do NOT print a linefeed after the date. void incrDate(int N) –...
Code is in C# Your instructor would like to thank to Marty Stepp and Hélène Martin at the University of Washington, Seattle, who originally wrote this assignment (for their CSE 142, in Java) This program focuses on classes and objects. Turn in two files named Birthday.cs and Date.cs. You will also need the support file Date.dll; it is contained in the starter project for this assignment. The assignment has two parts: a client program that uses Date objects, and a...
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...
Create a calendar for the year 2019, for a particular month (of your choosing ), highlight a particular date (also your choosing) with an asterisk. Make sure the calendar displays the week, the days of the week and the year. Make sure the MSU Programming Class appears in the title of the Calendar. I will choose May 1st for the month and date. The code below is what I will be using. Please show where I can go to in...
Write a program that, given a month and year, prints a calendar, such as June 2016 Su Mo Tu We Th Fr Sa 5 6 7 8 910 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 To find out the weekday of the first day of the month, call this function: Computes the weekday of a given date. @param year the year @param month the month (1=January 12=...
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...
I need to create a Java class file and a client file that does the following: Ask user to enter Today’s date in the form (month day year): 2 28 2018 Ask user to enter Birthday in the form (month day year): 11 30 1990 Output the following: The date they were born in the form (year/month/day). The day of the week they were born (Sunday – Saturday). The number of days between their birthday and today’s...
Description: This project focuses on creating a Java class, Date.java, along with a client class, DateCleint.java, which will contain code that utilizes your Date.java class. You will submit both files (each with appropriate commenting). A very similar project is described in the Programming Projects section at the end of chapter 8, which you may find helpful as reference. Use (your own) Java class file Date.java, and a companion DateClient.java file to perform the following: Ask user to enter Today’s...
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...