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

Java - GVDate

EthanB60
EthanB60 


I have a project that's due tomorrow and i need help! I will attach the assigned file CIS 162 Project 2 GVdate Due Date • 10/1/14 Before Starting the Project • Read chapters 3 and 4 • Read section 5.1-5.2 before attempting the challenge requirements • Read this entire project description before starting Learning Objectives After completing this project you should be able to: • write, compile and run a simple Java class • write equations using variables • write methods to meet specific requirements • explain the differences between local variables, instance variables and method parameters Note Do not use the existing Java Date class in any way. For Your Reference Recall that there are 365 days in a year (except a leap year that has 366 days). The months and number of days are provided: January (31), February (28 or 29 – depending on whether or not is a leap year), March (31), April (30), May (31), June (30), July (31), August (31), September (30), October (31), November (30), December (31) Requirements Create a class called GVdate to keep track of a calendar date including month, day and year. You can do simple things like check if it is your birthday, advance to the next day, check if a given date is valid and check if it is a leap year. • Your code should follow the CIS 162 Programming Style Guide. (10 pts) • Provide appropriate names and data types for each of the private instance variables: the month, day and year (int), two final integers that represent YOUR birthday (month and day) and a String with the number of days for each of the months starting with January Example of the String containing the number of days for each month: "3128313031…31" (6 pts) • public GVdate (int m, int d, int y) – set the instance variables. For now assume that the input parameters are correct. (3 pts) • public GVdate (String pDate) – This constructor should parse the string parameter to break it apart and assign the values of month, day and year to the instance variables. CIS 162 Project 2 - Fall 2014 Page 1 of 7You will need to use the String methods, indexOf, substring and the Integer.parseInt method. The format of the String pDdate is "mm/dd/yyyy". For now assume that the input parameter is correct. (10 pts) • public void setMonth(int pMonth)- set the month to the input parameter. For now assume that the pMonth entered as parameter is correct. (1 point) • public int getMonth( ) – return the month. (1 point) • public void setDay(int pDay)- set the day to the input parameter. For now assume that the pDay entered as parameter is correct. (1 point) • public int getDay( ) – return the day. (1 point) • public void setYear(int pYear)- set the year to the input parameter. For now assume that the pYear entered as parameter is correct. (1 point) • public int getYear( ) – return the year (1 point) • public String toString() -- return a formatted date string (for example "7/10/2014"). (3 pts) • public void setDate (int m, int d, int y) – set the instance variables. For now assume that the input parameters are correct. (3 pts) • public boolean isMyBirthday () – return true if the date is YOUR birthday. Otherwise return false. (ignoring the year). (4 pts) • public void nextDay( ) – advance the date one day. This may also require advances to the month and/or the year. (15 pts) Note: Invoke the isLeapYear method, described below, to figure out if the year is a leap year. If it is a leap year, change the number of days for February from 28 to 29 in the String where you stored the number of days for each month. Instead of using literal numbers in your if statements to compare the number of days, use the substring method to retrieve the number of days for each month from the String that contains the days for each month, the Integer.parseInt method, and invoke the isLeapYear method when needed. Examples: 4/10/2014 will advance to 4/11/2014 12/31/2014 will advance to 1/1/2015. 2/28/2013 will advance to 3/1/2013 2/28/2004 will advance to 2/29/2004 – note that 2004 is a leap year • public boolean equals(GVdate otherDate) – return true if the month, day and year of the provided otherDate passed as a parameter matches the internal date - the instance variable date- Otherwise return false(5 pts) • public boolean isLeapYear(int y) – return true if the year passed as parameter is a leap year. Otherwise return false. Leap years occur every four years on multiples of four such as 2012 and 2016. There are a few exceptions: 1. Leap years DO occur on multiples of 400 such as 1600 and 2000. 2. Leap years DO NOT occur on multiples of 100 such as 1800 and 1900. (15 pts) 2Challenge Requirements – 20 points The following methods should only be attempted after everything else is working. • public boolean isDayValid (int pMonth, int pDay, int pYear) – return true if pDay is a valid day for the month and year entered as parameters, return false otherwise. Remember to invoke the isLeapYear method when appropriate. (3 pts) • public boolean isMonthValid(int pMonth) – return true if pMonth is a valid month, return false otherwise (1 pts) • public boolean isYearValid (int pYear) – return true if pYear is a positive integer number, return false otherwise (1 pts) • Modify the two constructors and the set methods (setDay, setMonth and setYear) to validate the input parameters. If the day, month and/or year are not valid, print an error message to the user. You must invoke the isDayValid, isMonthValid and/or isYearValid methods. (5 pts) • Overload the toString method (create another toString method) public String toString(int format). The format parameter indicates the type of formatted date to be returned. (10 pts) format = 1 - return a formatted date string (for example "7/10/2014"). format = 2 - return a formatted date string always displaying two digits for the month, day and year (for example "07/10/2014"). You are not allowed to use any decision statements like if or switch. format = 3 - return a formatted date with the 3 character month description. So the date 7/10/2014 would return the String "Sep 10, 2014". You are not allowed to use any decision statements like if or switch. You can do this by creating a single string with all of the 3 character month abbreviations and using the substring method. Example: "JanFebMarAprMay…Dec" format = 4 – return a formatted date with the month description. You may use any decision statements like if or switch to assign the correct month name (for example September 10, 2014). CIS 162 Project 2 - Fall 2014 Page 3 of 7Software Testing public static void main(String [] args) – write a main method to thoroughly test your solution. Instantiate two GVdate objects and invoke all methods with a variety of parameters and print statements. (10 pts) JUnit Testing JUnit is a Java library that helps to automate software testing. A JUnit test file DateTest.java has been provided on BlackBoard. Follow these instructions to use the test file. 1. Name your class GVdate. Exact spelling is required. Using a different name (date, gvDate, Date, etc.) will cause the tests to fail. 2. Complete ALL requirements described above or some of the unit tests will fail. 3. Download DateTest.java to the folder that contains your GVDate.java file. Right click with the mouse and carefully choose where the file is saved. Be sure to maintain the correct filename, DateTest.java. 4. Restart Bluej (if DateTest does not show up on your BlueJ window). BlueJ should recognize DateTest as a “<>” file after you compile the file. Running Junit Test After the Unit Test has compiled, right click on the green icon and select Test All. A number of automated tests will run. Those that pass will have a green check mark. Those that fail will have a gray X. Click on any of the test names for clues as to what might have gone wrong with your solution. Fix the code and try again! Show your instructor that ALL unit tests pass. 4Sample Main Method Your main method should be more extensive and test all methods. public static void main(String [] args) { System.out.println("Fall 2014 – CIS162 Project 2 – Your Name"); System.out.println("================================"); GVdate d = new GVdate(4,10,2014); System.out.println("Today: " + d); d.nextDay(); System.out.println("Tomorrow: " + d); d.nextDay(); System.out.println("Next Day: " + d); System.out.println("Testing leap year"); System.out.println("================="); System.out.println("Is 2014 leap year? " + d.isLeapYear(2014)); // Include code to test more leap years // Include code to test your birthday // Include code to test equals // Include code to test invalid parameters (day, month and/or year) } CIS 162 Project 2 - Fall 2014 Page 5 of 7Sample Output The following is provided as an example. Your messages can be more creative as long as they convey the correct information. Grading Criteria There is a 50% penalty on programming projects if your solution does not compile. • Stapled cover page with your name and signed pledge. (-5 pts if missing) • Project requirements as specified above. (85 pts) • Elegant source code that follows the GVSU Java Style Guide. (15 pts) Late Policy Projects are due at the START of the class period. However, you are encouraged to complete a project even if you must turn it in late. • The first 24 hours (-20 pts) • Each subsequent weekday is an additional -10 pts 6• Weekends are free days and the maximum late penalty is 50 pts. Turn In A professional document is stapled with an attractive cover page. Do not expect the lab to have a working stapler! • Cover page - Your project must have a cover page that includes your name, a title, an interesting graphic or photograph related to the project topic and the following signed pledge: "I pledge that this work is entirely mine, and mine alone (except for any code provided by my instructor). " You are responsible for understanding and adhering to the School of CIS Guidelines for Academic Honesty. • Sample Output – a printout of the Terminal window showing a variety of the printed messages. You can cut and paste into the Word document that contains your cover page. • Source code – a printout of the source code. CIS 162 Project 2 - Fall 2014 Page 7 of 7 Attachments Tags Clarifications

Answers

Solution

mariobeka
mariobeka 



Below you will find the two java classes need for the assignment. Comments included like it was specified. Attachments
Screen Shot 2014-10-07 at 12.03.09 AM.png (68 K) Download Preview

Test.java (1 K) Download Preview
– CIS162 Project 2 – Your Name"); System.out.println("================================"); GVdate d = new GVdate(1,1,2015); System.out.println("Today: " + d); d.nextDay(); System.out.println("Tomorrow: " + d); d.nextDay(); System.out.println("Next Day: " + d); System.out.println("\nTesting leap year"); System.out.println("================="); System.out.println("Is 2014 leap year? " + d.isLeapYear(2014)); System.out.println("Is 2014 leap year? " + d.isLeapYear(2012)); System.out.print

GVdate.java (4 K) Download Preview
d, int y) { this.month = m; this.day = d; this.year = y; } /** * Check date if is my birthday * * @return true if it is my birthday, false otherwise */ public boolean isMyBirthday() { return (BIRTHDAY_DAY== day && BIRTHDAY_MONTH==month); } /** * Advances this Date to

Screenshots
Screenshot
Purchase Answer