wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Eggs Profit and Loss Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Eggs Profit and Loss" Watch "Eggs Profit and Loss" New topic
Author

Eggs Profit and Loss

Michael Humphreys
Greenhorn

Joined: Dec 22, 2010
Posts: 23

Happy New Year To Everybody!!!

I am continuing my project Eggs Profit and Loss. I am now adding an input to the program so user can input the variables and the program would give the user the result. I have read one tutorial and this is what I came up with:



The problem is the program does nothing so I think the problem lies in the system scanner call...but I don't know where.
I do thank you all for the help so far.
Michael
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3056
    
  33

What is the error/output you are getting? Try removing the print statements between the Scanner calls. I think even the print statements will be taken as the input to the Scanner.


Mohamed Sanaulla | My Blog
Michael Humphreys
Greenhorn

Joined: Dec 22, 2010
Posts: 23

Hi All,
Well I figured this one out on my own. lol I was missing a line. I actually have two different ways of doing it. one producis the input on the same line as the string and the other puts the input below the string so all is well ty again.

here is the code I came up with:



Here is the output:


Number of chickens: 250
How many of your chickens are laying hens?
230
What is the cost of feed?
600
What is the price of eggs
2.35
How many eggs did you gather?
230
Michael Humphreys
Greenhorn

Joined: Dec 22, 2010
Posts: 23

I just wanted to post my clean copy of code so if some one is following this thread they can refrance good code. At least that is my intentions lol.

Here is the code:



and the result:

How many eggs did you gather?1000
The price of eggs? 2.25
Number Of Chickens =1000
Number Of Hens = 1000
Number Of Eggs Laid = 30000.0
CostOf Feed =500.0
Loss = -312.5
OH No, You had a loss!! What's the price of chicken meat???

The next phase of this project is to build a GUI to ask for the variable input. I am sure I will have questions LOL.

Michael
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Eggs Profit and Loss
 
Similar Threads
GUI integration with code written
Eggs Profit Loss - Building a GUI
Here i am again with if/else statement now
If-then Statements
Just a bit of advice on my first program.