COMP130 – Characters in a String Solved

$ 29.99
Category:

Description

Your task is to implement a program that finds the indexes of given character(s) in sentences which are read from a file.

1. Reading from a file (10 points)
The program should read in sentences from a text file. The name of the file is provided in the code.
2. Asking characters to search (30 points)
The program should ask the user to enter characters to search in a sentence. The program shall allow user to enter a character until a null value is entered.
3. Find the index of the characters (60 points)
The program shall find the indexes of all the given characters in the sentences and prints the result to console. If a character does not exist in the sentence, this should also be stated.
Here is a sample outcome of your program. Please note that the program should NOT be limited to this sample:

4. Writing to a file (Bonus question) – 10 points
The program shall print the sentences read from the file and the characters read from the user and prints the indexes of the characters in the sentence. The contents of the file should look similar to the output in the console. The name of the output file is provided in the code.

1

5. Editing of the Code
You should modify the code provided to you and only fill the regions between //Your
code starts here and //Your code ends here.

The code requires you use ArrayList for storing the sentences read from the input file. It requires you to implement the following methods:
• public void readFile () – the method read the sentences from an input file.
• public void askUserInputAndFindChar () – the method asks user to enter characters to search and finds the index numbers.

Feel free to implement other helper methods and instance variables. However, you should not replace the variables and methods provided to you.

6. Warnings:
• Write your name at the top of your *.java file.
• Don’t’ move the downloaded file to another location.
• Import Comp130-Libs and the exam *.java into Eclipse and update code accordingly.
• Write comments to explain your code.
• Pay attention to indentations and spacing in your code.

2

Reviews

There are no reviews yet.

Be the first to review “COMP130 – Characters in a String Solved”

Your email address will not be published. Required fields are marked *