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 - Java Tutorial
From the course: Java 8 Essential Training
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
Programming conditional logic3m 45s
-
(Locked)
Using the switch statement4m 51s
-
(Locked)
Creating looping code blocks5m 23s
-
(Locked)
Creating reusable code with methods4m 15s
-
(Locked)
Overloading methods with different signatures4m 51s
-
(Locked)
Passing arguments by reference or by value4m 47s
-
(Locked)
Challenge: Creating a more complex calculator application1m 53s
-
(Locked)
Solution: Creating a more complex calculator application3m 23s
-
(Locked)
-
-
-
-
-
-