All pastes #799569 Raw Edit

Mine

public java v1 · immutable
#799569 ·published 2007-11-27 19:05 UTC
rendered paste body
/** Class				oppgave1a* By				Rune Vikestad* E-Mail			vikestad@stud.ntnu.no* Web				http://folk.ntnu.no/vikestad/* Description		IT-1103, Basic Programming (Java), Exercise 6*/import java.io.*;import java.util.*;import javax.swing.JOptionPane;/*** Class: 'oppgave1b'*/public class oppgave1b {	/**	* Method: 'main'.	*/	public static void main(String[] args) throws IOException {		/*		* Variable Declarations		*/		FileReader fr;		FileWriter fw;		PrintWriter pw;		String fileInName;			// The name of the file we read from		String fileOutName;			// The name of the file we write to		int charCode;				// The decimal value of a character read		char wordPart;				// The alphanumeric value of a character read.		String wordTemp = "";		// The temporary string used to store words, before they're processed into an array.		int counter = 0;			// We use this integer to count how many words we've read, for the array.		String[] wordArray;			// Our words, in an array.		boolean wordExists;		/*		* Variable Initiations		*/		fileInName = JOptionPane.showInputDialog("File name: ");		fileOutName = JOptionPane.showInputDialog("File name (Output): ");		fr = new FileReader(fileInName);		fw = new FileWriter(fileOutName);		pw = new PrintWriter(fw);		wordArray = new String[100];		wordExists = false;		/*		* Process our stream.		*/		do {			charCode = fr.read();			/* If character isn't a Comma, Period, Space or EOF. */			if (charCode != 46 && charCode != 44 && charCode != 32 && charCode != -1) {				if (charCode >= 65 && charCode < 97) {					/* Found an upper case character, so make it lower case. */					charCode = charCode + 32;				}				/* Insert the character into our temporary word */				wordPart = (char)charCode;				wordTemp = wordTemp + wordPart;			}			if (charCode == 32) {				/* We found a space, which means we've got a word. */				System.out.println(counter);				for (int i=0;i<counter;i++) {					/* Check if the word we found, exists in our array. */					if (wordArray[i] == wordTemp) {						wordExists = true;					}				}				if (wordExists == false) {					wordArray[counter] = wordTemp;					System.out.println(wordArray[counter]);		// Print to screen.					pw.println(wordArray[counter]);				// Print to file.					wordTemp = "";					counter = counter+1;				} else if (wordExists == true) {					System.out.println("FOUND A WORD THAT EXISTS\n");				}			} else if (charCode == -1) {				/* We found the EOF, print the last word. */				wordArray[counter] = wordTemp;				System.out.println(wordArray[counter]);		// Print to screen.				pw.println(wordArray[counter]);				// Print to file.				wordTemp = "";				counter = counter+1;			}		} while (charCode > 0);		fr.close();		fw.close();		pw.close();		System.exit(0);	}}