Question: JAVA only please ***********************************PROVIDED CODE***************************************** // This is the test harness to use to validate/test the ValidDate class import java.util.Scanner; // import Scanner class for

JAVA only please

JAVA only please ***********************************PROVIDED CODE***************************************** // This is the test harness touse to validate/test the ValidDate class import java.util.Scanner; // import Scanner class

***********************************PROVIDED CODE*****************************************

// This is the test harness to use to validate/test the ValidDate class

import java.util.Scanner; // import Scanner class for retrieving user input

public class DateConversion {

public static void main (String [] args) { Scanner keyboard = new Scanner(System.in); // instantiate new object of Scanner class char answer = 'Y'; // declare & initialize variable to hold use response // assume starting point of "Yes"

while (Character.toUpperCase( answer ) == 'Y') // Test user response to continuation prompt { System.out.print("Enter a date in yyyy/mm/dd format: "); String offeredDate = keyboard.nextLine( ); // Accept & store user input

try { System.out.printf( "%nYou entered: %s", offeredDate ); // 'Mirror' input to user ValidDate inDate = new ValidDate ( offeredDate ); // Attempt to instantiate a ValidDate w/ input System.out.printf( "%nThe long form date reads: %s", inDate.getLongDate( ) ); System.out.printf( "%nThe short form date reads: %s%n%n", inDate.getValidDate( ) ); } // end try catch(InvalidDateException badDate) // if the data is 'bad' catch the exception here { System.out.printf( "%n%s%n", badDate.toString() ); } // end InvalidDateException catch catch( Exception xcptn ) // this catch block will catch ALL OTHER exceptions { System.err.printf( "%nWHAT HAPPENED?%n" ); } // end Exception catch System.out.println( "Do you want to enter another (Y/N)? "); // prompt user - additional input?

answer = keyboard.nextLine().charAt(0); // retrieve single character of user input } // end while

} // end main } // end DateConversion

*******************************************************************************************

// This is a custom exception class to be used in Lab 08. // This exception will be thrown if any part of the String offered to ValidDate is not valid.

public class InvalidDateException extends Exception { // The following constructor accepts a message as the only input parameter. This message will be displayed back to the user. public InvalidDateException( String message ) { super( message ); } // end one-parm constructor public InvalidDateException( String message, Throwable cause ) { super( message, cause ); } // end two-parm constuctor } // end InvalidDateException

**********************************END CODE******************************************

Thanks!

Purpose: Understanding data validation General Information You will write a Java class (ValidDate.java) that will store a user-input date as a String in the format yyyymmdd where yyyy is the four-digit year, mm is a numeric representation of month, and dd is the day of the month. The class constructor will validate that mm is valid, that dd is valid for the month provided, and that yyyy is greater than 2009. Two additional methods will be defined. One will return the date in mm/dd/yyyy format and one that will return the date with mm converted to the long-form month name(i.e., January 15, 2017). (See UML for details.) Provided Resources 1. Lab 08 Instructions, including requirements 2. A test harness for your code 3 InvalidDateException class 4. UML for class ValidDate 5. Sample output Requirements ValidDate Class Constructor There will be only one constructor. It will accept a single String value The constructor will then parse the String into three parts (each to be stored as an int value) based on a separator character (/): a month value, a day value, and a year value Validate the month value. If the month value is less than 1 or greater than 12, throw exception InvalidDateException, passing the message "Month value must be greater than or equal to 1 and less than or equal to 12". Validate the day value based on the month, that is, January 31 is valid, but neither February 31 nor April 31 would be. If an invalid day is encountered, throw exception InvalidDateException, passing the message "Day value must be greater than 0 and less than " The year value must be validated to be sure that it is greater than 2009. If an invalid year i encountered, throw exception InvalidDateException, passing the message "Year must be greater than 2009" Get and Set Methods Get and set methods for each instance variable must be defined

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!