# java fraction calc now compiles but output is wrong

Richard Scott

Ranch Hand

Posts: 30

posted 1 year ago

- 0

so all the errors in the code is fixed but its now got the wrong output

what I get:

Enter numerator; then denominator.

5

8

5/8

Enter numerator; then denominator.

4

10

4/10

Sum:0/0

it should be:

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

here is the code

Fraction.java

and the driver

what I get:

Enter numerator; then denominator.

5

8

5/8

Enter numerator; then denominator.

4

10

4/10

Sum:0/0

it should be:

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

here is the code

Fraction.java

and the driver

Richard Scott

Ranch Hand

Posts: 30

Richard Scott

Ranch Hand

Posts: 30

posted 1 year ago

ok so I have updated the driver, I realized I was using the wrong one! here it is:

and here are some more errors

Prog7.java:13: error: cannot find symbol

x.printAsDouble();

^

symbol: method printAsDouble()

location: variable x of type Fraction

Prog7.java:18: error: cannot find symbol

x.printAsDouble();

^

symbol: method printAsDouble()

location: variable x of type Fraction

Prog7.java:21: error: cannot find symbol

x.printAsDouble();

^

symbol: method printAsDouble()

location: variable x of type Fraction

3 errors

- 0

Richard Scott wrote:Paul Clapham wrote:Your Fraction constructor produces an invalid fraction: 0/0 has no meaning. (And worse, it makes your calculations fail.) I would suggest 0/1 for a default whose value is zero.

ok that's fixed but its still not printing the double or the product

ok so I have updated the driver, I realized I was using the wrong one! here it is:

and here are some more errors

Prog7.java:13: error: cannot find symbol

x.printAsDouble();

^

symbol: method printAsDouble()

location: variable x of type Fraction

Prog7.java:18: error: cannot find symbol

x.printAsDouble();

^

symbol: method printAsDouble()

location: variable x of type Fraction

Prog7.java:21: error: cannot find symbol

x.printAsDouble();

^

symbol: method printAsDouble()

location: variable x of type Fraction

3 errors

Mike. J. Thompson

Bartender

Posts: 689

17

posted 1 year ago

That's because you never call printDouble(), and you never multiply any of the Fractions together or attempt to print the result.

Edit: And extra posts have been made since I started this so my post now is not relevant!

- 1

Richard Scott wrote:

ok that's fixed but its still not printing the double or the product

That's because you never call printDouble(), and you never multiply any of the Fractions together or attempt to print the result.

Edit: And extra posts have been made since I started this so my post now is not relevant!

Richard Scott

Ranch Hand

Posts: 30

posted 1 year ago

that did it guys it works thank yall so much!!!

- 0

Mike. J. Thompson wrote:Richard Scott wrote:

ok that's fixed but its still not printing the double or the product

That's because you never call printDouble(), and you never multiply any of the Fractions together or attempt to print the result.

Edit: And extra posts have been made since I started this so my post now is not relevant!

that did it guys it works thank yall so much!!!

I agree. Here's the link: http://aspose.com/file-tools |