Question
Programming Project #2, PLUS some specifications listed below SUBMIT Date.java (with no imports, no main(), no System calls). Seriously, no main, no System, in what
Programming Project #2, PLUS some specifications listed below
SUBMIT Date.java (with no imports, no main(), no System calls).
Seriously, no main, no System, in what you submit, else automatic ZERO!!!!
----------------------------------------------------------------------------------------------------------------
1. Do not use any imports from the JAVA API, nor any package statements, nor System.
2. I also insist the fields of your Class must remain private access. Only three fields allowed in your Date Class (year, month, day).
3. If you wish, you can declare some private static final fields (such as number of days of months or names of the months etc)
3. Add a default constructor that initializes the default Date to January 1, 1970
4. As mentioned in the text, the toString() output is always 10 characters, like 1970/01/01
5. Whenever an illegal date is attempted (whether in the constructors or in the mutator method), your code throws an IllegalArgumentException.
6. The addDays and addWeeks methods can actually subtract days or weeks for a negative parameter passed. Test these for positive as well negative days and weeks as well.
7. Add a mutator method setDate(year, month, day) and check that the input is a valid date, if not, doesn't update the fields and throws the IllegalArgumentException.
8. Add a longDate() method that returns a String with the format as "November 19, 2019".
9. Create a static version of daysTo, used as shown in test code in Assign8B.java And this is the only static method in your Date Class.
10. Reuse: Avoid copy/paste of code (certainly no plagiarism) by using one method to call others in your Class, like only one section of "daysTo" algorithm, one general constructor called by the default, and one date verification algorithm that is used by many methods to keep the date valid.
I promise to only test dates after 1582/10/15 (when our modern calendar started) and/or dates before the year 3000 (as computers likely obsolete by then?).
Below is some test code, that represents only a portion of what I might test Assign8B.java
*********don't forget to add comments for all the part of the program.
Use java code
try to write it a little different from the one on Chegg solution
/* CS210 * from Building Java Programs text by Reges and Stepp (Pearson pub.) * * Programming Project #2, Chapter 8 also note text examples for output format */ public class Assign8B { // Part of the main method used to test the Date class // NO imports allowed from the JAVA API public static void main(String[] a) { Date one = new Date(2019,10,15); Date two = new Date(2020,2,29); // 2020 is a leap year one. addDays(1); // advance one day System.out.println(one); // toString will be called, style is 2019/10/16 one. addWeeks(10); // advance by 10 weeks System.out.println(one); // toString will be called, style is 2019/12/25 System.out.println(two daysTo(one)); // -66 days (negative) two.addDays(-5); // negative days allowed System.out.println(two); // toString will be called, style is 2020/02/24 two.addWeeks(-4); // negative weeks allowed System.out.println(two);// toString will be called, style is 2020/01/27 two.addWeeks(-8); // negative days allowed System.out.println(two);// toString will be called, style is 2019/12/02 System.out.println(one.getDay(); // day is now the 25th (advanced) System.out.println(one.getMonth(); // returns 12 System.out.println(one.getYear(); // still 2019 System.out.println(one.isLeap Year(); // false for 2019 System.out.println(one); // toString will be called, style is 2019/12/25 System.out.println(one.getMonth(); // returns 12 System.out.println(one.getYear(); // still 2019 System.out.println(one.isLeap Year()); // false for 2019 System.out.println(one); // toString will be called, style is 2019/12/25 try { Date three = new Date(12,34,1956); // obviously illegal } catch (IllegalArgumentException e) { System.out.println("Illegal day attempted"); } Date four = new Date(); // create "longDate" output // I thought a long date was dinner with a person you don't like? System.out.println(four.longDate()); // January 1, 1970 try { four.setDate(2019, 2, 29);// Attempt to set an illegal date } catch (IllegalArgumentException e) { System.out.println("Illegal day attempted"); } // Finally, let's understand what static methods are most commonly used for: System.out.println(Date.daysTo(two, one)); // 23 days (positive) System.out.println(Date.daysTo(one, four)); // -18255 days (negative) } } /* CS210 * from Building Java Programs text by Reges and Stepp (Pearson pub.) * * Programming Project #2, Chapter 8 also note text examples for output format */ public class Assign8B { // Part of the main method used to test the Date class // NO imports allowed from the JAVA API public static void main(String[] a) { Date one = new Date(2019,10,15); Date two = new Date(2020,2,29); // 2020 is a leap year one. addDays(1); // advance one day System.out.println(one); // toString will be called, style is 2019/10/16 one. addWeeks(10); // advance by 10 weeks System.out.println(one); // toString will be called, style is 2019/12/25 System.out.println(two daysTo(one)); // -66 days (negative) two.addDays(-5); // negative days allowed System.out.println(two); // toString will be called, style is 2020/02/24 two.addWeeks(-4); // negative weeks allowed System.out.println(two);// toString will be called, style is 2020/01/27 two.addWeeks(-8); // negative days allowed System.out.println(two);// toString will be called, style is 2019/12/02 System.out.println(one.getDay(); // day is now the 25th (advanced) System.out.println(one.getMonth(); // returns 12 System.out.println(one.getYear(); // still 2019 System.out.println(one.isLeap Year(); // false for 2019 System.out.println(one); // toString will be called, style is 2019/12/25 System.out.println(one.getMonth(); // returns 12 System.out.println(one.getYear(); // still 2019 System.out.println(one.isLeap Year()); // false for 2019 System.out.println(one); // toString will be called, style is 2019/12/25 try { Date three = new Date(12,34,1956); // obviously illegal } catch (IllegalArgumentException e) { System.out.println("Illegal day attempted"); } Date four = new Date(); // create "longDate" output // I thought a long date was dinner with a person you don't like? System.out.println(four.longDate()); // January 1, 1970 try { four.setDate(2019, 2, 29);// Attempt to set an illegal date } catch (IllegalArgumentException e) { System.out.println("Illegal day attempted"); } // Finally, let's understand what static methods are most commonly used for: System.out.println(Date.daysTo(two, one)); // 23 days (positive) System.out.println(Date.daysTo(one, four)); // -18255 days (negative) } }Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started