# A Fraction Program.. need help!

• Newbie
• Posts: 7

3+ Months Ago

A rational number can be represented as the ratio of two integer values, a and b, where b is not zero. The class has attributes for the numerator and denominator of this ratio. The ratio should always be stored in its simplest form. That is, any common factor of a and b should be removed. For example, the rational number 40/12 should be stored as 10/3.
Create the following attributes:
• numerator
• denominator
The class has the following constructors and methods:
• A default constructor that sets the rational number to 0/1.
• A constructor that has parameters for the numerator and denominator, and converts the resulting ratio to simplified form.
• simplify - a private method that converts the rational number to simplified form.
• getGCD(x, y) - a private static method that returns the largest common factor of the two positive integers x and y, that is, their greatest common divisor. For example, the greatest common divisor of 40 and 12 is 4.
• value - public method that returns the rational number as a double value.
• toString - public method that returns the rational number as a string in the form a/b.
The main program should ask for rational number, from the user, as two numbers (numerator, denominator). Note that methods 'simplify' and 'getGCD(x,y)' are private methods. The second constructor will call the private method simplify and the method 'simplify' will call the method 'getGCD(x,y)' . The only way to run the program (get it to simplify the rational number) is to create an object, and pass in the values of numerator and denominator. The second constructor will have to check for any Illegal entries and request new numbers, from the user, if required. There are many ways to find a GCD of two numbers. Do some searching! Call the relevant methods to display the final result. Your main program must have instructions to display the final result using both the methods.
• Genius
• Posts: 8485
• Loc: USA

3+ Months Ago

1) What kind of problem are you having with that assignment?
2) Is that C++ or something else?
3) I should let you know we won't do your homework for you, but we could help you get started on the right track.

[EDIT:] NOTE: By 'we' I'm excluding myself since I don't know programming language other then PHP.
• Newbie
• Posts: 7

3+ Months Ago

well i don't really get how to start it off. cause we have two different files one is the main and the other is the rational, so don't know what goes where. it's in java netbeans!
• Newbie
• Posts: 7

3+ Months Ago

anyone figured it out? really need help with this. thanks!
• ٩๏̯͡๏۶
• Posts: 3423
• Loc: Richland, WA

3+ Months Ago

Your best bet is to do the following, now don't code the functions, but I would start by doing a barebone. Create the varibles, classes and methods.

Quote:
Create the following attributes:
• numerator
• denominator
The class has the following constructors and methods:
• A default constructor that sets the rational number to 0/1.
• A constructor that has parameters for the numerator and denominator, and converts the resulting ratio to simplified form.
• simplify - a private method that converts the rational number to simplified form.
• getGCD(x, y) - a private static method that returns the largest common factor of the two positive integers x and y, that is, their greatest common divisor. For example, the greatest common divisor of 40 and 12 is 4.
• value - public method that returns the rational number as a double value.
• toString - public method that returns the rational number as a string in the form a/b.

## Post Information

• Total Posts in this topic: 5 posts
• Users browsing this forum: No registered users and 37 guests
• You cannot post new topics in this forum
• You cannot reply to topics in this forum
• You cannot edit your posts in this forum
• You cannot delete your posts in this forum
• You cannot post attachments in this forum