• Post Reply Bookmark Topic Watch Topic
  • New Topic

The final output is 0.0. What am I doing wrong?  RSS feed

 
Elka Lacno
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are no errors when running the program, expect my final output is 0.0, when it is supposed to be a number. HELP!!

Here is the class:


The tester class:


HELP!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does not work because you are using == to compare strings:

Use equals() instead:

== in Java compares references, it does not compare the content of objects.
 
Elka Lacno
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just fixed it to

and the output is still 0.0
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elka Lacno wrote:I just fixed it to

and the output is still 0.0

1. Did you change all the other places you're using '=='?
2. Is 'packages' actually equal to "A"? Or could it be equal to "a"? Or could it maybe just start with an "A"?
If you're in any doubt, add a
System.out.printf("packages='%s'%n", packages);
statement to make sure.

Languages are NOT forgiving about stuff like that, so you need to be VERY precise.

Winston
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Elka

Where are you calling the getBill method? I don't see an invocation for it in the code you have posted so the totalFee member variable will always be 0.0. Also, you have 2 arguments for the getBill method which are never used.
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And once you've fixed everything Winston has suggested, you then need to actually call the getBill method otherwise the value of totalFee will always be zero.
 
Elka Lacno
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, I changed all the == signs to .equals(). Our teacher hasn't really taught us that much, which is why I'm very confused. As for calling the getBill() method. I'm not sure where to put that in. I thought that once I returned the totalFee, that that would be good enough.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This will suffice. But you will need to remove the 2 parameters of the getBill method first.
 
Elka Lacno
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
^^^ Thank you so much! It worked
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know you can write a switch-case statement using Strings as the cases? That only works in Java7+.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!