Question: Main.java Rational.java import java.util.Scanner; A rational number is any number that can be represented as a ratio of integers. The rational class lets us make

 Main.java Rational.java import java.util.Scanner; A rational number is any number thatcan be represented as a ratio of integers. The rational class letsus make objects that represent rational numbers. public class Main { publicstatic void main(String[] args) Complete the reduce, multiply, add, reciprocal, and equals

Main.java Rational.java import java.util.Scanner; A rational number is any number that can be represented as a ratio of integers. The rational class lets us make objects that represent rational numbers. public class Main { public static void main(String[] args) Complete the reduce, multiply, add, reciprocal, and equals methods. Assume that the denominator is never zero. After that, complete the rest of the main method. (5 points) Here is a sample run: Scanner sc = new Scanner(System.in); System.out.println("Enter a numerator and a denominator "); int n = sc.nextInt(); int d = sc.nextInt(); Rational r1 = new Rational n, d); System.out.println( ri.tostring() + + r1.value() ); Rational r1_recip = r1.reciprocal(); System.out.println("The reciprocal is " + r1_recip.toString() ); System.out.println("Enter a 2nd numerator and denominator "); n = sc.nextInt(); d = sc.nextInt(); Rational r2 = new Rational( n, d); Enter a numerator and a denominator 68 3/4 = 0.75 The reciprocal is 4/3 Enter a 2nd numerator and denominator -1 4 The two fractions are not equal Their product is -3/16 Their sum is 1/2 if ( r1.equals( r2 ) ) System.out.println("The two fractions are equal" ); else System.out.println("The two fractions are not equal" ); // multiply r1 by r2 and display the result // add r1 and r2 and display the result } } public class Rational { private int num, denom; n = public Rational( int n, int d ) { // assumes d never equals zero if (d

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!