Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IT IS URGENT PLEASE HELP! Create a class called Rational. A rational number is the ratio of two integers. One is numerator and the other

IT IS URGENT PLEASE HELP!

Create a class called Rational. A rational number is the ratio of two integers. One is numerator and the other one is denominator. There should be operations such as addition subtraction division multiplication and reciprocal and should hide implementation details of data representation and internal manipulations. You should also define the following instance methods boolean isInteger() boolean isZero() boolean isLessThan(RationalNumber other) boolean equals(RationalNumber other) String toString().

Guides: The numerator carries the sign of the rational number. It can be + - or 0

The denominator is kept positive and can never be 0

Rational numbers with same value can be different representation such as 2/4 4/8 6/12. Equal numbers must have the same denominator and numerator. In other words rational numbers must be reduced to their lowest terms. The representation of 0 is as a rational number 0/1.

The representation should be done by a constructed Rational. The constructor shoould take two parameters which are x and y and construct a rational number x/y. The rational number should be reduced by removing the greatest common divisor between the x and y .You should define another method called greatestcommondivisor(it should be a private method because it shouldn't be part of Rational class) that computes the greatest common divisor of x and y and have the constructor use it to create the internal representation. Then create TestRational, then test it by creating several instances and perform operations on them.

Sample:

Rational a,b,c;

a = new Rational(2,20);

b = new Rational(-3,30);

c = a.add(b);

System.out.println(a + " + " + b " = " c);

c = a.multiply(b);

System.out.println(a + " a " + b " = " c);

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago