Advertisement
MnMWizard

db day 5

Feb 9th, 2018
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.58 KB | None | 0 0
  1. //Mason Marnell
  2. //DatabaseProject
  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.                         + "X: Exit";
  38.             choice = JOptionPane.showInputDialog(menu);
  39.             if(choice.equals("A"))
  40.                 readInList();
  41.             if(choice.equals("B"))
  42.                 DisplayMenu();
  43.             if(choice.equals("C"))
  44.                 SearchMenu();
  45.            
  46.         }
  47.     }
  48.    
  49.     public static void DisplayMenu() throws Exception{
  50.         String choice = "";
  51.             String menu = "Display Menu \n"
  52.                         + "A: Number  Legacy 1  Legacy 2 \n"
  53.                         + "B: Number  Name  Legacy 1 \n"
  54.                         + "C: Name  Legacy 1  Legacy 2 \n"
  55.                         + "X: Exit";
  56.             choice = JOptionPane.showInputDialog(menu);
  57.             if(choice.equals("A"))
  58.                 DisplayClass.NumberLegacy1Legacy2(LoricArray);
  59.             if(choice.equals("B"))
  60.                 DisplayClass.NumberNameLegacy1(LoricArray);
  61.             if(choice.equals("C"))
  62.                 DisplayClass.NameLegacy1Legacy2(LoricArray);
  63.            
  64.         }
  65.    
  66.    
  67.     public static void SearchMenu() throws Exception{
  68.         String choice = "";
  69.             String menu = "Search Menu \n"
  70.                         + "A: Search 1 \n"
  71.                         + "B: Search 2 \n"
  72.                         + "C: Search 3 \n"
  73.                         + "X: Exit";
  74.             choice = JOptionPane.showInputDialog(menu);
  75.             if(choice.equals("A"))
  76.                 System.out.println("Search 1");
  77.             if(choice.equals("B"))
  78.                 System.out.println("Search 2");
  79.             if(choice.equals("C"))
  80.                 System.out.println("Search 3");
  81.            
  82.         }
  83.    
  84.    
  85.     public static void main(String[] args) throws Exception{
  86.         readInList();
  87.         mainMenu();
  88.  
  89.     }
  90.  
  91. }
  92. //---------------------------------------------------------------------------------------------------------------------------
  93.  
  94. //DisplayClass
  95.  
  96. import java.util.ArrayList;
  97.  
  98. import javax.swing.JOptionPane;
  99.  
  100. public class DisplayClass {
  101.  
  102.     public static void NumberLegacy1Legacy2(ArrayList<Loric> theloric) {
  103.             String toDisp = "";
  104.             for (int i = 0; i < theloric.size(); i++) {
  105.                 toDisp += theloric.get(i).getNumber() + "   ";
  106.                 toDisp += theloric.get(i).getLegacy1() + "   ";
  107.                 toDisp += theloric.get(i).getLegacy2() + "   \n";
  108.             }
  109.             JOptionPane.showMessageDialog(null, toDisp);
  110.     }
  111.    
  112.     public static void NumberNameLegacy1(ArrayList<Loric> theloric) {
  113.         String toDisp = "";
  114.         for (int i = 0; i < theloric.size(); i++) {
  115.             toDisp += theloric.get(i).getNumber() + "   ";
  116.             toDisp += theloric.get(i).getName() + "   ";
  117.             toDisp += theloric.get(i).getLegacy1() + "   \n";
  118.         }
  119.         JOptionPane.showMessageDialog(null, toDisp);
  120. }
  121.  
  122.     public static void NameLegacy1Legacy2(ArrayList<Loric> theloric) {
  123.         String toDisp = "";
  124.         for (int i = 0; i < theloric.size(); i++) {
  125.             toDisp += theloric.get(i).getName() + "   ";
  126.             toDisp += theloric.get(i).getLegacy1() + "   ";
  127.             toDisp += theloric.get(i).getLegacy2() + "   \n";
  128.         }
  129.         JOptionPane.showMessageDialog(null, toDisp);
  130. }
  131.    
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement