lab2soln - 1. After using filescan.next() to read the first...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
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));
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

lab2soln - 1. After using filescan.next() to read the first...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online