Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The Java program below consists of two files: Rational.java and RationalTest.java, assumed to be in the same directory. The Rational class represents rational numbers as

The Java program below consists of two files: Rational.java and RationalTest.java, assumed to be in the same directory. The Rational class represents rational numbers as a pair of integers. Complete methods plus(), times() toString(), and equals() in Rational.java so that the output is: 7/5+13/3 = 86/15 7/5*13/3 = 91/15 7/5*(13/3+28/20) = 2408/300 7/5 is not equal to 13/3 7/5 is equal to 28/20 // RationalTest.java class RationalTest{ public static void main(String[] args){ String str; Rational x = new Rational(7, 5); Rational y = new Rational(13, 3); Rational z = new Rational(28, 20); System.out.println(x +"+"+ y +" = "+ x.plus(y) ); System.out.println(x +"*"+ y +" = "+ x.times(y) ); System.out.println(x +"*("+ y +"+"+ z +") = "+ x.times(y.plus(z))); str = (x.equals(y)?" is equal to ":" is not equal to "); System.out.println(x + str + y); str = (x.equals(z)?" is equal to ":" is not equal to "); System.out.println(x + str + z); } } // Rational.java class Rational{ int numerator; int denominator; // Fields Rational(int n, int d){ // Constructor if(d==0) throw new RuntimeException("zero denominator"); numerator = n; denominator = d; } Rational plus(Rational Q){ } Rational times(Rational Q){ } public String toString(){ } public boolean equals(Object x){ } } // end of class Rational

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

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago