Comp 110L

Lab Project #4

Due: 9/14/2009

 

1.            Write a program that reads in an integer between 1 and 12 representing a month, and outputs the number of days in that month.  Use a Java switch statement to assign the proper number of days based on the month.  Be careful about February.  It has 28 days unless it is a leap year so you need to know the year you are to determine the number of days for.  The year, therefore will also need to be provided.  Determining whether a year is a leap year or not can be done using the following rules.  A year is a leap year if it is divisible by 4, unless it is also divisible by 100 in which case it is not a leap year, unless it is also divisible by 400 in which case it is a leap year.  Write this leap year logic using nested if-else statements.

 

2.            Modify the program you wrote in Lab Project #3 to convert temperatures from Fahrenheit to Celsius as well as Celsius to Fahrenheit based on input from the user telling whether the temperature entered is Celsius or Fahrenheit.  That is, the program should convert a Celsius temperature entered to Fahrenheit and a Fahrenheit temperature entered to Celsius

 

For each of the above problems be sure to do the following:

 

1.            Plan your solution by writing down the algorithm to solve the problem before you write the code.

2.            Make sure your programs are self-documented including an appropriate comment header block.

3.            Test the programs by running at least three test cases on each.

 

For each problem, turn in the hand written algorithm design, a listing of the program, and a listing of the output from running the test cases.