I've just finished writing my very first program, a simple calculator, after only five days of learning Java through videos! I typically study for an hour or two each night. It took me almost an hour to write and debug everything from scratch, which I know is a bit slow, but I feel really accomplished! I'm open to all kinds of feedback. Thanks!
4 Answers
Great job on getting your first program up and running! Here are a few tips:
1. Try to keep your `System.out.println` statements on one line unless they get too long. It keeps your code cleaner.
2. Use more descriptive variable names instead of just `a` and `b` to make your code easier to understand.
3. Consider breaking your main method into smaller methods to enhance readability and reuse code.
4. Define your variables only when needed. For example, you can directly initialize them with `keyboard.nextDouble()`.
5. Use comments sparingly. Your code should ideally be self-explanatory, but you can add comments if something isn't clear.
Happy coding!
Awesome work! Diving right into projects is a fantastic way to learn. You’ve built a solid foundation here. To push your skills, consider allowing multiple operands—like entering `20 + 20 + 20` to total 60—or implementing operator precedence with parentheses, such as `4 * (5 + 2)`. Parsing more complex math could be a fun challenge! Good luck with your coding journey!
Nice job checking for division by zero! In the future, you might want to explore using a try/catch block for exceptions like `ArithmeticException`. You could also consider implementing a variable for `result` that stays outside the switch statement to avoid duplicating the print statement. It could simplify your code. Plus, you can print errors to `System.err` instead of `System.out` for better debugging.
Does your calculator work with decimals, or just whole numbers?
I set it up to use double, so it can handle decimals!

Thanks for the tips! I'll definitely try that out!