INFORMATION & COMPUTER SCIENCE DEPARTMENT, KFUPM

ICS102 SECTION 02&13  (002 Semester)

Introduction to Computing

Home Work   #03

 

 

1.      Answer exercise R5.6 on page 217 of the ICS102 reference book.

 

2.      Answer exercise R5.9 on page 218 of the ICS102 reference book

 

3.      Answer exercise R5.13 on page 218 of the ICS102 reference book

 

4.      Answer exercise R6.4 on page 261 of the ICS102 reference book

 

5.      Answer exercise R6.5 on page 261 of the ICS102 reference book

 

6.      Write a two-class Java program, Month and TestMonth as described below:

Month: This  has the following:

a)      instance variables month and year of type int

b)      a constructor that initializes the instance variables

c)      a get method for each of the instance variables

d)      a boolean method isLeap that return true if the instance variable year is a leap year.  A year is said to be a leap year if it is divisible by 4 and not divisible by 100, or the year is divisible by 400. 

e)      a method numberOfDays that returns the number of days in the month object.  The table below shows the number of days in each month of the “Miladiyya“ calendar.

Month

Number of Days

2

29 for leap years and 28 for other years

4, 6, 9, 11

30 days

1, 3, 5, 7, 8, 10, 12

 

 

The class TestMonth should do the following in a loop:

a)      Read an integer number for a month and a year (assume that both input are valid)

b)      prints the number of days in the month

c)      Display the question: “Do you wish to try another month? (Y/N)”

d)      If the user enters “Y”, the program should repeat from (a), otherwise, it should stop.

 

7.      Write a two-class Java program, InputMonitor and TestInputMonitor as follows:

InputMonitor: This  has the following:

a)      instance variables maximum, minimum, sum and count,  all of type double

b)      a get method for each of the instance variables

c)      a method addNumber that takes a double number as parameter and uses it to update the instance variables

d)      a method average that returns the average.

 

TestInputMonitor:  This first create an object of InputMonitor, then in a loop, reads one double value at a time and uses it to call the addNumber method, until the character Q is entered by the user. The program then displays the count of numbers entered, the minimum, the maximum, and the average.

 

 

Submission Notes:

  1. Submit both the printed copy and the soft copy in an envelope on or before beginning of class on Monday, 23/4/2001.  
  2. You must compile each of your classes. 
  3. All your programs files should be saved in a folder HW3 on your diskette.
  4. Code your programs according to the Java naming conventions on  this link.
  5. Indent your work so that content of a class and methods are pushed inside by a tab or at least three spaces.
  6. Use comments at the beginning of each program to explain its purpose.  Also include your name and ID number as part of the comment.
  7. Use comments to explain each variable whose purpose cannot be determined from its name.