We need it tomorrow, the code for the assignment #3 and #4 question. There was no continuation.
Date Class Project (part #3)
Add the following data items to your Date class 05 points
1. int dayOfYear
2. String monthName
3. String dayOfWeek
Add the following methods to your Date class 10 points
1. public void calcDayOfWeek()
Computes the day-of-the-week and stores the day of
week String in the dayOfWeek data item.
(depending in the month, day, and year data items)
2. public String getDayOfWeek() 05 points
returns the day-of-the-week
3. public void calcMonthName() 05 points
Finds the month name and stores the String in the
monthName data item.
4. public String getMonthName() 05 points
returns the month name data item
5. public void calcDOY() 20 points
Calculates the Julian day-of-year and stores it
in the dayOfYear data item.
Examples 01/10/2005 is 10 02/10/2005 is 41
03/01/2005 is 60 03/01/2000 is 61
6. public int getDOY() 05 points
returns the day-of-the-week
7. modify the public void printDate() method to include 05 points
the month name, day of week, and the dayOfYear
month xx (month name)
day xx
year xxxx and is (is not) a leap year
day of week xxxxxxxxx
day of year ddd
8. private void adjustData() that calls the methods 15 points
a. calcDayOfWeek()
b. calcMonthName()
c. calcDOY()
add adjustData() to your constructors and “setMethods()”
create a testing program to test your Date object and its methods.
Name the test program TestDate
Upload the Date.java and TestDate files to Date03 assignment for
evaluation if you wish
Date Class Project (part #4)
Add a constructors to your Date class.
public Date(int doy, int y) 20 points
a. sets year to y
b. using the doy, calculates the month and day
c. runs calcDayOfWeek()
d. runs calcMonthName()
add a method
public String getDateSpelledOut() 10 points
that returns a String with the date in the format
mmmmmmmm nn, yyyy day-of-week
Example November 14, 2008 Wednesday
January 1, 2009 Tuesday
************************************************************************************************************************
This is my code:
package DateProgram;
import java.util.Scanner;
public class DateTest {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Date date = new Date();
// Date d1;
// d1 = new date();
// Date d2 = new Date();
System.out.println("Enter Month from 1-12 : ");
date.setMonth(sc.nextInt());
System.out.println("Enter Day from 1-31 : ");
date.setDay(sc.nextInt());
System.out.println("Enter Year from 1900 and beyond : ");
date.setYear(sc.nextInt());
System.out.println("month is " +date.getMonth());
System.out.println("day is " +date.getDay());
System.out.println("year is " +date.getYear()+"\r");
System.out.println(date.getMonth()+ "/" +date.getDay()+"/" +date.getYear());
date.isValid();
date.calcLeapYear();
}
}
*************************************************************************************************
Utility Code:
package DateProgram;
public class Date {
private int month;
private int day;
private int year;
public Date(){
}
public int getMonth(){
return this.month;
}
public int getDay(){
if ((month<0 && month>12) && (month==4 || month==6 || month==9 || month==11))
{
if (day<0 && day>30)
System.out.println("Invalid day! ");
}
if ((month<0 && month>12) && (month==1 || month==3 || month==5 || month==7|| month==8 || month==10 || month==12))
{
if (day<0 && day>31)
System.out.println("Invalid day! ");
}
if ((month<0 && month>12) && (month==2))
{
if (day<0 && day>28)
System.out.println("Invalid day! ");
}
return this.day;
}
public int getYear(){
return this.year;
}
public void setMonth(int month)
{
this.month = month;
}
public void setDay(int day)
{
this.day = day;
}
//public void setyear(int year);
public void setYear (int year)
{
this.year = year;
}
public boolean isValid()
{
boolean isValid= true;
if (year>=1000 && year<=9999)
{
if (month>0 && month<13)
{
if (month==4 || month==6 || month==9 || month==11)
{
if (day>0 && day<=30)
isValid = true;
else
isValid = false;
}
if (month==1 || month==3 || month==5 || month==7|| month==8 || month==10 || month==12)
{
if (day>0 && day<=31)
isValid = true;
else
isValid = false;
}
if (month==2 && year%4==0)
{
if (day>0 && day<=29)
isValid = true;
else
isValid = false;
}
if (month==2 && year%4!=0)
{
if (day>0 && day<=28)
isValid = true;
else
isValid = false;
}
}
else
isValid = false;
}
else
isValid = false;
if (isValid)
System.out.println("Valid Date! ");
else
System.out.println("Invalid Date! ");
return isValid;
}
public boolean calcLeapYear()
{
boolean isLeapYear = true;
if(year %400 == 0)
{
isLeapYear = true;
}
if(year % 100 == 0)
{
isLeapYear = false;
}
if (year % 4 == 0)
{
isLeapYear = true;
}
else
{
isLeapYear = false;
}
if (isLeapYear)
System.out.println("Leap Year! ");
else
System.out.println("Not Leap Year! ");
return isLeapYear;
}
}