Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I am learning how to properly use the this keyword for Java and I needed some help with this fraction challenge. Here is the

Hello, I am learning how to properly use the this keyword for Java and I needed some help with this fraction challenge. Here is the task.

We are going to use this static class as we build out a newFractionclass. Your job is to complete theFractionclass based on the structure that is set up. To do this, you will need to use thethisnotation in your constructor and setters. You will also need to use it to pass the object to theFractionMathclass.

The tester is complete and can be used to test your objects. Feel free to make changes in this class to test other things.

Here is my code so far: Thanks

public class Fraction {   private int numerator;   private int denominator;   public Fraction(int numerator, int denominator){     this.numerator = numerator;     this.denominator = denominator;   } /** * Returns value of numerator * @return numerator */ public int getNumerator() {   return this.numerator; } /** * Sets new value of numerator * @param numerator new numerator value */ public void setNumerator(int numerator) {   this.numerator = numerator; } /** * Returns value of denominator * @return denominator */ public int getDenominator() {   return this.denominator; } /** * Sets new value of denominator * @param denominator new denominator */ public void setDenominator(int denominator) {   this.denominator = denominator; }   /** * Updates this fraction by adding another fraction * @param other Fraction to add to existing fraction */   //Calculate by using the FractionMath class, then update   //the numerator and denominator from the returned Fraction   public void addFraction(Fraction other){       }   /** * Updates this fraction by multiplying another fraction * @param other Fraction to multiple to existing fraction */   //Calculate by using the FractionMath class, then update   //the numerator and denominator from the returned Fraction   public void multiplyFraction(Fraction other){    this.Fraction.add()   }   /** * Prints fraction as numerator / denominator * Example: 1 / 2 */   public String toString(){       } } public class FractionMath {     /*   * This is a static class that the Fraction class will use.   * No updates are needed.   */     public static Fraction add(Fraction frac1, Fraction frac2){     int numerator = frac1.getNumerator() * frac2.getDenominator() +             frac2.getNumerator() * frac1.getDenominator();     int denominator = frac1.getDenominator() * frac2.getDenominator();     Fraction solution = new Fraction(numerator, denominator);     return solution;   }   public static Fraction multiply(Fraction frac1, Fraction frac2){     int numerator = frac1.getNumerator() * frac2.getNumerator();     int denominator = frac1.getDenominator() * frac2.getDenominator();     Fraction solution = new Fraction(numerator, denominator);     return solution;   } } 

How do I properly implement the use of "this " key word in Java in my Fraction class ?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

The most delicate bones in your body called?

Answered: 1 week ago

Question

The part of internal ear responsible for hearing is.....?

Answered: 1 week ago

Question

Ear part and its functions ?

Answered: 1 week ago

Question

The membranous labyrinth contains?

Answered: 1 week ago