Advertisement
MnMWizard

db day 9

Feb 20th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.71 KB | None | 0 0
  1. //Mason Marnell
  2. //DatabaseProject class
  3.  
  4. import java.io.File;
  5. import java.io.FileWriter;
  6. import java.io.PrintWriter;
  7. import java.util.ArrayList;
  8. import java.util.Scanner;
  9.  
  10. import javax.swing.JOptionPane;
  11.  
  12. public class DatabaseProject {
  13.  
  14.     static ArrayList LoricArray = new ArrayList<Loric>();
  15.    
  16.     public static void readInList() throws Exception{
  17.         Scanner file = new Scanner(new File("./src/listofcharacters"));
  18.         while(file.hasNextLine()){
  19.             String line = file.nextLine();
  20.             String Splitline[] = line.split(",");
  21.             int num = Integer.parseInt(Splitline[0]);
  22.             String name = Splitline[1];
  23.             String leg1 = Splitline[2];
  24.             String leg2 = Splitline[3];
  25.             Loric temp = new Loric(num,name,leg1,leg2);
  26.             System.out.println(temp);
  27.             LoricArray.add(temp);
  28.         }
  29.         System.out.println("Done reading in file.");
  30.                 }
  31.    
  32.     public static void Save() throws Exception{
  33.         PrintWriter output = new PrintWriter(new FileWriter("./src/listofcharacters"));
  34.         for (int i = 0; i < LoricArray.size(); i++) {
  35.             output.println(LoricArray.get(i));
  36.         }
  37.            
  38.        
  39.         System.out.println("File saved.");
  40.         output.close();
  41.     }
  42.     public static void mainMenu() throws Exception{
  43.         String choice = "";
  44.         while(! choice.equals("X")){
  45.             String menu = "Main Menu \n"
  46.                         + "A: Read in Data \n"
  47.                         + "B: Display Menu \n"
  48.                         + "C: Search Menu \n"
  49.                         + "D: Sort Menu \n"
  50.                         + "E: Add and Delete \n"
  51.                         + "F: Save \n"
  52.                         + "X: Exit";
  53.             choice = JOptionPane.showInputDialog(menu);
  54.             if(choice.equals("A"))
  55.                 readInList();
  56.             if(choice.equals("B"))
  57.                 DisplayMenu();
  58.             if(choice.equals("C"))
  59.                 SearchMenu();
  60.             if(choice.equals("D"))
  61.                 SortMenu();
  62.             if(choice.equals("E"))
  63.                 AddAndDelete();
  64.             if(choice.equals("F"))
  65.                 Save();
  66.         }
  67.     }
  68.    
  69.     public static void DisplayMenu() throws Exception{
  70.         String choice = "";
  71.             String menu = "Display Menu \n"
  72.                         + "A: Number  Legacy 1  Legacy 2 \n"
  73.                         + "B: Number  Name  Legacy 1 \n"
  74.                         + "C: Name  Legacy 1  Legacy 2 \n"
  75.                         + "X: Exit";
  76.             choice = JOptionPane.showInputDialog(menu);
  77.             if(choice.equals("A"))
  78.                 DisplayClass.NumberLegacy1Legacy2(LoricArray);
  79.             if(choice.equals("B"))
  80.                 DisplayClass.NumberNameLegacy1(LoricArray);
  81.             if(choice.equals("C"))
  82.                 DisplayClass.NameLegacy1Legacy2(LoricArray);
  83.            
  84.         }
  85.    
  86.    
  87.     public static void SearchMenu() throws Exception{
  88.         String choice = "";
  89.             String menu = "Search Menu \n"
  90.                         + "A: Search by name \n"
  91.                         + "B: Search by number \n"
  92.                         + "C: Search by legacy \n"
  93.                         + "X: Exit";
  94.             choice = JOptionPane.showInputDialog(menu);
  95.             if(choice.equals("A"))
  96.                 SearchClass.Name(LoricArray);
  97.             if(choice.equals("B"))
  98.                 SearchClass.Number(LoricArray);
  99.             if(choice.equals("C"))
  100.                 SearchClass.Legacy(LoricArray);
  101.            
  102.         }
  103.    
  104.    
  105.     public static void SortMenu() throws Exception{
  106.         String choice = "";
  107.             String menu = "Sort Menu \n"
  108.                         + "A: Sort alphabetically \n"
  109.                         + "B: Sort by number \n"
  110.                         + "C: Sort by number in reverse \n"
  111.                         + "X: Exit";
  112.             choice = JOptionPane.showInputDialog(menu);
  113.             if(choice.equals("A"))
  114.                 SortClass.Name(LoricArray);
  115.             if(choice.equals("B"))
  116.                 SortClass.Number(LoricArray);
  117.             if(choice.equals("C"))
  118.                 SortClass.NumberR(LoricArray);
  119.            
  120.         }
  121.    
  122.    
  123.     public static void AddAndDelete() throws Exception{
  124.         String choice = "";
  125.             String menu = "Add and Delete Menu \n"
  126.                         + "A: Add \n"
  127.                         + "B: Delete \n"
  128.                         + "X: Exit";
  129.             choice = JOptionPane.showInputDialog(menu);
  130.             if(choice.equals("A"))
  131.                 AddAndDelete.Add(LoricArray);
  132.             if(choice.equals("B"))
  133.                 AddAndDelete.Delete(LoricArray);
  134.            
  135.         }
  136.    
  137.    
  138.     public static void main(String[] args) throws Exception{
  139.         readInList();
  140.         mainMenu();
  141.  
  142.     }
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement