Pa Practice 1
Pa Practice 1
Pa Practice 1
SCHOOL OF COMPUTING
INSTRUCTIONS TO CANDIDATES
1. This assessment paper consists of 2 exercises on 5 pages.
2. This is an OPEN BOOK assessment. You may bring in any printed material and a
calculator, but not other electronic devices such as laptops, iPads or thumb-drives.
3. In line with the university rules, any form of communication with other students, or the
use of unauthorised materials is considered cheating and you are liable to the disciplinary
action.
4. The first 10 minutes of the assessment is reserved for you to read questions and design
algorithms. You are not allowed to type your programs in this period of time.
5. You are to use DrJava or VS Code to write your programs. No other IDEs are allowed.
6. You may assume that all input data are valid; hence no input validation is needed.
7. Once finish, you may submit your programs to CodeCrunch for automatic grading.
8. You are NOT allowed to use any Java language syntax not covered in weeks 1-9 (e.g.,
string functions or recursion).
Two sample runs of the program are shown below with the user's input shown in bold.
Sample run #1
Enter the number of integers in set A: 3
Enter set A: 4 5 14
Enter the number of integers in set B: 5
Enter set B: 1 2 3 5 9
A ^ B contains 1 integer(s)
A - B = [4, 14]
Sample run #2
Enter the number of integers in set A: 3
Enter set A: 5 6 7
Enter the number of integers in set B: 3
Enter set B: 5 6 7
A ^ B contains 3 integer(s)
A - B = []
Note that when you look from south to north at sea level (0 meter), taller buildings would
“override” low buildings. So the skyline essentially consists of the tallest building in each
column.
Write a program Skyline.java that reads the map of a city area and prints out its skyline. In
the skeleton program, complete the following four methods:
1) int[][] readMap() that reads a map into a two-dimensional array and returns
it. You may assume the following: a given map contains at least 2 rows and 2 columns,
there is at least one building in the given map, and the height of every building is
multiple of 10 meters.
2) int[] checkHeights(int[][] map) that returns a one-dimensional array
that stores the maximum height of each column of the given map. For example, such
an array for the above example map will be {70, 40, 40, 80, 20, 20}.
Two sample runs of the program are given below with the user's input shown in bold. For
your convenience of testing, test inputs are also appended to the back of the skeleton
program.
Sample run #1
Enter the size of map: 5 6
Enter 5*6 map:
10 10 10 10 10 10
10 40 40 10 20 20
70 10 10 80 20 20
0 0 0 0 0 0
0 0 0 0 0 0
#
# #
# #
# #
####
####
######
######
Tip: a skyline actually consists of hashes ('#') and spaces (' '). If you replace spaces (' ') with
dashes ('-') for easy identification, the above skyline would be:
---#--
#--#--
#--#--
#--#--
####--
####--
######
######