Question: HERE IS THE FOLLOWING TASK INSTRUCTIONS TO MAKE THE CODE DOWN BELOW: (please code it in java and use repl.it. I would like it if

HERE IS THE FOLLOWING TASK INSTRUCTIONS TO MAKE THE CODE DOWN BELOW:

(please code it in java and use repl.it. I would like it if you could send the link to your repl.it code as well for help)

Part One

Create a new class called Fraction.java. Include the following:

Data Fields:

numerator (integer)

denominator (integer)

Constructor:

Custom constructor that expects both a numerator and denominator

Methods:

Getter for numerator

Getter for denominator

Method to add (expects one Fraction object, returns a new Fraction object)

((n1) / (d1)) + ((n2) / (d2)) = ((n1d2) + (n2d1)) / d1d2

Method to subtract (expects one Fraction object, returns a new Fraction object)

((n1) / (d1)) - ((n2) / (d2)) = ((n1d2) - (n2d1)) / d1d2

Method to multiply (expects one Fraction object, returns a new Fraction object)

(n1) / (d1) * (n2) / (d2) = (n1n2) / (d1d2)

Method to divide (expects one Fraction object, returns a new Fraction object)

((n1) / (d1)) / ((n2) / (d2)) = (n1d2) / (d1n2)

A toString() method that returns the fraction in / form

Part Two

Write a driver that creates Fraction objects and tests all methods specified above.

So far I have this template to go off of:

public class Fraction{ //data fields private int numerator, denominator;

//constructor public Fraction (int n, int d){ numerator = n; denominator = d; } //accessors public int getNum(){ return numerator; } public int getDen(){ return denominator; } //add //somewhere in a Driver: // Fraction one = new Fraction(1,2); // Fraction two = new Fraction (2,3); //Fraction three = one.add(two); //System.out.println(three); public Fraction add(Fraction otherF){ int n1 = numerator; int d1 = denominator; int n2 = otherF.getNum(); int d2 = otherF.getDen(); //calculate a new numerator and denominator //create and return a new Fraction object } }

Please help me write the rest of the code in basic, beginner java.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!