[hotjoe.com] HotJoe Java Help Forums
  [Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
Visit java.com
Please send email if you are having login problems - see the posts below for more info.
Hotmail and Yahoo! users - please see the Hotmail post or the Yahoo! post for information on lost emails.
help with script my mistakes are probably easy  XML
Forum Index » New to Java
Author Message
spenceapalooza

Newbie

Joined: 06/23/2009 11:22:23
Messages: 1
Offline

// Save contents of this file as Date.Java .
// Default treatment of disallowed values is to change disallowed date to 1(st of month), disallowed month to January, disallowed year to 1900.

public class Date

{

private int dMonth; //variable to store the month

private int dDay; //variable to store the day

private int dYear; //variable to store the year


//Method to set the date

//Data members dMonth, dDay, and dYear are set

//according to the parameters

//Postcondition: dMonth = month; dDay = day;

// dYear = year;

public void setDate(int month, int day, int year)

{

if(year >= 1)

dYear = year;

else

dYear = 1900; //default value




// Insert code here to use the month provided if it is valid, otherwise default to January (dmonth = 1).


// Checking that the date is allowable for the month:
switch(dMonth)

{

case 1: case 3: case 5: case 7:

case 8: case 10: case 12: if(1 <= day && day <= 31)

dDay = day;

else

dDay = 1;

break;

case 4: case 6: case 9: case 11:
if(1 <= day && day <= 30)

dDay = day;

else

dDay=1;

break;




case 2: if(isLeapYear())

{
if(Year%4=0)

if(1 <= day && day >=29)

dDay = day;
}

else

{
if(1 <= day && day <= 2

dDay= day;;

break;
}

}

}





//Method to return the month

//Postcondition: The value of dMonth is returned

public int getMonth()

{

return dMonth;

}



//Method to return the day

//Postcondition: The value of dDay is returned

public int getDay()

{

return dDay;

}



//Method to return the year

//Postcondition: The value of dYear is returned

public int getYear()

{

return dYear;

}



//Method to return the date in the form mm-dd-yyyy

public String toString()

{

return (dMonth + "-" + dDay + "-" + dYear);

}



//Constructor to set the date

//Data members dMonth, dDay, and dYear are set

//according to the parameters

//Postcondition: dMonth = month; dDay = day;

// dYear = year;

public Date(int month, int day, int year)

{

setDate(month, day, year);

}



//Default constructor

//Data members dMonth, dDay, and dYear are set to

//the default values

//Postcondition: dMonth = 1; dDay = 1; dYear = 1900;

public Date()

{

dMonth = 1;

dDay = 1;

dYear = 1900;

}



public boolean isLeapYear()

{
// Insert LeapYear test logic here.
}

}

i cant figure out how to make the leap year logic work... and also how do i make a test at the bottom?

Sunkist

Newbie

Joined: 06/25/2009 19:07:54
Messages: 2
Offline

first of all what are you trying to do? make some kind of calendar? if your trying to see if a year is a leap year or something just take the year and see if its divisible by 4.
 
Forum Index » New to Java
Go to:   
Powered by JForum 2.1.9 © JForum Team
This site run by Scott Dunbar of Xigole Systems. © 2005-2011 - Scott Dunbar
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners
hotjoe.com, xigole.com, and Scott Dunbar have no affiliation with Oracle