Question: Write a class called RationalNumber that represents a fraction with an integer numerator and denominator. A RationalNumber object should have the following methods: // Constructs

Write a class called RationalNumber that represents a fraction with an integer numerator and denominator. A RationalNumber object should have the following methods:

// Constructs a new rational number to represent the number, we will

// assume the denominator will not be 0.

public RationalNumber(int num, int den)

// Sets the numerator to 0 and the denominator to 1

public RationalNumber()

// Returns this rational numbers denominator value.

public int getDenominator()

// Returns this rational numbers numerator value.

public int getNumerator()

// Returns a String representation of this rational number, such as "3/5". // If the rational number is "4/1" then the method should return "4".

public String toString()

Please write in Java and on a simple level

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!