Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java program question This problem is based on Programming Exercise 12.8. Listing 6.8 - Hex2Dec.java implements the hexToDecimal(String hexString) method which converts a hex string
Java program question
This problem is based on Programming Exercise 12.8. Listing 6.8 - Hex2Dec.java implements the hexToDecimal(String hexString) method which converts a hex string into a int, and a main method that uses it. First type this code (pages 218-219) and test it. (The code does not handle negative numbers correctly, but you can ignore this.) Then define a custom exception called HexFormatException in a file called HexFormatException.java. Make it extend NumberFormatException. Modify the existing code so that the hexToDecimal method will throw a HexFormatException if the string is not a hex string. ("Edge case": Make sure that hexToDecimal throws the exception if the string has length zero.) Finally, modify the main method so that if hexToDecimal throws this exception then the main method will catch it and display an appropriate error message Note: When your HexFormatException class compiles, you may get the following warning message: The serializable class HexFormatException does not declare a static final eralVersionUID field of type long You can get rid of the message by placing this line in your class: public static final long serialVersionUID 1L; Here are three sample runs indicating how your program should behave: Enter a hex number: 1af The decimal value for hex number laf is 431 Enter a hex number: 4gb3 That input is not a valid hexidecimal number. Enter a hex number: That input is not a valid hexidecimal numberStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started