The purpose of this tutorial is to get you thinking about conditionals. A conditional is an if - else statement. In your day-to-day activity, you probably weigh options pretty regularly.
If I study hard I should get a great job, otherwise, I'll be working a low-paying job.
In programming, you can test whether a conditional is true or not. For example, a = 1 (a is assigned the value of 1); You'll then run a test to see if a == 1 (does a equal 1). If a == 1, a TRUE boolean value is returned, and in this case a does equal 1 so TRUE is returned.
Boolean is a data type that declares a value as either TRUE or FALSE.
So, in the code below we're creating the AdditionQuiz.java class.
1. We're generating 2 random numbers.
2. We're instantiating the Scanner class to allow us to receive input from the user.
3. We're asking the user what the added product of the two random numbers yields.
4. We're waiting for the user to enter the answer.
5. We're printing out the response. In the last part of the response, we place the conditional that's going to return either TRUE or FALSE depending on the accuracy of the statement.
Side note, Introduction to Java Programming is a great book. The author, Y. Daniel Liang goes into easy to understand, but comprehensive detail with each example.
If I study hard I should get a great job, otherwise, I'll be working a low-paying job.
In programming, you can test whether a conditional is true or not. For example, a = 1 (a is assigned the value of 1); You'll then run a test to see if a == 1 (does a equal 1). If a == 1, a TRUE boolean value is returned, and in this case a does equal 1 so TRUE is returned.
Boolean is a data type that declares a value as either TRUE or FALSE.
So, in the code below we're creating the AdditionQuiz.java class.
1. We're generating 2 random numbers.
2. We're instantiating the Scanner class to allow us to receive input from the user.
3. We're asking the user what the added product of the two random numbers yields.
4. We're waiting for the user to enter the answer.
5. We're printing out the response. In the last part of the response, we place the conditional that's going to return either TRUE or FALSE depending on the accuracy of the statement.
Side note, Introduction to Java Programming is a great book. The author, Y. Daniel Liang goes into easy to understand, but comprehensive detail with each example.
Comments
Post a Comment