Question: Project 2 Inheritance and interface Task 1 Define a Rational class based on Number and Comparable A Rational number has a numerator and a denominator

 Project 2 Inheritance and interface Task 1 Define a Rational class

Project 2 Inheritance and interface Task 1 Define a Rational class based on Number and Comparable A Rational number has a numerator and a denominator in the form a/b, where a is the numerator and b the denominator. For example, 1/5, 13/4, and 7/9 are rational numbers. Java provides data types for integers and floating- point numbers, but not for rational numbers. It is helpful to define a Rational class for representing rational numbers. Since rational numbers share many features with integers and floating-point numbers, and Number is the root for numeric wrapper classes, it is appropriate to define Rational as a subclass of Number. Since rational numbers are comparable, the Rational class should also implement the Comparable interface. Figure 1 illustrates the Rational class and its relationship to the Number class and the Comparable interface Write a program to test your Rational class, such as the additions, subtractions, multiplications, divisions, and numbers. comparisons for Rational Figure 1. Rational Diagram

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!