Advertisement
MnMWizard

db day 8

Feb 15th, 2018
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.77 KB | None | 0 0
  1. //Mason Marnell
  2. //DatabaseProject class
  3.  
  4. import java.io.File;
  5. import java.util.ArrayList;
  6. import java.util.Scanner;
  7.  
  8. import javax.swing.JOptionPane;
  9.  
  10. public class DatabaseProject {
  11.  
  12.     static ArrayList LoricArray = new ArrayList<Loric>();
  13.    
  14.     public static void readInList() throws Exception{
  15.         Scanner file = new Scanner(new File("./src/listofcharacters"));
  16.         while(file.hasNextLine()){
  17.             String line = file.nextLine();
  18.             String Splitline[] = line.split(",");
  19.             int num = Integer.parseInt(Splitline[0]);
  20.             String name = Splitline[1];
  21.             String leg1 = Splitline[2];
  22.             String leg2 = Splitline[3];
  23.             Loric temp = new Loric(num,name,leg1,leg2);
  24.             System.out.println(temp);
  25.             LoricArray.add(temp);
  26.         }
  27.         System.out.println("Done reading in file.");
  28.                 }
  29.    
  30.     public static void mainMenu() throws Exception{
  31.         String choice = "";
  32.         while(! choice.equals("X")){
  33.             String menu = "Main Menu \n"
  34.                         + "A: Read in Data \n"
  35.                         + "B: Display Menu \n"
  36.                         + "C: Search Menu \n"
  37.                         + "D: Sort Menu \n"
  38.                         + "E: Add and Delete \n"
  39.                         + "X: Exit";
  40.             choice = JOptionPane.showInputDialog(menu);
  41.             if(choice.equals("A"))
  42.                 readInList();
  43.             if(choice.equals("B"))
  44.                 DisplayMenu();
  45.             if(choice.equals("C"))
  46.                 SearchMenu();
  47.             if(choice.equals("D"))
  48.                 SortMenu();
  49.             if(choice.equals("E"))
  50.                 AddAndDelete();
  51.         }
  52.     }
  53.    
  54.     public static void DisplayMenu() throws Exception{
  55.         String choice = "";
  56.             String menu = "Display Menu \n"
  57.                         + "A: Number  Legacy 1  Legacy 2 \n"
  58.                         + "B: Number  Name  Legacy 1 \n"
  59.                         + "C: Name  Legacy 1  Legacy 2 \n"
  60.                         + "X: Exit";
  61.             choice = JOptionPane.showInputDialog(menu);
  62.             if(choice.equals("A"))
  63.                 DisplayClass.NumberLegacy1Legacy2(LoricArray);
  64.             if(choice.equals("B"))
  65.                 DisplayClass.NumberNameLegacy1(LoricArray);
  66.             if(choice.equals("C"))
  67.                 DisplayClass.NameLegacy1Legacy2(LoricArray);
  68.            
  69.         }
  70.    
  71.    
  72.     public static void SearchMenu() throws Exception{
  73.         String choice = "";
  74.             String menu = "Search Menu \n"
  75.                         + "A: Search by name \n"
  76.                         + "B: Search by number \n"
  77.                         + "C: Search by legacy \n"
  78.                         + "X: Exit";
  79.             choice = JOptionPane.showInputDialog(menu);
  80.             if(choice.equals("A"))
  81.                 SearchClass.Name(LoricArray);
  82.             if(choice.equals("B"))
  83.                 SearchClass.Number(LoricArray);
  84.             if(choice.equals("C"))
  85.                 SearchClass.Legacy(LoricArray);
  86.            
  87.         }
  88.    
  89.    
  90.     public static void SortMenu() throws Exception{
  91.         String choice = "";
  92.             String menu = "Sort Menu \n"
  93.                         + "A: Sort alphabetically \n"
  94.                         + "B: Sort by number \n"
  95.                         + "C: Sort by number in reverse \n"
  96.                         + "X: Exit";
  97.             choice = JOptionPane.showInputDialog(menu);
  98.             if(choice.equals("A"))
  99.                 SortClass.Name(LoricArray);
  100.             if(choice.equals("B"))
  101.                 SortClass.Number(LoricArray);
  102.             if(choice.equals("C"))
  103.                 SortClass.NumberR(LoricArray);
  104.            
  105.         }
  106.    
  107.    
  108.     public static void AddAndDelete() throws Exception{
  109.         String choice = "";
  110.             String menu = "Add and Delete Menu \n"
  111.                         + "A: Add \n"
  112.                         + "B: Delete \n"
  113.                         + "X: Exit";
  114.             choice = JOptionPane.showInputDialog(menu);
  115.             if(choice.equals("A"))
  116.                 AddAndDelete.Add(LoricArray);
  117.             if(choice.equals("B"))
  118.                 AddAndDelete.Delete(LoricArray);
  119.            
  120.         }
  121.    
  122.    
  123.     public static void main(String[] args) throws Exception{
  124.         readInList();
  125.         mainMenu();
  126.  
  127.     }
  128.  
  129. }
  130. // --------------------------------------------------------------------------------------------------------------------------------
  131.  
  132. //AddAndDelete class
  133.  
  134. import java.util.ArrayList;
  135.  
  136. import javax.swing.JOptionPane;
  137.  
  138. public class AddAndDelete {
  139.  
  140.     public static void Delete(ArrayList<Loric> theloric){
  141.         String name = JOptionPane.showInputDialog("Enter a character's name");
  142.         for (int i = 0; i < theloric.size(); i++) {
  143.             if(theloric.get(i).getName().contains(name)){
  144.                 String toDisp = "Name: " +theloric.get(i).getName() +"\n";
  145.                 toDisp += "Number: " +theloric.get(i).getNumber() +"\n";
  146.                 toDisp += "Legacy 1: " +theloric.get(i).getLegacy1() +"\n";
  147.                 toDisp += "Legacy 2: " +theloric.get(i).getLegacy2() +"\n";
  148.                
  149.                 String ans = JOptionPane.showInputDialog(toDisp +"\n DO YOU WANT TO DELETE?");
  150.                 if(ans.contains("Y") || ans.contains("y")){
  151.                     theloric.remove(i);
  152.                 }
  153.                
  154.             }
  155.         }
  156.         JOptionPane.showMessageDialog(null, "Deletion complete, RIP");
  157.  
  158.     }
  159.    
  160.     public static void Add(ArrayList<Loric> addguard){
  161.        
  162.         int num = Integer.parseInt(JOptionPane.showInputDialog("Enter a new guard number"));
  163.         String name = JOptionPane.showInputDialog("Enter the new guard's name");
  164.         String leg1 = JOptionPane.showInputDialog("Enter this guard's most defining legacy");
  165.         String leg2 = JOptionPane.showInputDialog("Enter this guard's next defining legacy, or put none");
  166.         Loric temp = new Loric(num,name,leg1,leg2);
  167.         addguard.add(temp);
  168.     }
  169.  
  170. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement