Results 1 to 5 of 5
  1. #1
    chitwood is offline Member
    Join Date
    Jan 2008
    Posts
    23
    Rep Power
    0

    Default Month and year program code!!!!HELP PLEASE!!!

    I need help!!!!

    This is the assignment and here is the code I have already???? Can someone help me please?

    Create a program that prompts the user to enter the month and year. The program will then display the number of days in the month. For example, if the user enters month 8 and year 2007, the program will display "August 2007 has 31 days". Use input dialog boxes and message dialog boxes.

    Don't forget that leap year must be part of your calculation. The formula for determining whether a year is leap year is found in your textbook and also on the internet (using a simple Google search). Once you've determined whether you have a leap year, then you can determine how many days are in February.


    import javax.swing.JOptionPane;

    public class LeapYear {
    public static void main(String[] args) {
    // Prompt the user to enter a year
    String yearString = JOptionPane.showInputDialog("Enter a year");

    //Convert the string into an int value
    int year = Integer.parseInt(yearString);

    // Check if the year is a leap year
    boolean isLeapYear =
    (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);

    // Display the result in a message dialog box
    JOptionPane.showMessageDialog(null,
    year + " is a leap year? " + isLeapYear);
    }
    }




    I dont understand how to add the month portion to the assignment Can someone help me please?????????

    Thanks,

    Chitwood

  2. #2
    felixtfelix is offline Member
    Join Date
    Dec 2007
    Location
    Mumbai, India
    Posts
    37
    Rep Power
    0

    Default

    here you go.

    import javax.swing.JOptionPane;


    public class LeapYear {

    private int[] days ={31,28,31,30,31,30,31,31,30,31,30,31};
    private String[] months = {
    "January","February","March","April","May","Ju ne",
    "July","August","September","October","November"," December"
    };

    public void display(int month,int year){
    if(isLeapYear(year)){
    days[1] = 29;
    }

    JOptionPane.showMessageDialog(null, months[month-1] +" " +year +" has "+days[month-1] +" days");
    }

    public boolean isLeapYear(int year){
    return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    }

    public static void main(String[] args){
    LeapYear leapYear = new LeapYear();

    int month = Integer.parseInt(JOptionPane.showInputDialog("Ente r Month"));
    int year = Integer.parseInt(JOptionPane.showInputDialog("Ente r Month"));

    leapYear.display(month, year);
    }
    }

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default

    Quote Originally Posted by felixtfelix View Post
    here you go.
    Thank you for providing a free homework service in what is meant to be a forum.

    Would you be free to wash my car for me too? Without charge, of course.

    db

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Thank you for providing a free homework service in what is meant to be a forum.

    Would you be free to wash my car for me too? Without charge, of course.

    db
    Mine too, I didn't wash my car for months... :eek:

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Darryl.Burke View Post
    Thank you for providing a free homework service in what is meant to be a forum.
    The OP might be a little late handing in this assignment though, so not to worry too much!

Similar Threads

  1. Graph program code,hardnut
    By Javashak in forum Advanced Java
    Replies: 0
    Last Post: 03-24-2008, 03:25 PM
  2. Peculiarty in code of simple program...
    By Kreuz14 in forum New To Java
    Replies: 4
    Last Post: 01-23-2008, 03:27 AM
  3. Current month
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-07-2008, 08:40 AM
  4. Merry Christmas and happy New year
    By rgbosque in forum Forum Lobby
    Replies: 3
    Last Post: 12-31-2007, 02:44 AM
  5. code for making a java swing program a demo verson
    By fakhruddin in forum AWT / Swing
    Replies: 1
    Last Post: 11-27-2007, 08:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •