I'm in a high school Computer Science class. We are currently working on Java console applications.
Our final assignment was to write a program that has three options:
Store Information
Search and Read Information
Quit Program
I finished early as usual. It works but i want to know if i have any WTF's in my code.
import java.io.*;
public class FinalCS {
public static void main (String[] args) throws IOException
{
String Query = "";
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
QueryLoop:
while(!(Query.equals("QUIT")))
{
System.out.println("\nCHOOSE FROM THESE OPTIONS:\n| ENTER | SEARCH | QUIT |");
Query = in.readLine().toUpperCase();
if(Query.equals("ENTER"))
{
EnterStuff();
continue QueryLoop;
}
else if(Query.equals("SEARCH"))
{
SearchStuff();
continue QueryLoop;
}
else if(Query.equals("QUIT"))
{
}
else
{
System.out.println("INVALID SELECTION.\n");
}
}
System.out.println("END OF LINE.");
}
public static void EnterStuff()throws IOException
{
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
System.out.println("ENTER NAME(LAST, FIRST):");
String Name = in.readLine();
System.out.println("ENTER ADDRESS:");
String Address = in.readLine();
System.out.println("ENTER JOB:");
String Job = in.readLine();
System.out.println("ENTER MATERIAL COST:");
double MatCost = Double.parseDouble(in.readLine());
System.out.println("ENTER LABOR COST:");
double LabCost = Double.parseDouble(in.readLine());
double TotalCost = (MatCost*1.0825)+LabCost;
try
{
FileOutputStream fout;
fout = new FileOutputStream (Name + ".txt");
new PrintStream(fout).println ("NAME: "+ Name + ";" + "ADDRESS: " + Address + ";" + "JOB: " + Job + ";" + "MATERIAL COST:" + MatCost + ";" + "LABOR COST: " + LabCost + ";" + "TOTAL COST: " + TotalCost);
fout.close();
System.out.println("\nINFORMATION STORED.\n");
}
catch(IOException e)
{
System.out.println("\nCOULD NOT STORE INFORMATION.\n");
}
}
public static void SearchStuff()throws IOException
{
InputStreamReader converter = new InputStreamReader(System.in);
BufferedReader in = new BufferedReader(converter);
System.out.println("\nENTER NAME OF CLIENT. (LAST, FIRST)");
String Name = in.readLine();
try
{
FileInputStream fin;
fin = new FileInputStream (Name + ".txt");
String Info = new DataInputStream(fin).readLine();
int count = 0;
char separator = ';';
int index=0;
do
{
++count;
++index;
index=Info.indexOf(separator, index);
}
while (index!=-1);
String[] subStr=new String[count];
index=0;
int endIndex = 0;
for (int i=0; i<count; i++)
{
endIndex=Info.indexOf(separator, index);
if (endIndex==-1)
subStr[i]=Info.substring(index);
else
subStr[i]=Info.substring(index,endIndex);
index=endIndex+1;
}
for (int i=0; i<subStr.length; i++)
System.out.print(subStr[i] + "\n");
fin.close();
}
catch(IOException e)
{
System.out.println("\nCOULD NOT LOCATE CLIENT.\n");
}
}
}
Strong critiques are very much accepted. I want to major in CS so all help is appreciated.