Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java - Extended Date Class

Fwolfe2011
Fwolfe2011 


The project for this course is the creation of an ExtendedDate class. Note that this definition of the Date class will permit saving any values for a date’s instance variables including zero or negative values, values for month greater than 12, values for day greater than 31, and no limits for the values of year. Define a new class named ExtendedDate that inherits from or extends the Date class. This new class should provide the following additional capability. The class should ensure that only ExtendedDate objects with valid dates are created. For example, month should always be between 1 and 12. Day should be between 1 and 31. The maximum value of day depends on the month for the date. The maximum day for the month of February also depends on the year value for the ExtendedDate object (i.e. is it a leap year or not?). The value of year should be between 1900 and 2999 (we won’t worry about dates before or after that date). Once created, the values of an ExtendedDate object can be modified individually. For example, an ExtendedDate’s month, day, or year could be changed. However, we must sure that the result of any changes will not result in invalid dates being created. If it would, do not change the ExtendedDate object receiving the message. In addition, ExtendedDate objects should have additional capabilities. Specifically, ExtendedDate should provide the methods listed under the Main Elements section below. Objectives To successfully complete this project, you will be expected to apply what you have learned in this course and should include several of the following course and module objectives: 1. Apply object-oriented principles to practice 2. Select environment specific classes best suited to developing an application 3. Design necessary classes consistent with the requirements of an application 4. Implement the principles of inheritance and polymorphism in designing object-oriented applications 5. Evaluate design alternatives in a multi-tier architecture Main Elements Your ExtendedDate object should provide: Method Method Signature/Statement A default constructor public class ExtendedDate extends Date { // Default constructor // Data members are set according to super defaults A constructor that accepts parameters // Constructor that accepts parameters public ExtendedDate(int month, int day, int year) { } A method to set the date the overrides the inherited setDate method // Method to set the date – override inherited setDate method // If data is invalid, do not change the receiver public void setDate(int monthInt, int dayInt, int yearInt) { } A method to set the month ensuring that only valid changes are made // Method to set month ensuring that only valid changes are made public void setMonth(int anInt) { } A method to set the day ensuring that only valid changes are made // Method to set day ensuring that only valid changes are made public void setDay(int anInt) { } A method to set the year ensuring that only valid changes are made // Method to set year ensuring that only valid changes are made public void setYear(int anInt) { } A method to verify that month, day, and year variables constitute a legitimate date // New method to verify a date // Valid range is 1-1-1900 through 12-31-2999 public static boolean isValidDate(int month, int day, int year) { return true; } A method to test to see if a year value is a leap year // Method to test for a leap year public static boolean isLeapYear(int aYear) { return true; } A method to see if an ExtendedDate object is in a leap year // Instance method version of the above public boolean isLeapYear() { return true; } A method to return the number of days in the month for an ExtendedDate object // Return number of days in a month public int daysInMonth() { return 0; } A method to return the number of days passed in a year for an ExtendedDate object // Return number of days passed in year (includes current day) public int daysToDate() { return 0; } A method to return the number of days remaining in a year for an ExtendedDate object // Return number of days remaining in year public int daysRemainingInYear() { return 0; } A method to create a new ExtendedDate object by adding a number of days to an existing ExtendedDate object // Create a new ExtendedDate object with the values that result from adding a number of days to an existing ExtendedDate object. Cannot result in an invalid ExtendedDate being created. If an invalid date would be created, return a ExtendedDate with default values. public ExtendedDate futureDate(int inDay) { return new ExtendedDate(); } } Please note that the methods listed above state the ExtendedDate class’s public interface. It is essential that everyone use the same method signatures when creating the ExtendedDate class. We want to be able to test the ExtendedDate class to be sure that it properly implements its requirements. To do so, create a separate class in the same package named TestExtendedDate. Create a main() method in this class that provides tests for the methods of the ExtendedDate class. - See more at: http://www.cramshark.com/assignment/207/Java-ExtendedDate#sthash.qHeByNse.dpuf Attachments Tags Clarifications

Answers

Java - Extended Date Class - Solution

dickersonka
dickersonka 



Attached is the solution to the Java - Extended Date Class assignment including source and comments with a tester app. Attachments
ExtendedDate.zip (2 K) Download
Preview
System.out.println(); dt.setYear(500); System.out.println("Set year 500: " + dt.toString()); dt.setYear(3000); System.out.println("Set year 3000: " + dt.toString()); dt.setYear(2012); System.out.println("Set year 2012: " + dt.toString()); System.out.println(); dt.setMonth(0); System.out.println("Set month 0: " + dt.toString()); dt.setMonth(13); System.out.println("Set month 13: " +

Preview
month, int day, int year){ this.month = month; this.day = day; this.year = year; } // Method to return the date?s month value public int getMonth() { return month; } // Method to return the date?s day value

Preview
ExtendedDate being created. If an invalid date would be created, return a ExtendedDate with default values. public ExtendedDate futureDate(int inDay) { //create new date based on current date ExtendedDate d = new ExtendedDate(super.getMonth(), super.getDay(), super.getYear()); int daysRemaining = inDay; //loop until all days are

Screenshots
Purchase Answer