From the course: Java 8 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Creating a more complex calculator application

Solution: Creating a more complex calculator application - Java Tutorial

From the course: Java 8 Essential Training

Start my 1-month free trial

Solution: Creating a more complex calculator application

- In this challenge, I asked you to create a complex calculator application that executed any of the four standard mathematical operations. Here's how I solved the problem. First, I have an import statement at the top of the code for the Scanner class. As I've done in previous exercises, I'm using the Scanner class to let the user type in values. And down here at the bottom of the code, I have a getInput method. It receives an argument, a prompt, it prints that prompt to the console, creates a Scanner object and then returns the user's input to the calling scope. In the main method, I'm calling that method twice to get the two numeric values. And then I'm calling it again to let the user choose an operation. So by the time I get to line 12, I have everything I need to process the request. At this line, I'm declaring a double value and I'm initializing it to a value of zero. Now I'm doing it here because once I get into the next block, I don't want to declare the variable. I want the…

Contents