Question: Implement Hexadecimal numbers as an Abstract Data Type in Java (Note: the word Abstract in Abstract Data Type does not necessarily mean an abstract class).

Implement Hexadecimal numbers as an Abstract Data Type in Java (Note: the word Abstract in Abstract Data Type does not necessarily mean an abstract class). The name of the new type would be "Hexa". Declare an integer variable in your class to store the decimal value of a Hexadecimal numeral (i.e. for "2D" store 45). Do not forget to properly hide this attribute. Your class would only handle Hexadecimal numbers. Hexadecimal numbers are strings that are combinations of decimals from 0 to 9 and A, B, C, D, E, F characters.

a) Provide addition, subtraction, and multiplication operations with their usual meanings. Each one accepts a Hexadecimal number. All three methods return a new Hexadecimal number.

b) Provide a constructor that accepts a string, which is a text version of a hexadecimal number.

c) Provide a toString operation that returns the string representation of the Hexadecimal number.

d) Write a main and create two Hexadecimal numbers "2D" and "48" (45 and 75). Then demonstrate all operations. Print the results of the operations like: "2D + 4B = 78"

e) Add Exception handling to your constructor. It will throw an exception if one gives a value that is not a Hexadecimal number. Create a user defined exception class and handle it.

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!