Sunday
March 26, 2017

Post a New Question

Posted by on .

How would you write this program?

We are using Java in Netbeans IDE..

Write a program to enter the year (ex 2004) and month number (1-12) then compute the number of days in that month.

Example
Enter the Year: 2004
Enter the Month: 2
There are 29 days in that month

  • computer science - ,

    Some of the following links may help you:

    http://search.yahoo.com/search?fr=mcafee&p=how+to+write+programs+with+Java+in+Netbeans+IDE

    Sra

  • computer science - ,

    You have to do two things:
    1. create an array of 12 elements, each of which represents the number of days in the month of a non-leap year. So when the month is given, you can look up the array to give the answer.
    2. To take care of leap years, you need to create a boolean function (public boolean isLeapYear(int year){} ) taking the year as an argument, and return true if it is a leap year, and false otherwise.
    The rule for leap years as of the Gregorian calendar (see link) in 1582 is as follows:
    "Years divisible by 4 are leap years, except for years divisible by 100, which are non-leap years,
    except for years divisible by 400, which are again leap years."

    To check your implementation, check that 1900 was NOT a leap year, and 2000 WAS a leap year.

    If the entered month is 2 (February), then you code need to check for leap year. If isLeapYear(year) returns true, display 29 days, otherwise, display 28 days.

    Link for history of Gregorian calendar:
    http://en.wikipedia.org/wiki/Gregorian_calendar

Answer This Question

First Name:
School Subject:
Answer:

Related Questions

More Related Questions

Post a New Question