![]() ![]() I'd avoid the special characters like ℉ and instead write two simple characters ☏. This way, when reading your program (maybe half a year later), you immediately see at the same place that celsius is a double number coming from some input. celsius = input.nextDouble(), I'd combine that to read double celsius = input.nextDouble(). You wrote double fahrenheit, celsius and later e.g. Minor hintsĬombine variable declaration and value assignment. ![]() By the way, doing so will be easier if the different tasks have been separated. I'd either ask the user at the beginning for the conversion he wants, or make it two different programs. This will rarely both be needed at the same time. Your current program always forces the user to do exactly one C-to-F and then one F-to-C conversion. use a window system, or do bulk conversions of many values at once, etc. With separate methods, it will be easier to later change your program to e.g. ![]() output a Celsius value (a method void printCelsius(double celsius)).output a Fahrenheit value (a method void printFahrenheit(double fahrenheit)).convert from Fahrenheit to Celsius (a method double toCelsius(double fahrenheit)).convert from Celsius to Fahrenheit (a method double toFahrenheit(double celsius)).input a Fahrenheit value (a method double readFahrenheit()).input a Celsius value (a method double readCelsius()).Make it a habit to separate tasks that can be named individually into methods of their own: Your main method contains both aspects in one piece of code, even within the same line (e.g. Separate user interaction from computation Take them as a hint where to go from here, as soon as you feel ready for the "next level". Period.īut you're presenting your code here to get advice how to improve your programming skills, so here are a few remarks. ![]()
0 Comments
Leave a Reply. |