I have been working on and off of this, and I have run into a bit of a problem. I want a command "exit()" or close out of the program. It just seems more elegant than the little "x" in the terminal / command prompt window. I did this by having two loops: One that continues as long as a boolean "isRunning" is true and one that runs forever. When the user inputs "exit()", it calls a function that sets isRunning to false and then breaks the second loop. I gets the job done, but I feel like there should be a more elegant way to do this.
I also added support for an ini file. I focused more on making it work, so I ended up downloading a library off of the Internet because the syntax was a lot simpler than the walls of jargon I found on other sites. In retrospect, this seems like bad practice.
So right now I have two concerns: 'Proper' INI management and an elegant way to exit the program.
Verb.java
Spoiler
Code:
/*
* TODO:
* -- passe compose and aux. verb
* - etre is irregular, so default to avoir
* -- check on startup for verb_list.ini
* - if it exist, yey.
* - if not, make it and complain.
*
*/
/* Search the file for verbInfinitive,verbTense
* If found, locate objPronoun and use objPronoun's verb form
* If either search fails, default to regular conjugation
* VVVVVVVV
*/
IniEditor verbList = new IniEditor();
try {
verbList.load("verb_list.ini");
} catch (IOException e) {
return "\n**There was a problem loading verb_list.ini. Are you sure it exist?**";
}
public static void main( String args[]){
StartUp();
while(isRunning){
for(;;){
Scanner input = new Scanner(System.in);
String in = input.nextLine();
String infinitive = in.split(" ")[0];
if (infinitive.length() < 2){ // If infinitive is too short, demand another one
break;
}
if (in.equals("exit()")){
Exit();
break;
}
String tense = "present"; // If no tense is entered, default to present
if (in.split(" ").length >= 2){
tense = in.split(" ")[1];
}
Verb MyVerb = new Verb(infinitive);
for (int i = 0; i < 6; i++) {
System.out.println(MyVerb.getPronoun(i) + " " + MyVerb.conjugate(i, tense));
}
System.out.println(""); //spacer after each verb to make the output more readable
System.out.print("Ready for another verb. Remember the format is <verb> <tense>\n");
}
if (isRunning) {
System.out.print("Your verb is too short. Please try again:\n");
}
}
}
private static void StartUp(){
/* Check if file "verbs.ini" exist
* If false create it and fill with some sample verbs
*/
System.out.print(
"~~~~~~~~~~~~~~~~~~~~~~~~~~~" +
"Verb Conjugating Program" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n" +
"Please enter verbs in the following format:\n" +
"\t<infinitive> <tense>\n" +
"Examples:\n" +
"\tparler\n" +
"\tetre imperfect\n" +
"If you do not enter a tense, the present will be used.\n" +
"\tSupported tenses: present and imperfect\n\n" +
"Enter your verb:\n");
}
private static void Exit(){
System.out.print("Goodbye. :(\n");
isRunning = false;
}
}