Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Horse Betting The Road To Absolute Horse Racing 2

Authors: NAKAGAWA,YUKIO

1st Edition

B0CFZN219G, 979-8856410593

More Books

Students also viewed these Databases questions

Question

Find the derivative of y= cos cos (x + 2x)

Answered: 1 week ago

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago