Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Missing Output While Incorporating A Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Missing Output While Incorporating A Class" Watch "Missing Output While Incorporating A Class" New topic
Author

Missing Output While Incorporating A Class

B Mart
Greenhorn

Joined: Mar 08, 2011
Posts: 5
I would appreciate any assistance with this program. It compiles perfectly but I'm not getting any output. Thank you!





[HENRY: Added code tags]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I'm not getting any output.

How did you execute it ?


[My Blog]
All roads lead to JavaRanch
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18545
    
  40

The output when I ran it...

24 Oranges
at 10 for $2.99

36 Eggs
at 12 for $1.69

20 Apples
at 3 for $1.0

2 Watermelons
at 1 for $4.39

12 Bagels
at 6 for $3.5


Total: 34.69266666666667


Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Total: 34.69266666666667

What currency is this ?
B Mart
Greenhorn

Joined: Mar 08, 2011
Posts: 5
Henry, what program did you run it in? I wasn't getting any output in J Creator. Also, how can I reduce the decimals down to 2? I appreciate everyone's help!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I ran it in Eclipse and got the same output as Henry. You're probably not executing it properly under JCreator. I don't know that editor so I can't help further.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38046
    
  22
Welcome to the Ranch

When I used JCreator, I usually used it as an editor and executed the code from the command line. Isn't there a project→run option? If you do that, do you see a window similar to a command line? That is where the output should be.
To get a certain number of places after the decimal point, try the % tags.

You have some peculiar design there. Why are you not setting those values via a constructor? You don't usually call a getXXX method without assigning its value to something, as you are doing.
B Mart
Greenhorn

Joined: Mar 08, 2011
Posts: 5
I know it's weird code. It's a program for an assignment and they give you the class of Purchase and you are supposed to use it to total the bill (oranges, apples, etc.)
B Mart
Greenhorn

Joined: Mar 08, 2011
Posts: 5
p.s. Thank you for the warm welcome!
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38046
    
  22
Have you got it to work yet? Have you tried compiling and running it from the command line?
 
jQuery in Action, 2nd edition
 
subject: Missing Output While Incorporating A Class
 
Similar Threads
Need help..Please! How to keep a running total...
Java Classes
Exception in Thread-Inventory Program
Why is my type unexpected? required variable found value
Need advice - How to add items and keep a running total.