Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement getWuatrator and getbencoinator. Then fill in the sostring method so that it returns a Fraction in the form numerator denominator, such as or

Implement getWuatrator and getbencoinator. Then fill in the sostring method so that it returns a Fraction in the form "numerator denominator", such as " or ". Main Test your costring method using main. In main, create a Fraction that represents . Then you should ask the user for the numerator and denominator for another Fraction. Create a new Fraction object to represent the user's fraction so you can print it out later. Compute the fractions' sum (in main) as follows

You can store the results of the sum in another Fraction object. Print out the equation and the answer using the objects. Note you do not have to call tostring on the objects explictly. Your output should look something like Enter the numerator: Enter the denominator:

1 public class Fraction 2. 1 private int numerator: private int denominator; public Fraction(int number, int denom) { numerator numer ; denominator denom; ? 1/ Returns the numerator public int getNumerator() { return Numerator;

} // Returns the denominator public int getDenominator() i return Denominator: } /1 Returns a string representing a fraction If in the form // numerator/denominator public string tostring() ? return numerator/denominator: } 3

import java.util.scanner: public class FractionTester public static void main(string[] ergs) f create objects scanner input = new scanner(System. in); Fraction the new Fraction() : // Ask for input system.out.println("Enter the numerator: "); string str = input. nextLine(); System. out.println("Enter the denominator: "); string who = input. nextLines(); create a new Fraction with the user's input return str/who; II Add the fractions return sum. (str/who) + (Numerator/Denominator); /1 Nake use of the getDenominator and getNumerator methods /1 Print out the fractions as an equation system. out. print sum ; // Remember you don't have to call tostring yourself!

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

Mobile Usability

Authors: Jakob Nielsen, Raluca Budiu

1st Edition

0133122131, 9780133122138

More Books

Students also viewed these Programming questions