CS1120 Spring 2007

Instructor: Zille Huma Kamal

Worksheet I       

January 9, 2007

 

Name:________________________________________________________

 

 

Develop a class called Date with the following members and methods:

  1. private data members: day, month, year
  2. properties for each private data member
  3. methods:
    1. A print method that prints the date in traditional format – “09/06/06
    2. A print method that prints the date in the following format – “Today is 6th day of September in the year 2006”
    3. A set date method, which takes 3 arguments, day, month and year and assigns them to the data members
    4. 2 constructors:

a default constructor – that sets the date to October 1 1979

an overloaded constructor that takes 3 arguments, and assigns them to the day, month and year data members

 

Develop a class called TestDate which does the following:

  1. Create three Date objects, and initialize them as follows:
    1. Default date object
    2. A date object with the following date: 04/29/04
    3. And a data object with the following date: June 18th 2006
  2. Print the objects
  3. Ask the user for a date, and create a new date object that represents the user given date.
  4. Print the date object of (6).

 

Final test

  1. Open the test file, read the Dates and store them in a Date array. File Format mm/dd/yyyy.
  2. Sort the entries in the array in ascending order and print them.