Question
Hello! I'm trying to get d1 passed to Date.java without changing the code in Test.java. Thank you! public class Test { public static void main(String
Hello!
I'm trying to get d1 passed to Date.java without changing the code in Test.java. Thank you!
public class Test { public static void main(String [] args) { System.out.println("**********************Testing the Date class**********************: "); System.out.println("Testing the constructor"); System.out.println("Trying invalid date--year"); try { Date d1= new Date(2012,8,28); System.err.println("****Fails-no Exception thrown"); } catch(Exception e) { System.out.println("****passes"); } System.out.println("Trying invalid date--month");
//Code truncated
public class Date implements Comparable
int day; int month; int year;
public Date(int year, int month, int day)throws IllegalArgumentException{ if (!isValid(month, day, year))throw new IllegalArgumentException("Invalid date"); this.month = month; this.day = day; this.year = year; if (year < 2014 || year > 2020) { System.out.println("Invalid date"); // System.exit(1); throw new IllegalArgumentException(); } if (month < 1 || month > 12) { System.out.println("Invalid date"); throw new IllegalArgumentException(); // System.exit(1); } if (day < 1 || day > 31) { System.out.println("Invalid date"); throw new IllegalArgumentException(); //System.exit(1); } else{ Date now = new Date(month, day, year); System.out.println("toString(): " + now); }
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