Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class called Fraction (this is not related to problem 2 from the text).

ID: 3641813 • Letter: W

Question

Write a class called Fraction (this is not related to problem 2 from the text). Include the following:

int variables for the numerator and the denominator

An empty constructor that sets the fraction to 0/1.

A two-int-argument constructor that accepts the numerator and denominator. Ignore the problem of a 0 denominator at this time.

A copy constructor (public Fraction(Fraction))

Methods: Add, subtract, multiply and divide methods of the following form:

public Fraction add(Fraction) -- This does not modify the fraction it's called on, but returns the result of adding it to the fraction that's passed in.

public double add(double)

public void assign(Fraction) -- copies the argument fraction over the values in this fraction

Thus, the equivilent of a = a + b; is a.assign(a.add(b));

public double getDouble() -- returns the value of the Fraction as a double

override toString() to return a string representation of the fraction in properly reduced form. Be sure to correctly account for negatives.

implement equals(Fraction), and make sure it works regardless of whether the internal representation is reduced.

Explanation / Answer

I will help you out on a large part of this java class, but I cant do the entire thing for you ...Hope it helps public class Fraction { int num; int denom; public Fraction() { num = 0; denom = 1; } public Fraction(int num, int denom) { this.num = num; this.denom = denom; } public Fraction(Fraction inputFraction) { this = inputFraction; } //I will implement two methods and you should be able to do the other two public Fraction add(Fraction add) { return new Fraction(this.num*add.denom + add.num*this.denom, this.denom*add.denom); } public Fraction multiply(Fraction mult) { return new Fraction(this.num*mult.num, this.denom*mult.denom); } public void assign(Fraction assign) { this.num = assign.num; this.denom = assign.denom; } public double getDouble() { return (this.num/this.denom); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote