the first
import java.util.*;
import javax.swing.*;
public class AnalyseMonth {
public static void main(String[] args){
String theMonth = ""; //the month as text, without abbreviation
int daysInTheMonth; //the number of days in the month
// use GregorianCalendar to ascetain the current year (default setting)
GregorianCalendar today;
today = new GregorianCalendar();
int theYear = today.get(Calendar.YEAR);
// get year and month in question from user. The current year is set as a default in the dialog box
theYear = Integer.parseInt(JOptionPane.showInputDialog("Which year?", Integer.toString(theYear)));
theMonth = JOptionPane.showInputDialog(null, "Which month?");
// create myDaysInMonth object and set year and month
DaysInMonth myDaysInMonth;
myDaysInMonth = new DaysInMonth();
myDaysInMonth.setYear(theYear);
myDaysInMonth.setMonth(theMonth);
// get the days in month. If month was mis-spelled, myDaysInMonth returns -1
daysInTheMonth = myDaysInMonth.getDaysInMonth();
// depending on datum returned, display error message or days in the month message
if (daysInTheMonth == -1)
{
JOptionPane.showMessageDialog(null, "Bad month: " + theMonth);
}
else
{
JOptionPane.showMessageDialog(null, theMonth.toUpperCase() + ", " + theYear + " has " + daysInTheMonth + " days.");
}
}
}
and the last
public class CheckIfLeapYear {
int y;
//Constructor accepts an integer as a parameter
public CheckIfLeapYear(int year){
y = year;
}
// Using known leap year criteria, determine, by way of
// modulo division, the leap year status of the year.
// This class returns a boolean.
public boolean isLeapYear(){
if (y % 400 == 0)
{
return true; //it is a leap year.
}
else if (y % 100 == 0)
{
return true; //it is a leap year.
}
else if (y % 4 == 0)
{
return true; //it is a leap year.
}
else
{
return false; // it is not a leap year.
}
}
}
I am a new user to java but i have been getting through all the assignments except this one I just dont know how to begin. Again, he wants us to put in the middle class named "DaysInMonth". All help is appreciated. Thanks!
Here is how i tried starting out. I just wanted to see if i could get a quick print out if i just entered the month may. I know i did it wrong and I am very confused on how to bring in "theMonth" input into the "DaysInMonth" class.
import java.util.*;
import javax.swing.*;
class DaysInMonth {
public DaysInMonth() {
if (theMonth.equalsIgnoreCase(daysInTheMonth) == May)
{ JOptionPane.showMessageDialog(null, + theMonth); }
else { JOptionPane.showMessageDialog(null, "Bad month: " + theMonth);}
}
}
I'm looking for someone to point me in the right direction. Thanks guys!
This post has been edited by davedave22: 29 September 2008 - 08:16 PM

New Topic/Question
Reply




MultiQuote






|