Question: I have provided a main method. Please add your fraction class. You need constructors, add, subtract, multiply, and divide methods, and a toString method. Your

I have provided a main method. Please add your fraction class. You need constructors, add, subtract, multiply, and divide methods, and a toString method. Your toString method needs to return the numerator followed by / followed by the denominator - NO spaces. DO NOT make any attempt to reduce the fractions (we shall do that later).

Please add comments throughout.

import java.util.Scanner;

public class H4 {

public static class Fraction { } public static void main(String[] args) { Fraction f= new Fraction(); //test default constructor System.out.println(f); //test mutators f.setNumerator(4); f.setDenominator(5); //test accessors System.out.println("numerator is " + f.getNumerator() + " and denominator is " + f.getDenominator()); System.out.println(f); //test constructor Fraction g= new Fraction(8,19); System.out.println(g); Scanner keyboard = new Scanner (System.in); //get the data for the next fraction and construct it int n1=keyboard.nextInt(); int d1=keyboard.nextInt(); Fraction one=new Fraction (n1,d1); //get the data for the next fraction and construct it n1=keyboard.nextInt(); d1=keyboard.nextInt(); Fraction two=new Fraction (n1,d1); //test methods for add, subtract, multiply, divide System.out.println(one + " + " + two + " = " + one.add(two)); System.out.println(one + " - " + two + " = " + one.subtract(two)); System.out.println(one + " * " + two + " = " + one.multiply(two)); System.out.println(one + " divided by " + two + " = " + one.divide(two)); } }

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!