Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How do I complete these tasks/project in Java? In mathematics, a rational number is any number that can be expressed as the quotient or fraction

How do I complete these tasks/project in Java?

image text in transcribed image text in transcribed

image text in transcribed

image text in transcribed

In mathematics, a rational number is any number that can be expressed as the quotient or fraction p/q of two integers, a numerator p and a non-zero denominator q. For example, 1/2 is a rational number, as is You can think of 7 as a rational number with an implicit 1 in the denominator. Write a program Rational.java. The purpose of this exercise is to write a class definition that includes a variety of methods, including constructors, instance methods, and modifiers. Download the code in this repo to your local machine. It contains tests you can use to check that your implementation is correct. Constructors, getters Define a class called Rational. A Rational object should have two integer instance variables that store the numerator and denominator. - Write a constructor that takes no arguments and that sets the numerator to 0 and denominator to 1. - Write a function getNumerator() that returns the numerator for the rational number. - Write a function getDenominator0 that returns the denominator for the rational number. - Write a second constructor that takes two arguments p and q, and uses them to initialize the instance variables for the numerator and denominator. Rationalr=newRational(10,15);Rationals=newRational();//initializesthenumber10/15//initializesthenumber0/1 tostring - Write a tostring method for Rational. This method takes no arguments, and returns the string representation of the rational. For example, the rational number 4/3 should be represented as the string "4/3" (no spaces). - Write a main function. Create some rationals and testing that it works with println is a good idea at this stage. When you call println on an object, the object is converted to a string using its tostring method, and the result is what is printed. Reduce Write an instance method named reduce that reduces a rational number to its lowest terms by finding the greatest common divisor (GCD) of the numerator and denominator and dividing through. This method should be a pure method; it should not modify the instance variables of the object on which it is invoked. It should return a new Rational number that has been reduced. You can use this function to return the GCD of two numbers. public static int findGcd(int n1, int n2){ int gcd =1; for (int i=1;i

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

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

Design a health and safety policy.

Answered: 1 week ago