CISC 1115
Introduction to Programming Using Java
Lab #14
Techniques IV — Partially-Populated Arrays, Vectors, Parallel Arrays, Subarrays

How to Develop and Submit your Labs

Lab 14.1 — Almost a Vector (AlmostAVector) Approval

Create an array and populate it with integers read in from the file numbers.text, then print out various items of information about the array (see below). You should assume a maximum of 100 numbers.

Sample Test Run

For example if the file numbers.text contains:

12.3
2.5
9.4
3.14
22.15
17
54.3
7.6
the program should produce the following output:
The array: {12.3, 2.5, 9.4, 3.14, 22.15, 17.0, 54.3, 7.6} contains 100 elements of which 8 elements are being used
The first element of the array is 12.3
The last element of the array is 7.6 and is at position 7
The middle element of the array is 3.14 and is at position 3
There are 92 empty elements in the array
Notes:

Lab 14.2 — A Partially Populated Array (PartiallyPopulated Array) Approval

The file flight_manifest contains names of passengers preceded by the class they are flying (first, business or econom — see below for the exact format). Write a program that reads in the data — a line at a time (using nextLine — and prints out the passengers by class. You should assume a maximum of 100 passengers.

Sample Test Run

For example if the file flight_manifest contains:

Business class: Bill Gates
Economy: Gerald Weiss
Economy: David Arnow
First class: Warren Buffet
Business class: Paula Whitlock 
First class: Jim Cox
Economy: Dina Sokol
the program should produce the following output:
First class: Warren Buffet
First class: Jim Cox

Business class: Bill Gates
Business class: Paula Whitlock 

Economy: Gerald Weiss
Economy: David Arnow
Economy: Dina Sokol
Notes:

Lab 14.3 — Parallel Arrays (ParallelArrays)

For the purpose of this exercise, we introduce the notion of aligning pairs of numbers (this is not a standard term, I made it up for this exercise). Given a sequence of pairs of numbers, 'aligning' consists of making all the pairs of numbers go in the same direction, i.e., either all the pairs have the first number less than the second or vice-versa. Write a program to read in pairs of numbers from the file numbers.text, and aligns them (my term) before writing them out to the file aligned_pairs.text. If the pairs read in contains more pairs in which the first number is less than the second, then the pairs should aligned with first < second; otherwise they should be paired using first > second.

Sample Test Run #1

If the file numbers.text contains:

1  	4
10 	5
12	14
22	27
25	10
then after program execution, the file aligned_pairs.text should contain the following:
1 4
5 10
12 14
22 27
10 25
since there are 3 pairs ((1, 4), (12, 14), and (22, 27)) in which the first number is less than the second, while there are only two pairs ((10, 5) and (25, 10)) in which the first number is greater than the second number.

Sample Test Run #2

If the file numbers.text contains:

3	2
6	7
9	6
then after program execution, the file aligned_pairs.text should contain the following:
3 2
7 6
9 6
since there are 2 pairs ((3, 2) and (9, 6)) in which the first number is greater than the second, while there is only one pair ((6, 7)) in which the first number is less than the second number. Notes:

Lab 14.4 — Printing Subarrays (Subarray)

The file numbers.text contains a header value followed by the corresponding number of integers. Read the values int an array and print out the a sequence of subarrays, with the first subarray consisting of the entire array, the second consisting of the second to next to last element, the third consisiting of the thitd to third from last element, and so on, until a subarray of size one or two is printed.

Sample Test Run

For example if the file numbers.text contains:

7
12
41
26
77
11
19
44
the program should produce the following output:
{12, 41, 26, 77, 11, 19, 44}
{... 41, 26, 77, 11, 19 ...}
{... 26, 77, 11 ...}
{... 77 ...}
Notes:

Lab 14.5 — Printing Subarrays — Take 2 (Subarrays) (Optional)

The same basic specs as Lab 14.4, but with additional subarray patterns printed out:

Sample Test Run

For example if the file numbers.text contains:

7
12
41
26
77
11
19
44
the program should produce the following output:
{12, 41, 26, 77, 11, 19, 44}

{12 ...}
{12, 41 ...}
{12, 41, 26 ...}
{12, 41, 26, 77 ...}
{12, 41, 26, 77, 11 ...}
{12, 41, 26, 77, 11, 19 ...}
{12, 41, 26, 77, 11, 19, 44}

{... 44}
{... 19, 44}
{... 11, 19, 44}
{... 77, 11, 19, 44}
{... 26, 77, 11, 19, 44}
{... 41, 26, 77, 11, 19, 44}
{12, 41, 26, 77, 11, 19, 44}

{12 ...}
{... 41 ...}
{... 26 ...}
{... 77 ...}
{... 11 ...}
{... 19 ...}
{... 44}

{12, 41 ...}
{... 41, 26 ...}
{... 26, 77 ...}
{... 77, 11 ...}
{... 11, 19 ...}
{... 19, 44}

{12, 41, 26 ...}
{... 41, 26, 77 ...}
{... 26, 77, 11 ...}
{... 77, 11, 19 ...}
{... 11, 19, 44}

{12, 41, 26, 77 ...}
{... 41, 26, 77, 11 ...}
{... 26, 77, 11, 19 ...}
{... 77, 11, 19, 44}

{12, 41, 26, 77, 11 ...}
{... 41, 26, 77, 11, 19 ...}
{... 26, 77, 11, 19, 44}

{12, 41, 26, 77, 11, 19 ...}
{... 41, 26, 77, 11, 19, 44}

{12, 41, 26, 77, 11, 19, 44}

{12, 41, 26, 77, 11, 19, 44}
{... 41, 26, 77, 11, 19 ...}
{... 26, 77, 11 ...}
{... 77 ...}
Notes: