Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Concepts of Database Management

Authors: Philip J. Pratt, Mary Z. Last

8th edition

1285427106, 978-1285427102

More Books

Students also viewed these Databases questions