I am working on a program that reads a text file that holds an entire dictionary and will take the word, pronunciation, and definition and add it to an AVL tree. I am working on the loop that reads through the .txt file and stores the different things(word, definition, ...) into strings. Whenever the loop runs, it adds an extra enter in the definition string. This is my Code:
package text;
import java.util.*;
import java.io.*;
public class Text {
public static void main(String args[]) throws IOException{
File file = new File(args[0]);
Scanner scanner = new Scanner(file);
int cap = 0, proLine = 0;
String word="", pro="",def="";
String strLine;
while (scanner.hasNext()){
strLine = scanner.nextLine();
if(isCaps(strLine))
cap++; proLine = 1;
if((isCaps(strLine)) && cap == 1)
word = strLine;
if(proLine == 1 && cap ==1)
pro = strLine;
if(isDefn(strLine)){
def = strLine;
}
if(cap == 2){
System.out.println(word+"\n"+pro+"\n"+def);
cap = 0;
proLine = 0;
}
}
}
private static boolean isCaps(String str){return (str.equals(str.toUpperCase()));}
private static boolean isDefn(String str){return str.contains("Defn");}
}
This is the text file i have been using
"ABAFT
A*baft", adv. (Naut.)
Defn: Toward the stern; aft; as, to go abaft.
ABAISANCE
A*bai"sance, n. Etym: [For obeisance; confused with F. abaisser, E. abase]
Defn: Obeisance. [Obs.] Jonson."