Implement immutable data type rational for rational number, Mathematics

Assignment Help:

Implement an immutable data type Rational for rational numbers that supports addition, subtraction, multiplication and division.

public class Rational


Rational(int numerator, int denominator)

Rational

plus(Rational b)

sum of this number and b

Rational

minus(Rational b)

difference of this number and b

Rational

times(Rational b)

product of this number and b

Rational

divides(Rational b)

quotient of this number and b

boolean

equals(Rational that)

is this number equal to that?

String

toString()

string representation

Notes

  1. You do not have to worry about testing for overflow, but use as instance variables two long values that represent the numerator and denominator to limit the possibility of overflow.
  2. Use Euclid's algorithm to ensure that the numerator and denominator never have any common factors.
  3. Include a test client that exercises all of your methods.

 

 


Related Discussions:- Implement immutable data type rational for rational number

What is converse- inverse and contrapositive, What is Converse, Inverse, an...

What is Converse, Inverse, and Contrapositive In geometry, many declarations are written in conditional form "If ...., then....." For Example: "If two angles are right angles,

Describe about parallel and perpendicular lines, Describe about Parallel an...

Describe about Parallel and Perpendicular Lines ? Parallel Lines : Parallel lines are coplanar lines (lines that lie in the same plane) that never intersect. The bl

Example of differential equations, y(x) = x -3/2 is a solution to 4x 2 y′...

y(x) = x -3/2 is a solution to 4x 2 y′′ + 12xy′ + 3y = 0 , y (4) = 1/8 , and y'(4) = -3/64 Solution :  As we noticed in previous illustration the function is a solution an

Find the equation for each of the two planes , Find the equation for each o...

Find the equation for each of the two planes that just touch the sphere (x - 1) 2 + (y - 4) 2 + (z - 2)2 = 36 and are parallel to the yz-plane. And give the points on the sphere

How many inches is the smaller dimension of the decreased, A photographer d...

A photographer decides to decrease a picture she took in sequence to fit it within a certain frame. She requires the picture to be one-third of the area of the original. If the ori

Calculate the investment - apr 4 percent, Suppose you start saving today fo...

Suppose you start saving today for a $55,000 down payment that you plan to make on a house in 7 years,  assume that you make no deposits into the account after the initial deposit,

Simplex table, maximize Z=2x+5y+7z, subject to constraints : 3x+2y+4z =0

maximize Z=2x+5y+7z, subject to constraints : 3x+2y+4z =0

Vijay, how to solve trignometric equations more easier?

how to solve trignometric equations more easier?

Matrix, matrix of [1 4 ] [a b]=4/9

matrix of [1 4 ] [a b]=4/9

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd