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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!