Part II: Add your attributes and methods
Your HexaicosadecimalNumber class should know how to express a number in both hexaicosadecimal and decimal. To do this, it should have two attributes: string Representation and double Representation. (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 Java's 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 (double Representation)
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 double To HexaicosadecimalString(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 doesn't do much). Compile and run your program. If you encounter errors, fix them before continuing.
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.