Question
In Java please: You will get input from a file called H5.txt Download H5.txt Input consists of integers representing the numerator and denominator of fractions.
In Java please:
You will get input from a file called H5.txt Download H5.txt
Input consists of integers representing the numerator and denominator of fractions. NOTE that some numerators and some denominators will be negative.
As you input 2 integers create a Fraction object. Your constructor should not allow negative denominators. If both numerator and denominator are negative make both positive, if the denominator is negative but the numerator is positive then flip those signs so that the numerator is negative and the denominator positive. Your constructor should also reduce the fractions.
NOTE: when trying to reduce a fraction you still need to find the biggest POSITIVE integer that divides numerator and denominator without leaving a remainder, even if your numerator or denominator is negative . So your constructor (and any other method) calls your gcd method like this:
int g = gcd(Math.abs(n), Math.abs(d)); so that the parameters are positive even if n or d are negative. (Math.abs gives you the absolute value)
After creating each Fraction object, add it to an arraylist.
Output the entire arrayList. (I want to see that your gcd method is working even for negative numbers). I DO NOT want to see any negative denominators.
At the end of your program output the biggest and the smallest Fraction (as a Fraction).
For example: The biggest Fraction was 119/120
The smallest Fraction was -2/37
Hint: Some students are having problems because they are calling the gcd method even when the numerator is zero. This leads to a problem within gcd, because it finds the smallest positive integer, which will be zero, and then tries to test if zero divides the integers leaving no remainder. So consider when to call gcd. If n==0, do you really want to write int g = gcd(n.d)??
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started