Question: In this project, you will implement a class to represent a rational number. Mathematically (and for this assignment), a rational number is defined as a

 In this project, you will implement a class to represent arational number. Mathematically (and for this assignment), a rational number is definedas a fraction in which the numerator and denominator are integers with

In this project, you will implement a class to represent a rational number. Mathematically (and for this assignment), a rational number is defined as a fraction in which the numerator and denominator are integers with the denominator being non-zero. Requirements To ensure consistency among solutions each implementation must implement the following requirements Your implementation should reflect the definition of a simplified rational number at all times A long (integer) is used to represent both the numerator and denominator * The Rational class must be able to handle both positive and negative numbers. * The rational number must be in simplest form after eve ry operation; that is , % shall be immediately reduced to . In order to simplify a rational number properly, use the the Euclidean Algorithm to determine the greatest common divisor of the two numbers All methods that have an object as parameter must be able to handle an input of null. By definition, the denominator of a fraction cannot be zero since it leads to an undefined value. In Java, this division by zero results in an ArithmeticException; the Rational class must throw an ArithmeticException when division by zero is attempted. The denominator should be initialized to a sensible and consistent value. The numerator shall be initialized to zerc The denominator should always be positive leaving the numerator to indicate the sign of the number (positive or negative) The Rational class shall reside in the default package Methods There are many methods that one would expect to be supported in a Rational class; unless specified you will have to implement all of the described methods Constructors * Rational (O o Description: constructs a Rational initializing the value to 0. Rational (long a) o Parameters: a - the default value for the Rational number. Description: constructs a Rational initializing the value to % Rational (long a, long b) throws ArithmeticException o Parameters a - an integer specifying the initial value of the numerator. b- an integer specifying the initial value of the denominator " " In this project, you will implement a class to represent a rational number. Mathematically (and for this assignment), a rational number is defined as a fraction in which the numerator and denominator are integers with the denominator being non-zero. Requirements To ensure consistency among solutions each implementation must implement the following requirements Your implementation should reflect the definition of a simplified rational number at all times A long (integer) is used to represent both the numerator and denominator * The Rational class must be able to handle both positive and negative numbers. * The rational number must be in simplest form after eve ry operation; that is , % shall be immediately reduced to . In order to simplify a rational number properly, use the the Euclidean Algorithm to determine the greatest common divisor of the two numbers All methods that have an object as parameter must be able to handle an input of null. By definition, the denominator of a fraction cannot be zero since it leads to an undefined value. In Java, this division by zero results in an ArithmeticException; the Rational class must throw an ArithmeticException when division by zero is attempted. The denominator should be initialized to a sensible and consistent value. The numerator shall be initialized to zerc The denominator should always be positive leaving the numerator to indicate the sign of the number (positive or negative) The Rational class shall reside in the default package Methods There are many methods that one would expect to be supported in a Rational class; unless specified you will have to implement all of the described methods Constructors * Rational (O o Description: constructs a Rational initializing the value to 0. Rational (long a) o Parameters: a - the default value for the Rational number. Description: constructs a Rational initializing the value to % Rational (long a, long b) throws ArithmeticException o Parameters a - an integer specifying the initial value of the numerator. b- an integer specifying the initial value of the denominator

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!