Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

You will get input from a file called H8.in. 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. Output the Fraction. (I want to see that your gcd method is working even for negative numbers). I DO NOT want to see any 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. This is so that you do not output 3/-4, but rather -3/4. DO NOT store these Fractions in any data structure (such as an array or ArrayList). Just keep track of the biggest and the smallest. At the end of your program output the biggest and the smallest. You will need to alter your Fraction class to include a compareTo method, and you will need to consider carefully how you know one fraction is less than another. Here is what I have so far please edit or add:

public static class Fractions { //Attributes private int numerator; private int denominator; //Constuctors public Fractions() { numerator = 0; denominator=1; } public Fractions(int n, int d) {

} //Setters and gettrs public int getNumerator() { return numerator; }

public void setNumerator(int n) { this.numerator=n; }

public int getDenominator() { return denominator; }

public void setDenominator(int d) { this.denominator=d; } //toString public String toString() { return numerator + "/" + denominator; } //Calculates greatest common factor private int gcd(int int1, int int2) { if ((int1 % int2) == 0) { return int2; } else{ return gcd(int2, int1 % int2); } } public int compareTo(Fractions f) {

} public static void main(String[] args) { //Initialize the file File inFile = new File("H8.in"); Scanner fileInput = null; //try and catch try { fileInput = new Scanner(inFile); } catch (FileNotFoundException e) { }

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 Management An Organizational Perspective

Authors: Richard T. Watson

1st Edition

0471305340, 978-0471305347

More Books

Students also viewed these Databases questions