# Computer science

1.Fraction that has a numerator and a denominator. The class should
have methods that can:
(a) add and subtract two Fractions together and
return the resulting Fraction,
(b) create a duplicate of itself and return the duplicate,
(c) see if another Fraction is equivalent to itself and return True or False appropriately and
(d) reduce itself to the lowest equivalent Fraction.

.

1. 👍
2. 👎
3. 👁
1. What are you supposed to do for the exercise - pseudocode, public class,...?

Can you pin-point your difficulty with the problem.

Is it the logic or the syntax that gives you problems? I assume you are programming in Java?

1. 👍
2. 👎
2. Sorry, It's Java, and I am suppose to
write a class to represent one of the following items. Note that each class must a proper constructor even though the constructor is not explicitly named.

1. 👍
2. 👎
3. So you start off with defining the public class, the instance variables, and the constructors. If you define a constructor with parameters, it is always preferable to define one without to replace the default constructor.
A constructor has the same name as the class, and has no return type.

To make a (shallow) copy of an instance, you will need a copy constructor, which is a constructor which has a single parameter of type equal to the class, such as:
public Fraction(Fraction f){....}

I'll get you started. Post your code if you have difficulties.

public class Fraction
{
// instance variables
private int numerator;
private int denominator;
// constructors
public Fraction()
{ // default constructor, do nothing
}
public Fraction(Fraction original)
{
// write your code here
}
// write your constructor here
// write your other methods here
public static void main(String[] args)
{
// write your code to test the class
}
}

1. 👍
2. 👎

## Similar Questions

1. ### Math

The denominator of a fraction in the simplest form is greater than the numerator by 1. If 4 is added to the numerator, and 3 is subtracted from the denominator, then the fraction itself is increased by 2 1/6 . Find the original

2. ### algebra

The denominator of a fraction is 3 more than twice the numerator. If both the numerator and denominator are decreased by 7 and the simplified result is 7/19 find the original fraction

3. ### math

the numerator of a fraction is 3 less than the denominator. if 4 us added to the numerator and to the denominator, the resulting fraction is equivalent to 3/4. find the original fraction. Show your solution

4. ### Mathematics

The numerator of a fraction is 4 less than its denominator. If both the numerator and the denominator of the fraction are increased by 2, then the resulting fraction is equal to 3/5. What is the fraction? Write an equation that

1. ### Algebra 2

The Denominator of a fraction exceeds the numerator by 4. When 3 is added to both the numerator and denominator, the fraction becomes 4/5. Find the fraction.

2. ### Algebra

the denominator of a fraction exceeds the numerator by 7, if the numerator is increased by 3, and the denominator is increased by 5, the resulting fraction equals 1/2. Find the original fraction.

3. ### Maths

The numerator of a fraction is 5 less than the denominator. If 1 is added to both the numerator and denominator the fraction would become 2/3. Find the fraction

4. ### Math

The numerator of a fraction is two less than its denominator. When both numerator and denominator are increased by 3, the fraction is incre ased by 3/20. Find the original fraction. Pls include solution and workings thx :)

1. ### Math

Which statements about comparing fractions are correct? Select all that apply. A. When two fractions have the same denominator, the fraction with the greater numerator is greater. B. When two fractions have the same numerator, the

2. ### algebra

The denominator of a fraction is 4 less than the numerator .If the denominator is doubled and the numerator is increased by 6,the sum of the original fraction and the new one is 3 .Find the original fraction.

3. ### Math

A fraction has a value 2/3. If 4 is added to the numerator and the denominator is decreased by 2, the resulting fractions have the value 6/7. What is the original fraction? (Let x be the numerator and y be the denominator)

4. ### MATH

the numerator of a fraction is one-half the denominator! If the numerator is is increased by 2 and denominator is decreased by 2, the value of the fraction is 2/3. What is the numerator of the original fraction?