Way Back, You Were Given Two JAVA Programs

Way Back, You Were Given Two JAVA Programs

<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>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    2 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us