CN4001 Applied ICT Principles Assignment - Topic: Making

Post New Homework

CN4001 Applied ICT Principles Assignment - Practical Exercises Topic: Making Choices, Staffordshire University, UK

Task 1 - For this task we will attempt to write a program that asks the user to enter two numbers and then compares these two numbers.

a) Create a NEW PROJECT (New > New Project) - call it Lab3a (make sure Create Main Class is unticked)

b) Add a new MAIN CLASS to your project (New > File> Java Main Class) - call it CompareApp.

c) Write the code to declare two variables, 'num1' and 'num2' say. These variables should be able to hold whole numbers only. Then write additional code to allow the user to enter values into these two variables.

d) Use in if statement so that the message "Numbers ARE equal" is displayed if the two numbers are equal. Then display an "END OF PROGRAM" message at the end of the program.

e) Add an else branch to the above if statement so that the message "Numbers ARE NOT equal", is displayed if the two numbers are not equal. The "END OF PROGRAM" message should still be displayed at the end of the program.

f) Modify the program further so if the two numbers are not equal, as well as displaying the message "Numbers ARE NOT equal", the program then displays "FIRST number BIGGER" if the first number is bigger than the second or displays "SECOND number BIGGER" if the second number is bigger than the first. The "END OF PROGRAM" message should still be displayed at the end of the program.

g) Add some Javadoc comments into this program.

h) Show your work to your tutor and then upload the CompareApp.java file to Moodle via your group's submission link.

Task 2 - For this task we will attempt to write a program that reveals secrets to spies depending upon their security level (1-3).

a) Create a NEW PROJECT (New > New Project) - call it Lab3b (make sure Create Main Class is unticked)

b) ADD A NEW MAIN CLASS to your project (New > File> Java Main Class) - call it SecretsApp.

c) This program will allow spies to enter their security level. Declare the appropriate variable and a Scanner object.

d) Write the code that asks the user to enter their security level and store this level in the appropriate variable.

e) The following secrets can be revealed to the spies depending upon their security level:

LEVEL 3: "The cook is an alien"

LEVEL 2: "There is a secret room in the basement"

LEVEL 1: "The security guard is a robot"

Use a switch statement to reveal the correct secret to the spy (note, only 1 secret should be revealed to each spy). Then display an "END OF PROGRAM" message at the end of the program.

f) Finally, adapt the program so that an error message "NO SUCH LEVEL" is displayed when an incorrect security level is entered.

g) Add some Javadoc comments into this program.

h) Show your work to your tutor and then upload the SecretsApp.java file to Moodle via your group's submission link.

Extra Challenges -

1. Modify the CompareApp program further so if the two numbers are not equal, as well as displaying the message "Numbers ARE NOT equal", the program also displays "FIRST number BIGGER" if the first number is bigger than the second and displays "SECOND number BIGGER" if the second number is bigger than the first.

2. Modify the switch statement from the SecretsApp program so that a spy with level 3 clearance can get to see all 3 secrets, the spy with level 2 can see both level 2 and level 1 secrets, but a spy with level 1 clearance can only see the level 1 secret.

3. Create a suitable project and Class in NetBeans to solve the following task:

Implement a program that asks the user to enter two numbers and then guess at the sum of those two numbers. If the user guesses correctly a congratulatory message is displayed, otherwise a commiseration message is displayed along with the correct answer.

Note - Just make programming.

Post New Homework
Captcha

Looking tutor’s service for getting help in UK studies or college assignments? Order Now