-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab 5 - Word in File
43 lines (34 loc) · 1.51 KB
/
Lab 5 - Word in File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//An expansion of Lab 4, this compares words on a file to the words in wordArray
import javax.swing.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.FileInputStream;
import java.io.IOException;
public class Lab5 {
public static void main(String[] args) throws IOException{
String[] wordArray = {"hello", "goodbye", "cat", "dog", "red", "green", "sun", "moon"};
String isOrIsNot, inputWord;
//Read file input
BufferedReader br= new BufferedReader(new InputStreamReader(new FileInputStream(args[0])));
String line = br.readLine();
System.out.println(line);
while (true){
inputWord = JOptionPane.showInputDialog(null, "Enter a word in all lower case:");
if(wordIsThere(inputWord, wordArray))
isOrIsNot = "is";
else
isOrIsNot= "is not";
JOptionPane.showMessageDialog(null, "the word " + inputWord + " " + isOrIsNot + " on the list");
}
}
public TextFileInput (String filename, String[] array){
while (i = 0; i < array.length(); i++) {}
}
public static boolean wordIsThere(String findMe, String[] theList){
if(findMe.equals("STOP")) System.exit(0);
for (int i = 0; i < 8; i++){
if (findMe.equals(theList[i])) return true;
}
return false;
}
}