Starting from:

$34.99

Comp248 Assignment 3 Solution



General Guidelines When Writing Programs: Refer to assignment #1 handout.

Question 1: (locker puzzle game)

After all the students have passed through the building and changed the lockers, which lockers are open? Write a program to find your answer. The program should display the answer like this:

Locker x is open
Locker y is open …
Locker z is open


Question 2: (Duplicate Elimination)

Use a one-dimensional array to solve the following problem: Write an application that inputs ten numbers, each between 10 and 100, both inclusive. Save each number that was read in an array that was initialized to a value of -1 for all elements. Assume a value of -1 indicates an array element is empty. You are then to process the array, and remove duplicate elements from the array containing the numbers you input. Display the contents of the array to demonstrate that the duplicate input values were actually removed. Sample Output could be as follows:




Sample 1:

Please input a value in [10,100] value 1: 78 value 2: 34 value 3: 46 value 4: 74 value 5: 87 value 6: 39 value 7: 39 value 8: 46 value 9: 78 value 10: 78 The unique values are: 78 34 46 74 87 39

Sample 2:

Please input a value in [10,100] value 1: 20 value 2: 25 value 3: 34 value 4: 7 Wrong value, please input a value in [10,100]: 77 value 5: 45 value 6: 34 value 7: 120 Wrong value, please input a value in [10,100]: 22 value 8: 34 value 9: 25 value 10: 20 The unique values are: 20 25 34 77 45 22


Submitting Assignment 3

What to submit:
Zip the 2 source codes (the .java files only please, not the entire project) of this assignment as a .ZIP file (NOT .RAR) using the following naming convention: a#_studentID, where # is the number of the assignment and studentID is your student ID number.

For example, for this second assignment, student 123456 would submit a zip file named
a3_123456.zip

Evaluation Criteria for Assignment 3
Source Code
Comments for all 2 questions (3 pts.)
Description of variable and constants 1 pt.
Description of the algorithm 1 pt.
Programming styles for all 2 questions (3 pts.)
Use of significant names for identifiers 1 pt.
Indentation and readability 1 pt.
Welcome Banner/Closing message 1 pt.
Question 1 (7 pts.)
The usage of array 2 pts.
The algorithm used to identify the open lockers 3 pts.
The correctness of displaying the open lockers. 2 pts.
Question 2 (7 pts.)
Declaration and initialization of the array 1 pts.
Only input user values within specified range 1 pts.
Implementation of the algorithm to find duplicates. 3 pts.
Correctly print the result 2 pt.
TOTAL 20 pts.

More products