//Mason Marnell
//DatabaseProject class
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class DatabaseProject {
static ArrayList LoricArray = new ArrayList<Loric>();
public static void readInList() throws Exception{
Scanner file = new Scanner(new File("./src/listofcharacters"));
while(file.hasNextLine()){
String line = file.nextLine();
String Splitline[] = line.split(",");
int num = Integer.parseInt(Splitline[0]);
String name = Splitline[1];
String leg1 = Splitline[2];
String leg2 = Splitline[3];
Loric temp = new Loric(num,name,leg1,leg2);
System.out.println(temp);
LoricArray.add(temp);
}
System.out.println("Done reading in file.");
}
public static void Save() throws Exception{
PrintWriter output = new PrintWriter(new FileWriter("./src/listofcharacters"));
for (int i = 0; i < LoricArray.size(); i++) {
output.println(LoricArray.get(i));
}
System.out.println("File saved.");
output.close();
}
public static void mainMenu() throws Exception{
String choice = "";
while(! choice.equals("X")){
String menu = "Main Menu \n"
+ "A: Read in Data \n"
+ "B: Display Menu \n"
+ "C: Search Menu \n"
+ "D: Sort Menu \n"
+ "E: Add and Delete \n"
+ "F: Save \n"
+ "X: Exit";
choice = JOptionPane.showInputDialog(menu);
if(choice.equals("A"))
readInList();
if(choice.equals("B"))
DisplayMenu();
if(choice.equals("C"))
SearchMenu();
if(choice.equals("D"))
SortMenu();
if(choice.equals("E"))
AddAndDelete();
if(choice.equals("F"))
Save();
}
}
public static void DisplayMenu() throws Exception{
String choice = "";
String menu = "Display Menu \n"
+ "A: Number Legacy 1 Legacy 2 \n"
+ "B: Number Name Legacy 1 \n"
+ "C: Name Legacy 1 Legacy 2 \n"
+ "X: Exit";
choice = JOptionPane.showInputDialog(menu);
if(choice.equals("A"))
DisplayClass.NumberLegacy1Legacy2(LoricArray);
if(choice.equals("B"))
DisplayClass.NumberNameLegacy1(LoricArray);
if(choice.equals("C"))
DisplayClass.NameLegacy1Legacy2(LoricArray);
}
public static void SearchMenu() throws Exception{
String choice = "";
String menu = "Search Menu \n"
+ "A: Search by name \n"
+ "B: Search by number \n"
+ "C: Search by legacy \n"
+ "X: Exit";
choice = JOptionPane.showInputDialog(menu);
if(choice.equals("A"))
SearchClass.Name(LoricArray);
if(choice.equals("B"))
SearchClass.Number(LoricArray);
if(choice.equals("C"))
SearchClass.Legacy(LoricArray);
}
public static void SortMenu() throws Exception{
String choice = "";
String menu = "Sort Menu \n"
+ "A: Sort alphabetically \n"
+ "B: Sort by number \n"
+ "C: Sort by number in reverse \n"
+ "X: Exit";
choice = JOptionPane.showInputDialog(menu);
if(choice.equals("A"))
SortClass.Name(LoricArray);
if(choice.equals("B"))
SortClass.Number(LoricArray);
if(choice.equals("C"))
SortClass.NumberR(LoricArray);
}
public static void AddAndDelete() throws Exception{
String choice = "";
String menu = "Add and Delete Menu \n"
+ "A: Add \n"
+ "B: Delete \n"
+ "X: Exit";
choice = JOptionPane.showInputDialog(menu);
if(choice.equals("A"))
AddAndDelete.Add(LoricArray);
if(choice.equals("B"))
AddAndDelete.Delete(LoricArray);
}
public static void main(String[] args) throws Exception{
readInList();
mainMenu();
}
}
Comments