Computer science

posted by .

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.

.

  • Java? -

    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?

  • Computer science -

    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.

  • Computer science -

    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
    }
    }

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. math

    i need some to explain how to turn 1.05 into a fraction Do you know how to add fractions?
  2. math

    12 1/3 + 7 7/15 switch fractions to improper fractions then find a common denominator to find improper fraction of 12 1/3 multiply whole number (12) by the denominator of the fraction (3) then add the numerator of the fraction (1) …
  3. computer science

    hi i'm taking compsci and I need someone to give me some examples of these classes, thanks! You will have to write a class to represent one of the following items. Note that each class must a proper constructor even though the constructor …
  4. Computer Science

    2. Student that has a name, point and course count. The class should have methods that can: (a) add a grade to the GPA and GPA should be calculated and returned appropriately, (b) create duplicate of itself and return that duplicate, …
  5. Computer Science

    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. 2. Student that has a name, point and course count. The class should have methods …
  6. Computer Sci Help pls

    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. 2. Student that has a name, point and course count. The class should have methods …
  7. math

    The denominator of a fraction is 4 more than the numerator. If both the denominator and the numerator are increased by 1, the resulting fraction equals 1/2. What is the original fraction?
  8. math i need help 3 questions

    1. The numerator and denominator of a fraction are in the ratio of 3 to 4. If 4 is added to the numerator and subtracted from the denominator, the value of the resulting fraction is 4/3. The numerator of the original fraction is A. …
  9. 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?
  10. math

    The denominator of a fraction is 20 more than the numerator of the fraction. If 5 is added to the numerator of the fraction and the denominator is unchanged, the value of the resulting fraction becomes 38. Use x as your variable. Find …

More Similar Questions