Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You will get input from a file called H5.txt Input consists of integers representing the numerator and denominator of fractions. NOTE that some numerators and

You will get input from a file called 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)?

image text in transcribed

H5 - Notepad File Edit Format View Help 4 10 37 4 5 6 15 1 -4 8 23 - 19 -21 1 -8 0 10 1 -12

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

=+ Are unions company-wide, regional, or national?

Answered: 1 week ago

Question

=+j Explain the litigation risks in international labor relations.

Answered: 1 week ago

Question

=+j What rules will apply to the process of negotiations?

Answered: 1 week ago