Activity 2.3 - Using if statements

Topic

This activity is about nested if statements.

Materials

In addition to the discussion of the solution in the Solution document, the project for this activity contains two classes:

Task

Imagine Alice has purchased a software licence on-line. She already has a trial version of the software. In an email message she is sent a user identification number and a registration code. By entering these, the trial version is converted into a full one.

The activity is to complete the method checkLicence, which compares two integers entered from the keyboard with stored values and accepts the registration if both agree. Otherwise the user is invited to try again.

Instructions

Open the class Ex2_3 and add additional code to the method checkLicence where indicated.

When you have made the required changes, run the project to test your solution. Make sure it works correctly in all four possible cases (i.e., both numbers are right, one or the other of the numbers is wrong, or both numbers are wrong). When prompted for your details, enter them into the window at the bottom of the NetBeans screen and press the Enter key.

The output window for the running project is the place where you enter any
 input from the keyboard.

Notes

The statements that read the numbers from the keyboard are already supplied for you. They make use of an object of a utility class Scanner. The details of how this class works have been deliberately kept behind the scenes, in accordance with the principle of information hiding, but you will learn more about the Scanner class in Unit 4.