CSE 142 Autumn 2011 Programming Assignment 8 Birthday Date 12 points Due Wednesday November 30 2011 11 30 PM This program focuses on classes and objects Turn in two files named Birthday java and Date java You will also need the support file Date class from the course web site place it in the same folder as your program The assignment has two parts a client program that uses Date objects and a Date class of your own whose objects represent calendar dates It is meant to be shorter than other recent assignments and is also worth fewer points Part A Birthday java client program The first part of this assignment asks you to write a client program very similar to Homework 4 that uses an existing Date class written by the instructor The goal of Part A is to give you a bit of practice creating and using Date objects from a client s perspective and to give you an appreciation for the usefulness Date objects in general Begin by prompting the user for today s date and for his her birthday each as a month day pair Use this information to print the number of days in the month the user was born and the number of days from today to the user s birthday If the user s birthday is today print a Happy Birthday message Below are several example logs of execution from the program user input is bold and underlined Your program s output should match these examples exactly given the same input See the course web site for more logs with other input What is today s date month and day 11 4 What is your birthday month and day 9 9 There are 30 days in month 9 Number of days until birthday 9 9 309 What is today s date month and day 8 19 What is your birthday month and day 11 30 There are 30 days in month 11 Number of days until birthday 11 30 103 What is today s date month and day 12 15 What is your birthday month and day 12 15 There are 31 days in month 12 Happy birthday What is today s date month and day 10 2 What is your birthday month and day 10 1 There are 31 days in month 10 Number of days until birthday 10 1 364 Solve this problem using Date objects The methods and behavior of each Date object are described on the next page For Part A you can use an instructor provided version of Date by downloading the file Date class from the web site and saving it to the same folder as your Birthday java file You can construct a Date object as follows Date name new Date month day To figure out the number of days until the user s birthday represent today and the birthday as Date objects By advancing one date until it reaches the other and counting you can determine the number of days between them Absolute days from Homework 4 should not be used to calculate the days until the user s birthday You do not have to worry about leap years at all for this assignment Assume that February always has 28 days and that the year is always 365 days long A leap year occurs roughly every 4 years and adds a 29th day to February making the year 366 days long But we will ignore that possibility for this assignment Assume valid input that the user will always type a month between 1 12 and a day between 1 and the end of that month 1 of 3 Part B Date java class of objects The second part of this assignment asks you to implement a class named Date stored in a second file named Date java For all methods constructors shown below you may assume that any parameter values passed are valid Your Date class should implement the following behavior public Date int month int day Constructs a new Date representing the public int getMonth given month and day This method should return the month of the Date object on which it was called between 1 and 12 For example if the Date object represents August 17 this method should return 8 public int getDay This method should return the day of the month of the Date object on which it was called between 1 and the number of days in that month which will be between 28 and 31 For example if the Date object represents August 17 this method should return 17 public void setDate int month int day Modifies the state of the Date object on which it was called to represent the given month and day You may assume that the parameter values passed are valid public String toString This method should return a String representation of the Date object on which it was called in a month day format For example if the Date object represents March 24 return 3 24 If this Date object represents December 3 return 12 3 This method returns the string it does not print output public boolean equals Date d This method should return true when the Date object as the given Date parameter or false otherwise on which it was called represents the same date public int daysInMonth This method should return the number of days in the month represented by the Date object on which it was called The following table lists the number of days in each of the twelve months of the year 1 2 3 4 5 6 7 8 9 10 11 12 Name Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Days 31 28 31 30 31 30 31 31 30 31 30 31 For example if the Date object represents August 17 this method should return 31 If this Date object represents February 14 you should return 28 You do not need to worry about leap years public void nextDay This method should modify the state of the Date object on which it was called by advancing it 1 day in time For example if the Date object represents September 19 a call to this method should modify the Date object s state so that it represents September 20 Note that depending on the date a call to this method might advance the Date object into the next month or year For example the next day after August 17 is August 18 the next day after February 28 is March 1 and the next day after December 31 is January 1 None of the methods listed above should print any output to the console You may not utilize any behavior from the instructor provided Date class to help implement your own Date class nor use any of Java s date related classes such as java util GregorianCalendar or java util Date 2 of 3 Testing Your Program You can test your Date program by running your Birthday java program from Part A with it By compiling your Date java file you will overwrite our provided Date class with your own If …
View Full Document
Unlocking...