Sunday

January 25, 2015

January 25, 2015

Posted by **Sarah N** on Friday, May 28, 2010 at 10:38pm.

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.

.

- Java? -
**MathMate**, Friday, May 28, 2010 at 10:57pmWhat 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?

- Computer science -
**Sarah N**, Friday, May 28, 2010 at 11:07pmSorry, 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.

- Computer science -
**MathMate**, Saturday, May 29, 2010 at 7:36amSo 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

}

}

**Answer this Question**

**Related Questions**

computer science - hi i'm taking compsci and I need someone to give me some ...

math - i need some to explain how to turn 1.05 into a fraction Do you know how ...

math - 12 1/3 + 7 7/15 switch fractions to improper fractions then find a common...

math - The denominator of a fraction is 4 more than the numerator. If both the ...

8th grade math - The denominator of a fraction is 4 more than the numerator. If ...

algebra - The denominator of a fraction is 12 more than the numerator. If 16 is ...

Math-Algebra - The numerator of a fraction is 3 less than the denominator. If 5 ...

Maths - When the numerator and denominator of a fraction are each increased by 5...

Math - The denominator of a fraction is 4 more than the numerator. If both the ...

Algebra - The denominator of a fraction is 2 less than twice the numberator. If ...