Create a class Rational representing rational numbers as pairs of integers (numerator and denominator), together with basic arithmetical operations and comparisons.
Supply the following constructors:
Rational(int numerator, int denominator).
Rational() getting the numerator and the denominator from a user using a dialog.
Rational(double d); sets the denominator to some power of 10 and calculates the numerator based on the argument value.
Rational(String numerator, String denominator) (convert strings to integer numbers).
Implement the following public methods:
addition: Rational add(Rational arg);
multiplication: Rational mul(Rational arg);
subtraction: Rational sub(Rational arg);
division: Rational div(Rational arg);
equality: boolean equals(Rational arg);
boolean lessThan(Rational arg)
boolean greaterThan(Rational arg)
boolean lessThanOrEqual(Rational arg)
boolean greaterThanOrEqual(Rational arg)
the string representation of the number: String toString();
The methods 1..4 return a reference to a new object of the class Rational as the result of the operation carried out on the argument arg and this object.
The method boolean equals(Rational arg); test two rationals for equality.
The method String toString(); allows for printing the number with the invocation: [url removed, login to view](...).
The constructor must throw the exception IllegalArgumentException, whenever the denominator equals 0.
The method div(Rational arg) throws the exception ArithmeticException, whenever the argument arg represents the value of 0.
The method void reduce(), which reduces this fraction to the common denominator, may turn out useful.
Overload the methods for carrying out arithmetical operations so that they take arguments of type int as well as double:
public Rational add(int i) - adds an integer to this rational.
public Rational add(double d) - adds a double value to this rational. You may use the constructor Rational(double d) in the implementation of this method.
Add static constants: ZERO, ONE.
Supply some tests in the method main(...).
32 freelancers are bidding on average $35 for this job
Having 5 years of java development experience, also sun certified java programmer. will be able to delivered the requirement on time up to your satisfaction.