Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your HexaicosadecimalNumber class should know how to express a number in both hexaicosadecimal and decimal. To do this, it should have two attributes: stringRepresentation and
Your HexaicosadecimalNumber class should know how to express a number in both hexaicosadecimal and decimal. To do this, it should have two attributes: stringRepresentation and doubleRepresentation. (What types should these variables be, and what should their access modifiers be?)
Your HexaicosadecimalNumber class should have two constructors, both of which will populate the two attributes appropriately. One will take as input a String (representing a number in hexaicosadecimal), and the other will take as input a double. Both methods have to populate both attributes.
You might now be thinking, How do I populate both attributes when I only have one representation as input to the constructor? You will need two helper functions: hexaicosadecimalStringToDouble(String in) and doubleToHexaicosadecimalString(double in). You should call these functions in your constructors as needed.
You should also override the toString() method of HexaicosadecimalNumber. This is a special method that belongs to Javas Object() class, from which all other classes including HexaicosadecimalNumber are derived. The signature of the toString() method is
public String toString()
As you can see from the method signature, this function is public, takes no arguments, and returns a String. This function is called automatically when an object of that class is printed, for example by System.out.println().The string should be in the following format:
stringRepresentation (doubleRepresentation)
That is, if your hexaicosadecimal number object is named temp and contains the value abcde (for which the equivalent decimal representation is 19010.0; check this later!), the result of
calling
System.out.println(temp)
should be
abcde (19010.0)
For the two helper functions - hexaicosadecimalStringToDouble(String in) and doubleToHexaicosadecimalString(double in) just have them return dummy values for now. (I.e. return 0.0 from the first function, and NOT IMPLEMENTED from the second.) At this point, you should have a complete working program (that doesnt do much). Compile and run your program. If you encounter errors, fix them before continuing.
Step 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