Write a static method named matchIndex that accepts as its parameter a Scanner for an input file. Your method should compare the first line of the file (target line) to every other line in the file looking for places where the character at a given 0- based index from the two lines is the same. For example, in the strings "hello" and "belt", the characters at indexes 1 ('e') and 2 (I') match. Your code should be case-sensitive; for example, "J" does not match "j". 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 1 This is the target line for comparison 2 Those achy down socks 3 Wheels on the school bus go round 4 The wipers go swish swish swish 5 His name is Robert Paulson 6 so long 'n thanks for all the fish 7 Humpty Dumpty sat on a wall 8 And then he also had a great fall 9 booyakasha 10 Bruno Ali G Borat When passed the above file, your method would produce the following output: target and 2: 0 1 3 target and 3: 1 19 27 29 target and 4: 0 1 5 target and 5: 11 17 18 target and 6: 7 13 target and 7: none target and 8: 9 10 11 target and 9: none target and 10: 11 14 Notice that lines are not generally the same length. You may assume that the file contains at least 1 line.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Write a static method named matchIndex that accepts as its parameter a Scanner for an input file. Your method should
compare the first line of the file (target line) to every other line in the file looking for places where the character at a given 0-
based index from the two lines is the same. For example, in the strings "hello" and "belt", the characters at indexes 1 ('e')
and 2 (I') match. Your code should be case-sensitive; for example, "J" does not match "j".
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 matehing characters are shown in bold, but these markings do not appear in the actual file.)
0123456789012345678901234567890123456789
This is the target line for comparison
2 Those achy down socks
3 Wheels on the school bus go round
4 The wipers go swish swish swish
5 His name is Robert Paulson
6 So long 'n thanks for all the fish
7 Humpty Dumpty sat on a wall
8 And then he also had a great fall
9 booyakasha
10 Bruno Ali G Borat
1
When passed the above file, your method would produce the following output:
target and 2: 0 1 3
target and 3: 1 19 27 29
target and 4: 0 1 5
target and 5: 11 17 18
target and 6: 7 13
target and 7: none
target and 8: 9 10 11
target and 9: none
target and 10: 11 14
Notice that lines are not generally the same length. You may assume that the file contains at least 1 line.
Transcribed Image Text:Write a static method named matchIndex that accepts as its parameter a Scanner for an input file. Your method should compare the first line of the file (target line) to every other line in the file looking for places where the character at a given 0- based index from the two lines is the same. For example, in the strings "hello" and "belt", the characters at indexes 1 ('e') and 2 (I') match. Your code should be case-sensitive; for example, "J" does not match "j". 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 matehing characters are shown in bold, but these markings do not appear in the actual file.) 0123456789012345678901234567890123456789 This is the target line for comparison 2 Those achy down socks 3 Wheels on the school bus go round 4 The wipers go swish swish swish 5 His name is Robert Paulson 6 So long 'n thanks for all the fish 7 Humpty Dumpty sat on a wall 8 And then he also had a great fall 9 booyakasha 10 Bruno Ali G Borat 1 When passed the above file, your method would produce the following output: target and 2: 0 1 3 target and 3: 1 19 27 29 target and 4: 0 1 5 target and 5: 11 17 18 target and 6: 7 13 target and 7: none target and 8: 9 10 11 target and 9: none target and 10: 11 14 Notice that lines are not generally the same length. You may assume that the file contains at least 1 line.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Constants and Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education