Question: Fraction.java / * * Fractions A unit fraction is a fraction of the form 1 / r , where r is a positive non -
Fraction.java
Fractions
A unit fraction is a fraction of the form r where r is a positive nonzero integer.
An Egyptian fraction is a sum of distinct positive unit fractions, so called
because this is the manner in which ancient Egyptians expressed fractions in general.
For example, they would have written as
Complete the following program that, given a set of pseudoEgyptian fractions
ie a set of distinct positive or negative unit fractions calculates the
sum and expresses it in its simplest ie reduced form by finding the greatest
common denominator.
This is not the same as taking a fraction and determining the set of unit fractions.
Each line of data will contain a set of numbers each of which is separated by whitespace.
They consist of a sequence of m distinct positive or negative integers which are
to be interpreted as representing the denominators of the Egyptian fraction.
For example,
Input Output
import java.util.Scanner;
public class Fraction
private int numerator;
private int denominator;
~
public Fraction
numerator ;
denominator ;
public Fractionint denominator
this denominator;
public Fractionint numerator, int denominator
public Fraction addFraction other
public String toString
Return a string in the form numeratordenominator
public static void mainString args
int denominator;
Fraction fraction new Fraction; Create a zero fraction
String data;
Scanner scanner new Scanner
System.in;
data scanner.nextLine;
Scanner stream new Scannerdata;
while streamhasNext
denominator stream.nextInt;
fraction.addnew Fractiondenominator;
System.out.printlnfractiontoString;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
