Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java class called Rational for performing arithmetic operations with Rationals.The class Rational must have the following: Data members: private int numerator int denominator

Create a Java class called Rational for performing arithmetic operations with Rationals.The class Rational must have the following:

Data members: private int numerator int denominator

Constructors Default-argument constructor Two-argument constructor to initialize numerator and denominator

Accessors (Getters) public int getNumerator() - return the numerator public int getDenominator() - return the denominator

Modifiers (Setters) public void setNumerator(int value) - set the numerator to value public void setDenominator(int value) - set the denominator to value

public inputRational() Input the numerator and the denominator from the keyboard

public String toString() return a string in the form numerator/denominator

private int gcd(int m, int n) - return the greatest common divisor int r; while(n != 0) { r = m % n; m = n; n = r; } return m;

Add two Rational numbers public void add(Rational, r1, Rational r2)

Subtract two Rational numbers public Rational sub(Rational r2)

Multiply two Rational numbers public void mul(Rational r1 , Rational r2)

Divide two Rational Numbers public Rational div(Rational R)

Return the real value or Rational r1 divided by Rational r2 public static double divToDouble(Rational r1,Rational r2)

For the main method it should have:

Input Rational object R1

Input Rational object R2

Add the Rational objects R1 and R2 and store the result in the Rational object R3. Display the result in the Following Format: numerator/denominator + numerator/denominator = numerator/denominator.

Subtract the Rational object R2 Rrom the Rational object R1 and store the result in the Rational object R3. Display the result in the following Format: numerator/denominator - numerator/denominator = numerator/denominator.

Multiply the Rational object R1 with the Rational object R2 and store the result in the object R3. Display the result in the following Format: numerator/denominator * numerator/denominator = numerator/denominator.

Divide the Rational object R1by the Rational object R2 and store the result in the object R3. Display the result in the following Format: numerator/denominator / numerator/denominator = numerator/denominator.

Display the result or dividing the object R1 by the object R2 in a real number.

Change the numerator or object R1 to 2

Change the denominator or object R2 to 5

Display the numerator or R1 and the denominator or R2 in the following Format: Numerator: ______ Denominator: _____

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

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

3. Would you say that effective teamwork saved their lives?

Answered: 1 week ago