You are going to be working with the class Rational, which defines rational number objects. A rational number is a number that can be written as a fraction. A rational number consists of a numerator and a denominator (which cannot be 0). Rational numbers also have the ability to be displayed in their original form, decimal form, or reduced form. You are going to be completing various object methods to perform the tasks previously listed.
You are to begin with the Rational Class and RationalTest classes provided. Make all modifications outlined in the point values below. Pay close attention to the names of the attributes, methods, and return values. You are given starter files and the test files necessary. Only modify class Rational and keep the function headers provided to you for all of Part 1.
Part 1a:
This version requires that you complete the constructor, getOriginal(), and getDecimal() methods of class Rational.
- Constructor: At this stage, it should have a parameter list that accepts two arguments, a numerator and denominator that are defaulted appropriately. These parameters must initialize attributes called originalNumerator and originalDenominator.
- getOriginal(self): This method should return a string representation of the original fraction. This method will be used in displayData().
- getDecimal(self): This method should return a string representation of the original fraction as a decimal. This method will be used in displayData().
class Rational(object):
"""This creates a rational number (fraction)"""
def __init__(self, numerator=0, denominator=1):
"""Constructor for a rational number with a numerator and denominator"""
pass # remove pass instruction before you begin
def getOriginal(self):
"""Returns a string representation of the original rational number"""
return Fraction(numerator/denominator)
pass # remove pass instruction before you begin
def getDecimal(self):
"""Returns a string representation of the rational number in decimal form"""
return self.denominator
pass # remove pass instruction before you begin
What do I need to add to this code in order for it to run properly according to the directions?