This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Eggs Profit and Loss

 
Michael Humphreys
Greenhorn
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3159
33
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Michael Humphreys
Greenhorn
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
Android Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic