Topic: 求助,不会写这个程序 |
Print this page |
1.求助,不会写这个程序 | Copy to clipboard |
Posted by: czboycool Posted on: 2004-12-16 01:07 老外给的题目,不知道如何下手,谁能帮忙 Overview Write a program named SearchTextA to search for a multiple occurrences of a string in a document provided by the DocumentA class (described in the section Document Object). The text to search for will be passed as a command line parameter. The program should output the text that will be searched for, and the line number and offset of each occurrence found. The output should follow strict format guidelines as described under Output below. A test case consisting of 3 files input.txt, output.txt, and search.txt should be submitted. The content of the files should should satisfy certain criteria as described under Test Case. A sample test case is shown under Sample Input/Output. Document Object The DocumentA.class is provided to you. Put the class file in the same directory as your source file when you compile. The DocumentA constructor requires a string representing a valid filename. The DocumentA class has 2 public methods: boolean hasNext() and String next(). hasNext() returns a boolean indicating if there are more lines of the file to be read. next() returns the next line of the file as a string without line termination. You should always call hasNext() before calling next(). Command Line Parameters The program should accept two command line parameters. The first parameter should be a valid filename of the file to be searched. The second parameter will be the text to search for. Delimit this string with quotes (") if there are spaces or special characters in the string. If 2 parameters are not present, print out a message to System.err and return. Program Logic The program should create a DocumentA object using the filename passed as an argument. It should then retrieve lines of text from the document using the hasNext() and next() methods. Search each line retrieved for the search text. Different occurrences of the search text will not overlap. There might be several occurrences on one line. The occurrences may be adjacent to each other. Output Before searching begins, the program should output the string to be searched for on a line by itself to System.out using the following format: "Searching for 'string':", where string is the search text. For each match found in the document, the program should output an additional line with the following format: "Found at line n, position i", where n is the line number (starting from 1) and i is the character position (0 based). If no match is found in the document, print out "Not Found". |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |