Sale!

CS2230: Data Structures Homework 1

$30.00

Category:

CS2230: Data Structures
Homework 1
Total points = 20

To submit the program, zip all documents into a single file. Submit your solution through
ICON Dropbox. Be sure to change the name on the author tag to your full name. Always
save the proof of submission, otherwise we can’t verify if you submitted your
assignment.
Problem 1 (10 points)
Write a method called ifEqual that takes as input an array of integers, and returns
TRUE if there is at least one pair of integers that are equal to each other, and FALSE
otherwise. For example, when the input array is [51,30,56,-24,14,56], ifEqual
should return true; whereas if the input array is [51,30,56,-24,14,17,89,98],
ifEqual should return false.
The given program (Equality.java) contains a dummy method called ifEqual,
and your solution should fill out the body of the method. You must SUBMIT your version of
Equality.java containing all necessary changes.
Problem 2. (10 points)
You are going to develop a simple airplane seat reservation system in this problem. Assume a
small airplane with seat numbers show in the following pattern:
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
8 A B C D
Notice that there are eight rows and four columns in this example. Assume an ‘X’ marks that the
seat is already assigned. Thus, if seats 2C and 5A are already assigned, the representation should
look like:
1 A B C D
2 A B X D
3 A B C D
4 A B C D
5 X B C D
6 A B C D
7 A B C D
8 A B C D
You are given an incomplete program (AirplaneSeatReservation.java) that uses a
two-dimensional character array seats. Check the constructor method of the given program
Fall 2016 August 29, 2016
carefully to understand how the array is initialized. Initially no seat is assigned. Your task is to
implement the following methods:
A. reserveSeat(): This method takes an integer parameter row and a character
parameter col. These two parameters represent a specific seat that corresponds to
a specific slot in the two-dimensional array. The method simply puts the character
‘X’ in the correct slot to mark the corresponding seat as taken. For example, if row
is 2 and col is ‘A’, this method replaces the content of seats[1][0] by the
character ‘X’. Remember that the index of the first element in an array is zero (not
one).
B. freeSeat(): This method takes exactly the same parameters as the method
reserveSeat(), but does just the opposite. It puts the character given by
parameter col at the slot (in 2D array) that represents the seat specified by the
parameters row and col. For example, if row is 2 and col is ‘A’, this method
replaces the content of seats[1][0] by the character ‘A’.
C. getNumberOfSeatsAvailable(): Counts and returns the number of available
(i.e. unassigned) seats. The method returns an integer.
D. displaySeats(): Displays seats in the format shown in output.
Desired output:
1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D
8 A B C D
32
29
1 A B C D
2 A B X X
3 A B C D
4 A B C D
5 A B C D
6 A X C D
7 A B C D
8 A B C D
30
1 A B C D
2 A B C X
3 A B C D
4 A B C D
5 A B C D
6 A X C D
7 A B C D
8 A B C D
You must SUBMIT your version AirplaneSeatReservation.java of containing all
necessary changes.

Reviews

There are no reviews yet.

Be the first to review “CS2230: Data Structures Homework 1”

Your email address will not be published.