//Mason Marnell //DatabaseProject class import java.io.File; import java.util.ArrayList; import java.util.Scanner; import javax.swing.JOptionPane; public class DatabaseProject { static ArrayList LoricArray = new ArrayList(); 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 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" + "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(); } } 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(); } } // -------------------------------------------------------------------------------------------------------------------------------- //AddAndDelete class import java.util.ArrayList; import javax.swing.JOptionPane; public class AddAndDelete { public static void Delete(ArrayList theloric){ String name = JOptionPane.showInputDialog("Enter a character's name"); for (int i = 0; i < theloric.size(); i++) { if(theloric.get(i).getName().contains(name)){ String toDisp = "Name: " +theloric.get(i).getName() +"\n"; toDisp += "Number: " +theloric.get(i).getNumber() +"\n"; toDisp += "Legacy 1: " +theloric.get(i).getLegacy1() +"\n"; toDisp += "Legacy 2: " +theloric.get(i).getLegacy2() +"\n"; String ans = JOptionPane.showInputDialog(toDisp +"\n DO YOU WANT TO DELETE?"); if(ans.contains("Y") || ans.contains("y")){ theloric.remove(i); } } } JOptionPane.showMessageDialog(null, "Deletion complete, RIP"); } public static void Add(ArrayList addguard){ int num = Integer.parseInt(JOptionPane.showInputDialog("Enter a new guard number")); String name = JOptionPane.showInputDialog("Enter the new guard's name"); String leg1 = JOptionPane.showInputDialog("Enter this guard's most defining legacy"); String leg2 = JOptionPane.showInputDialog("Enter this guard's next defining legacy, or put none"); Loric temp = new Loric(num,name,leg1,leg2); addguard.add(temp); } }