1. After using filescan.next() to read the first integer in the file, you
should use filescan.nextLine() to read the rest of the line and
the end of line character.
As nextInt() reads an integer up to the first whitespace character,
the nextLine() following it will include that whitespace character. The
substring(1) drops that first whitespace character from the channel
name.
2.
/**
* Searches the cable system for the channel number
* given the channel name using linear search. Outputs
* the number of channels examined.
*
* Precondition: Channel names are sorted in channelArray in increasing order.
*
* @param channelName the name of the channel desired
* @return the number of the channel if the cable system has the channel name,
*
-1 otherwise
*/
public int search1(String channelName) {
for (int i = 0; i < numChannels; i++) {
int ordering = channelName.compareTo(channelArray[i].getName());
if (ordering == 0) {
// Found the channel name, return the number
System.out.println("Number of array cells examined: " + (i+1));
return channelArray[i].getNumber();
}
else if (ordering < 0) {
This
preview
has intentionally blurred sections.
Sign up to view the full version.

This is the end of the preview.
Sign up
to
access the rest of the document.
- Spring '09
- Reid-Miller
- Whitespace, array cells
-
Click to edit the document details