From the course: Learning Java 11
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Sample solution: Multiple choice - Java Tutorial
From the course: Learning Java 11
Sample solution: Multiple choice
(upbeat music) - [Instructor] Let's walk through how to create a multiple-choice program in Java. From the previous lesson we started off with this template. The first thing we need to do is come up with our question and answer choices. Our question will be what is the largest planet in our solar system. The answer choices will be Earth, Jupiter, and Saturn. We set the correct answer choice to be equal to choice two because Jupiter is the largest planet in the solar system. I could make choice three have the value Jupiter and then choice two have the value Saturn but I would need to remember to update correct answer to choice three instead of choice two. Next we'll ask our question. Then we'll give the user some answer choices. To retrieve the users input we create a scanner using system.n and you use the .next operation. Now for the control flow portion. We can use an if statement to check if the users input matches the correct answer. If the condition is true we'll print out a…
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)
Mapping out program control flow3m 57s
-
(Locked)
Operators in Java2m 26s
-
(Locked)
Decision-making with if in Java4m 8s
-
(Locked)
Understanding scope in Java1m 39s
-
(Locked)
While loops (conceptually)1m 53s
-
(Locked)
While loops in Java3m 19s
-
(Locked)
Challenge: Multiple choice2m 22s
-
(Locked)
Sample solution: Multiple choice5m 1s
-
(Locked)
-
-
-
-