Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Its urgent, I have main class, But I need Rational class as well. So I can test my rational.java in Main. I need rational.java class

Its urgent, I have main class, But I need Rational class as well. So I can test my rational.java in Main. I need rational.java class which corresponds to the given main class. I need the code in 7 hours. Please can you help me?? import java.util.*; public class Main{ public static void main(String[] args) { try{ Rational r1 = new Rational(16,12); Rational r2 = new Rational(3,5); try { Rational r3 = new Rational(1,0); } catch (IllegalArgumentException e) { System.out.println("Exception catched, r3 discarded!"); } Rational r4 = new Rational(-8,-3); Rational r5 = new Rational(2,-1); List list = Arrays.asList(r1, r2, r4, r5); Collections.sort(list); System.out.println(r4 + " + " + r5 + " = " + r4.add(r5)); System.out.println(r1 + " + " + r2 + " = " + r1.add(r2)); System.out.println(r1 + " - " + r2 + " = " + r1.sub(r2)); System.out.println(r2 + " - " + r1 + " = " + r2.sub(r1)); System.out.println(r1 + " * " + r2 + " = " + r1.mult(r2)); System.out.println(r1 + " / " + r2 + " = " + r1.div(r2)); System.out.println(r1 + " > " + r2 + " : " + r1.compareTo(r2)); System.out.println(r2 + " is " + r2.doubleValue()); System.out.println("In order: " + list); } catch (ArithmeticException e){ e.printStackTrace(); } } }

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions