Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need assistance writing the following Java code. A mixed number contains both an integer portion and a fractional portion. Design a class MixedNumber of

I need assistance writing the following Java code.

A mixed number contains both an integer portion and a fractional portion. Design a class MixedNumber of mixed numbers that uses the class Fraction. Provide operations for MixedNumber that are analogous to those of Fraction. That is, provide operations to set, retrieve, add, subtract, multiply, and divide mixed numbers. The fractional portion of any mixed number should be in lowest terms and have a numerator that is strictly less than its denominator. Write a Java interface, named MixedNumberInterface, and include comments for each method.

Implement the class MixedNumber by using the operations in Fraction whenever possible. For example, to add two mixed numbers, convert them to fractions, add the fractions by using Fraction's add operation, then convert the resulting fraction to a mixed form. Use analogous techniques for the other arithmetic operations.

Handling the sign of a mixed number can be a messy problem if you are not careful. Mathematically, it makes sense for the sign of the integer part to match the sign of the fraction. But if you have a negative fraction, for example, the toString method for the mixed number could give you the string "-5 -1/2", instead of "-5 1/2", which is what you would normally expect. Here is a possible solution that will greatly simplify computations.

Represent the sign of a mixed number as a character data field. Once this sign is set, make the integer and fractional parts positive. When a mixed number is created, if the given integer part is not zero, take the sign of the integer part as the sign of the mixed number and ignore the signs of the fraction's numerator and denominator. However, if the given integer part is zero, take the sign of the given fraction as the sign of the mixed number.

The MixedNumber class will need to extend java.lang.Number class and implement java.lang.Comparable interface (in addition to MixedNumberInterface). It will also need to override the toString and equals methods of Object class.

write JUnit test for the class

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

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions

Question

When should a purchaser use supplier development and why?

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago