Fall 2012, The College of Saint Rose

Lab 4: Days in Month
Due: 11:59 PM, Tuesday, October 2, 2012

In this lab, you will write a program to calculate the number of days in a given month in a given year.

You may work alone or with a partner on this lab.

Days Per Month

In case you don't remember, here are the numbers of days per month in the modern calendar:

 Month Days January 31 February 28 or 29 March 31 April 30 May 31 June 30 July 31 August 31 September 30 October 31 November 30 December 31

February has 28 days except during a leap year. A leap year occurs in any year divisible 4 (with some exceptions we will not worry about for the purposes of this assignment). This simple rule works for years 1901 through 2099.

Your program will read in two integers, a month number (1 for January, 2 for February, etc.) and a year number. It will output the number of days in that month with a message like:

```There are 30 days in 9/2012.
```

Getting Set Up

• Create a folder for your work on this lab. Lab4 might be a good name.
• Follow the usual procedure (you can see all the detailed steps on the Lab 1 page) to create a new BlueJ project called Lab4Progs. We will not create any Java classes just yet.

Lab Procedure

Write a Java program in a class called DaysInMonth that solves the above problem. You are encouraged to develop a Visual Logic flowchart first, but you need not turn that in. For your Java program, you may use either terminal I/O with a Scanner and System.out.println calls or dialog boxes with JOptionPanes.

Here are some guidelines and suggestions for your program:

• You must perform error checking on your input to ensure the month entered is valid (in the range 1-12) and that the year is valid (1901-2099). Print an error message then terminate your program with System.exit(1); if you encounter invalid input.
• Reminder: we can determine if a number is divisible by 4 by dividing that number by 4 and checking if the remainder is 0.
• You should use the `&&` and `||` boolean operators to simplify your conditionals.
• Your program should have only one statement that outputs the answer (i.e., a single System.out.println or JOptionPane.showMessageDialog, located after your conditional statement that determines the correct number of days in the given month.

Style and Documentation Reminders

Before you submit your programs, make sure they conform to our guidelines for style and documentation.

In particular, you should have a comment at the top of each class that describes your program and has your name (and that of your partner if you are working with someone), the course number and section (02 for 11:15, E1 for 4:10). You should have comments throughout your programs describing your variables and any non-obvious Java statements or groups of statements.

All identifiers (class names and variable names) should be meaningful and conform to Java's naming conventions.

Your code should be nicely formatted, with new lines after any `{` or `}`, and indented as done in class examples.

Before 11:59 PM, Tuesday, October 2, 2012, submit your Java program to Blackboard for grading. Please upload only your Java source file DaysInMonth.java - the one with the .java file extension, not the .class, .ctxt, package.bluej or README files).

This assignment is worth 30 points, which are distributed as follows:

 > Feature Value Score Reading inputs 4 Error checking inputs 4 Computing basic days per month 5 Leap year correctness 4 Appropriate output 3 Using correct filename 1 Comments 4 Naming conventions 3 Formatting 2 Bonus for month names instead of numbers 2 Total 30