This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Hello. I am a novice Java programmer just beginning my training and I have a problem with a program I am writing (source code follows). I cannot get my loop to run, the program states that I am to get user input on wheter they can to convert from Celsius to farenheit and vice-versa, the loop should rpaet until they press "n". Any help appreciated.
[ January 26, 2003: Message edited by: Brusse James ]
Please put your code between CODE markers and indent it correctly. (See below text entry box) What actually happens when you run it? I can't run it because I do not have the IO classes. Paste in some actual output.
Are you sure that this codeis in the right place?
[ January 26, 2003: Message edited by: Barry Gaunt ]
As far as I can see, your control flow (all those 'if else if' thingies) is incorrect. Your code reads:
Two more remarks: 1) the int 'choice1, choice2' variables aren't used; 2) you forget to print the result of the calculations. kind regards
Joined: Nov 22, 2002
Sorry about not having the code markers, I'm new at this. Anyway, when the program is run the 'if' loops are skipped, allowing not input at all, the two int variables (choice1, choice2) I have since deleted they were just a brainstorm. I assumed that nesting the 'if' statements in the do..while loop was the best route, but it hasn't worked. Here is how the screen is supposed to look: 1. Convert Farenheit to Celsius 2. Convert Celsius to Farenheit [user makes choice] Enter number to be converted [user input] [output] number conversion [output] Do you want to continue y/n? My Program will ask for the inputs and then go directly to the y/n question without allowing the user to enter a number. Brusse James
Joined: Nov 22, 2008
What you're showing above is quite something different from what your code is actually doing, but let's get on ... The scenario above can be decomposed into five distinct sections: 1) ask the user what s/he wants (F --> C or C --> F); 2) get temperature input value; 3) perform the wanted calculation; 4) display the results; 5) ask for continuation. The 3rd step can be split further into: 3a) perform F --> C calculation; 3b) perform C --> F calculation. in Java lingo, this should boil down to something like:
Now, it's up to you to fill in the methods userChoice(), userTemperature(), calcFtoC(), calcCtoF(), displayResults() and getUserContinue(). kind regards [ January 26, 2003: Message edited by: Jos Horsmeier ]