posted 3 years ago
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 3 years 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
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
posted 3 years 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 3 years ago
that did it guys it works thank yall so much!!!
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!!!
Are you okay? You look a little big. Maybe this tiny ad will help:
The WEB SERVICES and JAXRS Course
https://coderanch.com/t/690789/WEBSERVICESJAXRS
