Advertisement
MnMWizard

db day 11

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