Question: This code will go in the file Numbers.java, any tests in a class called ExampleNumbers that you add to that file. (Note: I can write

This code will go in the file Numbers.java, any tests in a class called ExampleNumbers that you add to that file. (Note: I can write WholeNumber and Fraction. The Decimal is the only part I need help)This code will go in the file Numbers.java, any tests in aclass called ExampleNumbers that you add to that file. (Note: I can

Remember that you will not be nesting any interfaces or classes. Doing so will cause th autograder to fail. We saw in our reading that representing fractional numbers like 0.6 with doubles can be fraught. Some languages and libraries do support exact fractions, and we can implement classes that act like them in Java. We won't be able to use the built-in + and * operators, because these are only defined for numbers and strings, but we can define methods for the operations we care about. We can represent numbers with an interface: interface Number { int numerator(); int denominator(); Number add (Number other); Number multiply(Number other); String toText(); double toDouble(); } Your task is to create three classes that implement the interface above. One should be called WholeNumber and represent whole integers. The second should be called Fraction and represent mixed numbers. The third should be called Decimal and represent decimals Decimal should have: You may find it helpful to use Integer.parseInt() to convert a string to an integer. A field int mantissa representing the mantissa of the decimal when expressed in scientific notation A field int exponent representing the exponent of the decimal when expressed in scietific notation An implementation of all the methods above: numerator should return the numerator of the decomal when expressed as a fraction denominator should return the denominator of the decimal when expressed as a fraction add should return a new Number that represents adding this decimal to the one provided as an argument. Note the marinent could be either a WholeNumber, Fraction, or Decimal multiply should return a new Number that represents multiplying this decimal to the one provided as an argument. Note that the argument could be either a WholeNumber, Fraction, or Decimal toText should return a String in the format #. #. So if mantissa is 314 and exponent is -2, this should be "3.14". However, if mantissa is 12345 and exponent is -3, then the result should be "12.345". The amount of numbers before and after the decimal point will depend on the original input. . toDouble should return the value of the number expressed by the mantissa and exponent as a double. So if mantissa is 314 and exponent is - 2, this should be 3.14

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!