![]() ![]() Some outputs are unnecessary, some info could be added. Run your program and have a critical look at the inputs and outputs.At least separate user interface and algorithmic tasks. Don't do everything in the main() method.(eo "- \n Your Result: " ( firstNumber - secondNumber )) ĭefault: ("\n Please select a valid character") (eo " \n Your Result: " ( firstNumber secondNumber )) (eo "/ \n Your Result: " ( firstNumber / secondNumber )) (eo "* \n Your Result: " ( firstNumber * secondNumber )) Scanner scanner = new Scanner(System.in) So, a formally-improved version might be: import To me, that looks like old-fashioned C language from the 1970s. Don't declare variables some lines before you use them (like you did with xe and xo).A variable name should clearly tell what its content means. Use variable names like "operation" (good example), and avoid names like "xe", "xo", or "eo".Every reader of your program will see that you are closing your resource, even without your comment. You can omit comments like //Close if the next line does exactly this, explicitly.Use spacing consistently (insert a space after an opening parenthesis or not?). ![]() Use an IDE that can automatically maintain a proper code indentation (the "switch" line is out of alignment).We Java programmers are REALLY used to these conventions, so programs that don't follow them confuse us and lead to mis-interpretations. variables and fields should begin lower-case, closing braces should be placed on their own line. Read and follow the Java code conventions: e.g.Let me suggest some improvements for the next program version. ("\n Select between (*,/, ,-)\n Type out the character in a single letter: ") Ĭase "*": (EO "* \n Your Result: " ( xe * xo )) break Ĭase "/": (EO "/ \n Your Result: " ( xe / xo )) break Ĭase " ": (EO " \n Your Result: " ( xe xo )) break Ĭase "-": (EO "- \n Your Result: " ( xe - xo )) break ĭefault: ("\n Please select a valid character") } Just started out on Java and I would like to know your opinions on this calculator I made, took me 30 minutes so you can be rough.
0 Comments
Leave a Reply. |