Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 398 Weeks Ago, 3 Days Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 19 Sep 2017 My Price 10.00

rational numbers.

d you can think of 7 as a rational number with an implicit 1 in the denominator. For this assignment, you are going to write a class definition for rational numbers.

1. Create a new program called Rational.java that defines a class named Rational. A Rational object should have two integer instance variables to store the numerator and denominator.

2. Write a constructor that takes no arguments and that sets the numerator to 0 and denominator to 1.

3. Write a method called print Rational that takes a Rational object as an argument and prints it in some reasonable format.

4. Write a main method that creates a new object with type Rational, sets its instance variables to some values, and prints the object.

5. At this stage, you have a minimal testable program. Test it and, if necessary, debug it.

6. Write a second constructor for your class that takes two arguments and that uses them to initalize the instance variables.

7. Write a method called negate that reverses the sign of a rational number. This method should be a modifier, so it should return void. Add lines to main to test the new method.

8. Write a method called invert that inverts the number by swapping the numerator and denominator. Add lines to main to test the new method.

9. Write a method called to Double that converts the rational number to a double (floating-point number) and returns the result. This method is a pure function; it does not modify the object. As always, test the new method.

10. Write a modifier 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 function; it should not modify the instance variables of the object on which it is invoked. To find the GCD, see Exercise 6.10).

11. Write a method called add that takes two Rational numbers as arguments and returns a new Rational object. The return object should contain the sum of the arguments. There are several ways to add fractions. You can use any one you want, but you should make sure that the result of the operation is reduced so that the numerator and denominator have no common divisor (other than 1).

The purpose of this exercise is to write a class definition that includes a variety of methods, including constructors, modifiers and pure functions.

Answers

(5)
Status NEW Posted 19 Sep 2017 10:09 PM My Price 10.00

Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll

Not Rated(0)