Advertisement
MnMWizard

db day 7

Feb 13th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.47 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.                         + "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.             if(choice.equals("D"))
  47.                 SortMenu();
  48.            
  49.         }
  50.     }
  51.    
  52.     public static void DisplayMenu() throws Exception{
  53.         String choice = "";
  54.             String menu = "Display Menu \n"
  55.                         + "A: Number  Legacy 1  Legacy 2 \n"
  56.                         + "B: Number  Name  Legacy 1 \n"
  57.                         + "C: Name  Legacy 1  Legacy 2 \n"
  58.                         + "X: Exit";
  59.             choice = JOptionPane.showInputDialog(menu);
  60.             if(choice.equals("A"))
  61.                 DisplayClass.NumberLegacy1Legacy2(LoricArray);
  62.             if(choice.equals("B"))
  63.                 DisplayClass.NumberNameLegacy1(LoricArray);
  64.             if(choice.equals("C"))
  65.                 DisplayClass.NameLegacy1Legacy2(LoricArray);
  66.            
  67.         }
  68.    
  69.    
  70.     public static void SearchMenu() throws Exception{
  71.         String choice = "";
  72.             String menu = "Search Menu \n"
  73.                         + "A: Search by name \n"
  74.                         + "B: Search by number \n"
  75.                         + "C: Search by legacy \n"
  76.                         + "X: Exit";
  77.             choice = JOptionPane.showInputDialog(menu);
  78.             if(choice.equals("A"))
  79.                 SearchClass.Name(LoricArray);
  80.             if(choice.equals("B"))
  81.                 SearchClass.Number(LoricArray);
  82.             if(choice.equals("C"))
  83.                 SearchClass.Legacy(LoricArray);
  84.            
  85.         }
  86.    
  87.    
  88.     public static void SortMenu() throws Exception{
  89.         String choice = "";
  90.             String menu = "Sort Menu \n"
  91.                         + "A: Sort alphabetically \n"
  92.                         + "B: Sort by number \n"
  93.                         + "C: Sort by number in reverse \n"
  94.                         + "X: Exit";
  95.             choice = JOptionPane.showInputDialog(menu);
  96.             if(choice.equals("A"))
  97.                 SortClass.Name(LoricArray);
  98.             if(choice.equals("B"))
  99.                 SortClass.Number(LoricArray);
  100.             if(choice.equals("C"))
  101.                 SortClass.NumberR(LoricArray);
  102.            
  103.         }
  104.    
  105.    
  106.     public static void main(String[] args) throws Exception{
  107.         readInList();
  108.         mainMenu();
  109.  
  110.     }
  111.  
  112. }
  113.  
  114. //------------------------------------------------------------------------------------------------------------------------------------
  115. // SortClass class
  116.  
  117. import java.util.ArrayList;
  118.  
  119. import javax.swing.JOptionPane;
  120.  
  121. public class SortClass {
  122.  
  123.     public static void Name(ArrayList<Loric> theloric) {
  124.        
  125.         for (int i = 0; i < theloric.size(); i++) {
  126.             for (int j = 0; j < theloric.size()-1; j++) {
  127.                 if((theloric.get(j).getName().compareTo(theloric.get(j+1).getName()) > 0)){
  128.                     Loric temp = theloric.get(j);
  129.                     theloric.set(j, theloric.get(j+1));
  130.                     theloric.set(j+1, temp);
  131.                 }
  132.             }
  133.         }
  134.        
  135.         JOptionPane.showMessageDialog(null, "Done with sorting, go to display to see results");
  136.  
  137.     }
  138.    
  139. public static void Number(ArrayList<Loric> theloric) {
  140.        
  141.         for (int i = 0; i < theloric.size(); i++) {
  142.             for (int j = 0; j < theloric.size()-1; j++) {
  143.                 if((theloric.get(j).getNumber() > theloric.get(j+1).getNumber())){
  144.                     Loric temp = theloric.get(j);
  145.                     theloric.set(j, theloric.get(j+1));
  146.                     theloric.set(j+1, temp);
  147.                 }
  148.             }
  149.         }
  150.        
  151.         JOptionPane.showMessageDialog(null, "Done with sorting, go to display to see results");
  152.  
  153.     }
  154.  
  155.  
  156. public static void NumberR(ArrayList<Loric> theloric) {
  157.    
  158.     for (int i = 0; i < theloric.size(); i++) {
  159.         for (int j = 0; j < theloric.size()-1; j++) {
  160.             if((theloric.get(j).getNumber() < theloric.get(j+1).getNumber())){
  161.                 Loric temp = theloric.get(j);
  162.                 theloric.set(j, theloric.get(j+1));
  163.                 theloric.set(j+1, temp);
  164.             }
  165.         }
  166.     }
  167.    
  168.     JOptionPane.showMessageDialog(null, "Done with sorting, go to display to see results");
  169.  
  170. }
  171.    
  172.  
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement