Advertisement
MnMWizard

db day 6

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