Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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 number

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

How are Internet standards developed?

Answered: 1 week ago

Question

2. Define identity.

Answered: 1 week ago

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

4. Describe phases of majority identity development.

Answered: 1 week ago