Write a static method named " compareLines " that accepts one parameter ( a Scanner attached to an input file ). Your method should compare each neighboring pair of lines (the 1st and 2nd lines, then...


Write a static method named "compareLines" that accepts one parameter (a Scanner attached to an input file). Your method should compare each neighboring pair of lines (the 1st and 2nd lines, then the 3rd and 4th lines, and so on) looking for indexes in both strings that contain vowels [a, e, i, o, u, y, A, E, I, O, U, Y] and should output the index where both strings contained a vowel.


For example, in the strings "hello" and "bully, the characters at indexes 1 and 4 match since both contain vowels at that index.


For each pair of lines, your method should print output showing the character indexes that match, separated by spaces in the format shown below.  If no characters match, print "none" instead as shown below.


For example, suppose the input file contains the following text.
(Line numbers and character indexes are shown around the input and matching characters are shown in bold, but these markings do not appear in the actual file.)



0123456789012345678901234567890123456789 (String index)


The quick brown fox
Thoseachy down socks
Wheelson the school bus go round
The wipers go swish swish swish
This name is Robert Peltson
So long ‘n thanks for all the fish
Humpty Dumpty satona wall
and then healso hada great fall


When passed the above file, your method would produce the following output:

lines 1 and 2: 2 6 12 17


lines 3 and 4: 2 7 12 22
lines 5 and 6: none
lines 7 and 8: 12 15 18 21


Notice that lines are not generally the same length.
You may assume that the file contains an even number of lines.


import java.util.*;
import java.io.*;
public class MatchIndex {

  public static void main(String[] args) throws FileNotFoundException {
    Scanner fileIn = new Scanner(new File("test.txt"));
    compareLines(fileIn);
  }
      // *** Your method code goes here ***


} // End of MatchIndex class


Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here