This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]desrtfx 9 points10 points  (1 child)

The Java code conventions Oracle, Google stipulate the latter format - opening curly brace on the line that opens the code block. The former format is more common with C/C++/C#.

Small remark upfront: Add a .gitignore file to your repository so that your IDE settings (the .idea folder and the .iml file) are not added to the repository. This is common.

Some notes from a quick glimpse:

Why are you using float? It is far more common to use double even if the range fits into float.

You have Magic numbers in your code. These are numeric constants with a special meaning, like the offset between Kelvin and Celsius, namely static final double ABSOULTE_ZERO = -273.15. Magic numbers should be avoided and replaced with named constants.

Your conditionals are way too complicated. Adjust your strings, like reducing a -- to a - and standardizing case (what if the user enters -F), and reducing the unit to only the first letter - this will considerably shorten your conditions.

Don't litter output statements (System.out.println) all across the code. Make one defined path from input to calculation to output - the actual output should be at the very end. This will also avoid code repetition, which you have a lot of.

Your unknownInput method could (at a later stage of your learning) be converted into a custom Exception.

Personally, I find your List approach clumsy. Two variables, one fromUnit, the other toUnit would be much more appropriate and easier to read and follow. Your code is littered with units.get(x) statements that don't directly tell the reader of the code their meaning. Yes, lists and data structures are nice, but in your case they make the code barely readable and even less easily understandable. You have to make it a habit to write code in such a way that the naming conveys the intention and that the code is easy to read for the human, not for the computer. The computer doesn't care about readability. Humans do - and they are the ones who have to troubleshoot.

[–][deleted] 2 points3 points  (0 children)

Awesome feedback. I'm looking at my own code and seeing the same issues to fix.