Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A driver class, FirstLastProg7, that demonstrates this Fraction class. public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); Fraction c, d, x; //

A driver class, FirstLastProg7, that demonstrates this Fraction class.

public static void main(String[] args)

{

Scanner stdIn = new Scanner(System.in);

Fraction c, d, x; // Fraction objects

System.out.println("Enter numerator; then denominator.");

c = new Fraction(stdIn.nextInt(), stdIn.nextInt()); c.print();

System.out.println("Enter numerator; then denominator.");

d = new Fraction(stdIn.nextInt(), stdIn.nextInt());

d.print();

x = new Fraction(); // a fraction for number 0

System.out.println("Sum:");

x.add(c).add(d);

x.print();

x.printAsDouble();

x = new Fraction(1, 1); // a fraction for number 1

System.out.println("Product:");

x.multiply(c).multiply(d);

x.print();

x.printAsDouble();

System.out.println("Enter numerator; then denominator.");

x = new Fraction(stdIn.nextInt(), stdIn.nextInt());

x.printAsDouble();

} // end main

A Fraction class called Fraction.java that implements these methods:

add This method receives a Fraction parameter and adds the parameter fraction to the calling object fraction.

multiply This method receives a Fraction parameter and multiplies the parameter fraction by the calling object fraction.

print This method prints the fraction using fraction notation (1/4, 21/14, etc.)

printAsDouble This method prints the fraction as a double (0.25, 1.5, etc.)

Separate accessor methods for each instance variable in the Fraction class.

Sample Output

Enter numerator; then denominator.

5

8

5/8

Enter numerator; then denominator.

4

10

4/10

Sum:

82/80

1.025

Product: 20/80

0.25

Enter numerator; then denominator.

6

0

infinity

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

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago

Question

1.what is the significance of Taxonomy ?

Answered: 1 week ago

Question

What are the advantages and disadvantages of leasing ?

Answered: 1 week ago

Question

Name is needed for identifying organisms ?

Answered: 1 week ago