Skip to content

Instantly share code, notes, and snippets.

@anchetaWern
Created December 18, 2016 15:46
Show Gist options
  • Save anchetaWern/0301f10150021e3c56f0578ab471f7d3 to your computer and use it in GitHub Desktop.
Save anchetaWern/0301f10150021e3c56f0578ab471f7d3 to your computer and use it in GitHub Desktop.
TPL final act
package activity;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.logging.Level;
/**
*
* @author wernancheta
*/
public class Activity {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
File words_file = new File("./files/words.txt");
File syn_file = new File("./files/synonyms.txt");
FileReader fr;
FileReader fr2;
Scanner input = new Scanner(System.in);
String words[][] = new String[5][3];
int choice;
int index = 0;
try {
fr = new FileReader(words_file);
fr2 = new FileReader(syn_file);
BufferedReader br = new BufferedReader(fr);
BufferedReader br2 = new BufferedReader(fr2);
try {
for(String data = br.readLine(); data != null; data = br.readLine()){
words[index][0] = data;
index++;
}
} catch (IOException ex) {
System.out.println("io exception");
}
index = 0;
try {
for(String data2 = br2.readLine(); data2 != null; data2 = br2.readLine()){
words[index][1] = data2;
index++;
}
} catch (IOException ex) {
System.out.println("io exception");
}
} catch (FileNotFoundException ex) {
System.out.println("file not found");
}
do {
int count = 1;
for(int x = 0; x < words.length; x++){
System.out.println(count + ". " + words[x][0]);
count++;
}
System.out.println();
System.out.print("Select a word (number only): ");
choice = input.nextInt();
if(choice > 5 || choice < 1){
System.out.println("Invalid Input");
}else{
System.out.println();
System.out.println(choice + "." + words[choice - 1][0]);
System.out.println("Synonyms:");
//System.out.print("\t");
//System.out.println(words[choice - 1][1].replace(", ", "\n\t"));
String first = words[choice - 1][1].substring(0, words[choice - 1][1].indexOf(","));
String sec = words[choice - 1][1].substring(words[choice - 1][1].indexOf(",") + 2, words[choice - 1][1].lastIndexOf(","));
String third = words[choice - 1][1].substring(words[choice - 1][1].lastIndexOf(",") + 2);
System.out.println("\t1. " + first);
System.out.println("\t2. " + sec);
System.out.println("\t3. " + third);
System.out.println("============================");
}
} while (true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment