- Rational
Implement a rational number class: Rational
Augment your class with methods for:
a) Initialization (Constructor): parameters are numerator and denominator as integers. You must have 3 constructors as follows
No Parameters: 0 / 1
One Parameter (x): x / 1
Two Parameters (x, y): x / y
b) float getValue(): returns the value of the number
c) [bonus]Rational add(Rational r): adds to another rational number
All your numbers should be saved in Reduced Form
Augment your code with a driver class (that contains "main" method) that constructs two Rational numbers, get the average of the two numbers and prints it on the screen.
ahmedhesham 0 Newbie Poster
stultuske 1,116 Posting Maven Featured Poster
jalpesh_007 -3 Newbie Poster
jalpesh_007 -3 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.