<p> Testing Exceptions – due 07/14</p><p>Way back, you were given two JAVA programs MyInput which contained two methods readInt( ) returned an int from the keyboard readDouble( ) returned a double from the keyboard</p><p>TestMyInput – tested the two methods</p><p>Later, you added two methods to MyInput readChar( ) returned a character readString( ) returned a String readFloat() returned a float</p><p>You may have stumbled across the fact that your program bombed if an invalid character was entered in readInt( ) or readDouble( )</p><p>We will fix that with exception handling </p><p>Keep the program names as TestMyInput.java and MyInput.java</p><p>Add to the following methods…. readInt( ) & readFloat Add to this method the logic to catch the exception if an invalid character is entered on the keyboard or if no integers are entered on the keyboard. Process the exception in the method.</p><p>If an exception(s) occurs, display to the screen ‘invalid data entered’ and the data entered ‘no data entered’ return a 0 or 0.0</p><p> the program should not bomb readDouble( ) If an invalid character is entered on the keyboard or if no data is entered on the keyboard, allow the exception to move up the call chain and be captured and processed in the calling method.</p><p>So, TestMyInput will catch the exceptions from readDouble( )</p><p>If an exception(s) occurs, display to the screen invalid data entered and the data entered no data entered return a 0</p><p> the program should not bomb readChar( ) design for yourself one or two of your own Exception classes</p><p> in readChar( ) If more than one character is entered on the keyboard, throw one of your exceptions. TestMyInput should catch the Exception and display an error message more than one character entered and the data</p><p>If no characters are entered on the keyboard, throw the other exception. TestMyInput should catch the Exception and display an error message no data entered</p><p> the program should not bomb</p>
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages2 Page
-
File Size-