CISC 1115
Introduction to Modern Programming Techniques
Lab #00
Review

How to Develop and Submit your Labs

All the exercises in this Lab are marked for Approval because:

Lab 0.1 (Lab 6.6 in the 1115 labs) — Fun with Numbers (InfoOf3) (Approval)

Write a program that reads three numbers from the keyboard, and then prints out some information about the relationships between the numbers-- whether they are all equal, in ascending order, in descending order, and so on. To determine these relationships, you must use the following boolean-valued methods: Try to "talk boolean" — i.e., use boolean variables and conditional operators rather than if statements where possible

Sample Test Run

first number? 1
second number? 2
third number? 3
allAreEqual: false
twoAreEqual: false
noneAreEqual: true
areAscending: true
areDescending: false
strictlyAscending: true
strictlyDescending: false

Lab 0.2 (Lab 9.5 in the 1115 labs) — Calculating Averages (Averages) (Approval)

The file numbers.text consists of sequences of numbers, each sequence preceded by a header value nd then followed by that many integers. Read in the sequences and print their averages. When all sequences have been read in, print out the number of sequences processed. You should not rely on the numbers in each sequence all being on the same line; i.e., do not use nextLine for your input>. You should also not be using an array.

Sample Test Run

For example if the file numbers.text contains:

3 1 2 3
5 12 14 6 
	4 0
10 1 2 3 4 5 
    6 7 8 9 10
1 17
2 90 80
the program should produce the following output:
The average of the 3 integers 1 2 3 is 2.0
The average of the 5 integers 12 14 6 4 0 is 7.2
The average of the 10 integers 1 2 3 4 5 6 7 8 9 10 is 5.5
The average of the 1 integers 17 is 17.0
The average of the 2 integers 90 80 is 85.0
5 sets of numbers processed

Lab 0.3 (Lab 10.4 in the 1115 labs) — Finding the Last Occurrence of a Value in a File (FindLast) (Approval)

Write a program that prompts the user (at the keyboard)for a value and searches the file numbers.text for that value, printing out the last position where the number appears in the file (the first number in the file is at position 1). If the number does not appear in the file, print out an appropriate message. Continue asking the user for values until they signal end-of-file (i.e., in Windows one enters end-of-file at the keyboard by entering Ctl-Z, in Unix end-of-file is indicated by entering Ctl-D). The logic is the same as end-of-file for a disk file-- i.e., if your Scanner variable is named 'keyboard', you would have the loop condition 'while (keyboard.hasNextInt())'.

You may not use an array or any other data structure.

Sample Test Run

For example if the file numbers.text contains:

10
23
43
5
12
23
9
8
10
1
16
9
execution of the program should look like:

Enter a number: 10
10 last appears in the file at position 9
Enter a number: 29
29 does not appear in the file
Enter a number: 9
9 last appears in the file at position 12
Enter a number:

Some Guidance and Notes

Lab 0.4 (Lab 12.1 in the 1115 labs) — Array Information (ArrayInfo) (Approval)

The file numbers.text contains a header value, followed by that many double values. Create an array of the appropriate size, populate the array with the doubles, and print out various information about the array (see below).

Sample Test Run

For example if the file numbers.text contains:

8
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 8 elements
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
The largest element of the array is 54.3 and is at position 6
The smallest element of the array is 2.5 and is at position 1
Notes:

Lab 0.5 (Lab 15.1 in the 1115 labs) — Sorting Parallel Arrays Information (ParellelArraysSort) (Approval)

Given the file roster.text, containing pairs of ids (integers) and gpa's (doubles), read the file into a pair of arrays, and perform two sorts on them, the first by name in ascending order, the second by gpa in descending order. Print out the original and sorted arrays.

Suggested Methods

While you are free to code this lab as you wish, I would recommend the following methods:
  • The usual read method … accepts either the filename or a Scanner object created by main, together with the arrays and the capacity. The method loads up the arrays returns the number of entries read in.
  • Two sort methods, both accepting the two arrays and numbers of entries in the arrays (size). Since the two methods have the exact same signature, they cannot be overload (i.e., use the exact same name) … I used the named sortById and sortByGPA
  • swap accepts an array and a pair of indexes and swaps the values at those two indices (look at Lecture 12 for details on swapping elements of an array). You need two of these methods, one for swapping the elements of the id (int) array and the other for the gpa (double) array. Since these two methods will have different signatures (i.e., their paraeter lists are not identcal), you can use the same name for both (I used swap).
  • print accepting bot arrays and the size and prints them out in the appropriate manner
  • Other Suggestions

    Sample Test Run

    For example if the file roster.text contains:

    10050	3.1
    10721	2.3
    10010	3.7
    30921	2.5
    23462	4.0
    12345	2.9
    
    the program should produce the following output:
    Original data:
    10050: 3.1
    10721: 2.3
    10010: 3.7
    30921: 2.5
    23462: 4.0
    12345: 2.9
    
    Sorted by Id:
    10010: 3.7
    10050: 3.1
    10721: 2.3
    12345: 2.9
    23462: 4.0
    30921: 2.5
    
    Reverse Sorted by GPA:
    23462: 4.0
    10010: 3.7
    10050: 3.1
    12345: 2.9
    30921: 2.5
    10721: 2.3