8000 GitHub - sst19881025/kwic: softengineering_kwic
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

sst19881025/kwic

Folders and files

NameName< 8000 /span>
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

變更如下:
//----------------------------------------------------------------------
/**
 * KWIC.java
 *
 * Parses the data, makes shifts and sorts them. At the end prints the
 * sorted shifts.
 * @param file name of the input file
 */

  public void execute(String file){
    LineStorage lines = new LineStorage();
    Input input = new Input();
    CircularShifter shifter = new CircularShifter();
    Alphabetizer alphabetizer = new Alphabetizer();
    Output output = new Output();
    ChatMode chatmode =new ChatMode();

    chatmode.write(file);
    input.parse(file, lines);
    shifter.setup(lines);
    alphabetizer.alpha(shifter);
    output.print(alphabetizer);
  }

/**
 * Main function checks the command line arguments. The program expects 
 * exactly one command line argument specifying the name of the file 
 * that contains the data. If the program has not been started with 
 * proper command line arguments, main function exits
 * with an error message. Otherwise, a KWIC instance is created and program
 * control is passed to it.
 * @param args command line arguments
 */

  public static void main(String[] args){
	String input ="./input/data.txt";
    KWIC kwic = new KWIC();
    kwic.execute(input);
  }

//----------------------------------------------------------------------
/**
 * Write a new class
 *
 * ChatMode.java
 *
 * Use the chatting mode to get inputs.
 * Get the results in the terminal.
 */

package kwic.oo;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;

public class ChatMode {
	public void write(String file){
		try {
			InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br=new BufferedReader(isr);
			FileWriter fw =new FileWriter(file);
			BufferedWriter bw = new BufferedWriter(fw);
            boolean go_on = true;
            while (go_on) {
	            System.out.print("Add, Print, Quit:");
	            char c = br.readLine().charAt(0);
	            if (c =='a' || c == 'A') {
	            	String content = br.readLine();
	            	System.out.println("");
	    			bw.write(content);
	    			bw.newLine();
	            } else if (c =='p' || c =='P') {
	            	go_on = false;
	            } else if (c =='q' || c =='Q') {
	            	System.exit(0);
	            } else {
	            	System.out.println("Please input the right char.");
	            }
            }
            bw.flush();
            bw.close();
            fw.close();
            br.close();
            
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}


//----------------------------------------------------------------------
/* Process & Result is shown bellow:
 */
	Add, Print, Quit:a
	The Empire Strikes Back

	Add, Print, Quit:Add
	The Return of the Jedi

	Add, Print, Quit:p
	Back The Empire Strikes

	Empire Strikes Back The
	Jedi The Return of the
	Return of the Jedi The
	Strikes Back The Empire
	The Empire Strikes Back
	The Return of the Jedi
	of the Jedi The Return
	the Jedi The Return of

//----------------------------------------------------------------

About

softengineering_kwic

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0