File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Eggs Profit and Loss" Watch "Eggs Profit and Loss" New topic

Eggs Profit and Loss

Michael Humphreys

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.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3152

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

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?
What is the cost of feed?
What is the price of eggs
How many eggs did you gather?
Michael Humphreys

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.

I agree. Here's the link:
subject: Eggs Profit and Loss
It's not a secret anymore!