Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Mason Marnell
- // DatabaseProject class
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class DatabaseProject {
- static ArrayList LoricArray = new ArrayList<Loric>();
- public static void readInList() throws Exception{
- Scanner file = new Scanner(new File("./src/listofcharacters"));
- while(file.hasNextLine()){
- String line = file.nextLine();
- String Splitline[] = line.split(",");
- int num = Integer.parseInt(Splitline[0]);
- String name = Splitline[1];
- String leg1 = Splitline[2];
- String leg2 = Splitline[3];
- Loric temp = new Loric(num,name,leg1,leg2);
- System.out.println(temp);
- LoricArray.add(temp);
- }
- System.out.println("Done reading in file.");
- }
- public static void mainMenu() throws Exception{
- String choice = "";
- while(! choice.equals("X")){
- String menu = "Main Menu \n"
- + "A: Read in Data \n"
- + "B: Display Menu \n"
- + "C: Search Menu \n"
- + "D: Sort Menu \n"
- + "X: Exit";
- choice = JOptionPane.showInputDialog(menu);
- if(choice.equals("A"))
- readInList();
- if(choice.equals("B"))
- DisplayMenu();
- if(choice.equals("C"))
- SearchMenu();
- if(choice.equals("D"))
- SortMenu();
- }
- }
- public static void DisplayMenu() throws Exception{
- String choice = "";
- String menu = "Display Menu \n"
- + "A: Number Legacy 1 Legacy 2 \n"
- + "B: Number Name Legacy 1 \n"
- + "C: Name Legacy 1 Legacy 2 \n"
- + "X: Exit";
- choice = JOptionPane.showInputDialog(menu);
- if(choice.equals("A"))
- DisplayClass.NumberLegacy1Legacy2(LoricArray);
- if(choice.equals("B"))
- DisplayClass.NumberNameLegacy1(LoricArray);
- if(choice.equals("C"))
- DisplayClass.NameLegacy1Legacy2(LoricArray);
- }
- public static void SearchMenu() throws Exception{
- String choice = "";
- String menu = "Search Menu \n"
- + "A: Search by name \n"
- + "B: Search by number \n"
- + "C: Search by legacy \n"
- + "X: Exit";
- choice = JOptionPane.showInputDialog(menu);
- if(choice.equals("A"))
- SearchClass.Name(LoricArray);
- if(choice.equals("B"))
- SearchClass.Number(LoricArray);
- if(choice.equals("C"))
- SearchClass.Legacy(LoricArray);
- }
- public static void SortMenu() throws Exception{
- String choice = "";
- String menu = "Sort Menu \n"
- + "A: Sort alphabetically \n"
- + "B: Sort by number \n"
- + "C: Sort by number in reverse \n"
- + "X: Exit";
- choice = JOptionPane.showInputDialog(menu);
- if(choice.equals("A"))
- SortClass.Name(LoricArray);
- if(choice.equals("B"))
- SortClass.Number(LoricArray);
- if(choice.equals("C"))
- SortClass.NumberR(LoricArray);
- }
- public static void main(String[] args) throws Exception{
- readInList();
- mainMenu();
- }
- }
- //------------------------------------------------------------------------------------------------------------------------------------
- // SortClass class
- import java.util.ArrayList;
- import javax.swing.JOptionPane;
- public class SortClass {
- public static void Name(ArrayList<Loric> theloric) {
- for (int i = 0; i < theloric.size(); i++) {
- for (int j = 0; j < theloric.size()-1; j++) {
- if((theloric.get(j).getName().compareTo(theloric.get(j+1).getName()) > 0)){
- Loric temp = theloric.get(j);
- theloric.set(j, theloric.get(j+1));
- theloric.set(j+1, temp);
- }
- }
- }
- JOptionPane.showMessageDialog(null, "Done with sorting, go to display to see results");
- }
- public static void Number(ArrayList<Loric> theloric) {
- for (int i = 0; i < theloric.size(); i++) {
- for (int j = 0; j < theloric.size()-1; j++) {
- if((theloric.get(j).getNumber() > theloric.get(j+1).getNumber())){
- Loric temp = theloric.get(j);
- theloric.set(j, theloric.get(j+1));
- theloric.set(j+1, temp);
- }
- }
- }
- JOptionPane.showMessageDialog(null, "Done with sorting, go to display to see results");
- }
- public static void NumberR(ArrayList<Loric> theloric) {
- for (int i = 0; i < theloric.size(); i++) {
- for (int j = 0; j < theloric.size()-1; j++) {
- if((theloric.get(j).getNumber() < theloric.get(j+1).getNumber())){
- Loric temp = theloric.get(j);
- theloric.set(j, theloric.get(j+1));
- theloric.set(j+1, temp);
- }
- }
- }
- JOptionPane.showMessageDialog(null, "Done with sorting, go to display to see results");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement