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 1/r, where r is a positive non-zero 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 3/5 as 1/2+1/10.
Complete the following program that, given a set of pseudo-Egyptian fractions
(i.e., a set of distinct positive or negative unit fractions), calculates the
sum and expresses it in its simplest (i.e., 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
2103/5
535223/70
981212937/588
*/
import java.util.Scanner;
public class Fraction {
private int numerator;
private int denominator;
~
public Fraction(){
numerator =0;
denominator =1;
}
public Fraction(int denominator){
this(1, denominator);
}
public Fraction(int numerator, int denominator){
}
public Fraction add(Fraction other){
}
public String toString(){
// Return a string in the form numerator/denominator
}
public static void main(String[] 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 Scanner(data);
while (stream.hasNext()){
denominator = stream.nextInt();
fraction.add(new Fraction(denominator));
}
System.out.println(fraction.toString());
}
}
Fraction.java / * * Fractions A unit fraction is

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!