Untitled

 avatar
unknown
plain_text
2 years ago
22 kB
3
Indexable
import javax.swing.*;
import java.util.*;
public class MethodClass
{
    
    static int currentyear = 2023;
    public void AddRecord(ArrayList<MaltesePlayers> F) 
    {
         String[] nationalities = {"Maltese", "Foreign"};
        JComboBox<String> comboBox = new JComboBox<>(nationalities);
        int option = JOptionPane.showOptionDialog(null, comboBox, "Select player nationality", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[]{"OK", "Exit"}, "OK");
        if (option == JOptionPane.OK_OPTION) {
            String nationality = (String) comboBox.getSelectedItem();
                if (nationality == "Maltese") 
                {
                    MaltesePlayers mc = new MaltesePlayers();
                
                    JComboBox<Integer> comboBox2 = new JComboBox<>();
                    for (int i = 7; i < 18; i++) {
                        comboBox2.addItem(i);
                    }
                    int option1 = JOptionPane.showOptionDialog(null, comboBox2, "Select player age", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[]{"OK", "Exit"}, "OK");
                            if (option1 == JOptionPane.OK_OPTION) {
                            int age = (int) comboBox2.getSelectedItem();
                                switch(age) {
                                    case 6: int six = 8;
                                    mc.setDivision(six); break;
                                    case 7: int seven = 8;
                                    mc.setDivision(seven); break;
                                    case 8: int eight = 10;
                                    mc.setDivision(eight); break;
                                    case 9: int nine = 10;
                                    mc.setDivision(nine); break;
                                    case 10: int ten = 12;
                                    mc.setDivision(ten); break;
                                    case 11: int eleven = 12;
                                    mc.setDivision(eleven); break;
                                    case 12: int twelve = 4;
                                    mc.setDivision(twelve); break;
                                    case 13: int thirteen = 14;
                                    mc.setDivision(thirteen); break;
                                    case 14: int fourteen = 16;
                                    mc.setDivision(fourteen); break;
                                    case 15: int fifteen = 16;
                                    mc.setDivision(fifteen); break;
                                    case 16: int sixteen = 18;
                                    mc.setDivision(sixteen); break;
                                    case 17: int seventeen = 18;
                                    mc.setDivision(seventeen); break;
                                    default: break;
                        
                                        }
                            String ID = JOptionPane.showInputDialog("Please enter ID");
                            mc.setID(ID);
                            String Surname = JOptionPane.showInputDialog("Please enter Surname");
                            mc.setSurname(Surname);
                            String Name = JOptionPane.showInputDialog("Please enter Name");
                            mc.setName(Name);
                            String Locality = JOptionPane.showInputDialog("Please enter Locality");
                            mc.setLocality(Locality);                        
                            String PN = JOptionPane.showInputDialog("Please enter Player Number");
                            int PlayerNo = Integer.parseInt(PN);
                            mc.setPlayerNo(PlayerNo);
                            String H = JOptionPane.showInputDialog("Please enter Height in cm");
                            int Height = Integer.parseInt(H);
                            mc.setHeight(Height);
                            String G = JOptionPane.showInputDialog("Please enter no. of Goals Scored");
                            int Goals = Integer.parseInt(G);
                            mc.setGoals(Goals);
                            String A = JOptionPane.showInputDialog("Please enter no. of Assists Made");
                            int Assists = Integer.parseInt(A);
                            mc.setAssists(Assists);
                            F.add(mc);
                        }
                        else {
                            System.out.println("Exiting to Main Menu");
                        }    
                    }
                    else 
                    {
                        System.out.println("Exiting to Main Menu");
                    }
            }
            
            else 
            {
            ForeignPlayers fc = new ForeignPlayers();
            JComboBox<Integer> comboBox2 = new JComboBox<>();
                    for (int i = 7; i < 18; i++) {
                        comboBox2.addItem(i);
                    }
                    int option1 = JOptionPane.showOptionDialog(null, comboBox2, "Select player age", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[]{"OK", "Exit"}, "OK");
                            if (option1 == JOptionPane.OK_OPTION) {
                            int age = (int) comboBox2.getSelectedItem();
                                switch(age) {
                                    case 6: int six = 8;
                                    fc.setDivision(six); break;
                                    case 7: int seven = 8;
                                    fc.setDivision(seven); break;
                                    case 8: int eight = 10;
                                    fc.setDivision(eight); break;
                                    case 9: int nine = 10;
                                    fc.setDivision(nine); break;
                                    case 10: int ten = 12;
                                    fc.setDivision(ten); break;
                                    case 11: int eleven = 12;
                                    fc.setDivision(eleven); break;
                                    case 12: int twelve = 4;
                                    fc.setDivision(twelve); break;
                                    case 13: int thirteen = 14;
                                    fc.setDivision(thirteen); break;
                                    case 14: int fourteen = 16;
                                    fc.setDivision(fourteen); break;
                                    case 15: int fifteen = 16;
                                    fc.setDivision(fifteen); break;
                                    case 16: int sixteen = 18;
                                    fc.setDivision(sixteen); break;
                                    case 17: int seventeen = 18;
                                    fc.setDivision(seventeen); break;
                                    default: break;
                        
                                        }
                            String ID = JOptionPane.showInputDialog("Please enter Passport No.");
                            fc.setID(ID);
                            String Surname = JOptionPane.showInputDialog("Please enter Surname");
                            fc.setSurname(Surname);
                            String Name = JOptionPane.showInputDialog("Please enter Name");
                            fc.setName(Name);
                            String Locality = JOptionPane.showInputDialog("Please enter Locality");
                            fc.setLocality(Locality);                        
                            String PN = JOptionPane.showInputDialog("Please enter Player Number");
                            int PlayerNo = Integer.parseInt(PN);
                            fc.setPlayerNo(PlayerNo);
                            String H = JOptionPane.showInputDialog("Please enter Height in cm");
                            int Height = Integer.parseInt(H);
                            fc.setHeight(Height);
                            String G = JOptionPane.showInputDialog("Please enter no. of Goals Scored");
                            int Goals = Integer.parseInt(G);
                            fc.setGoals(Goals);
                            String A = JOptionPane.showInputDialog("Please enter no. of Assists Made");
                            int Assists = Integer.parseInt(A);
                            fc.setAssists(Assists);
                            F.add(fc);
                        }
                        else {
                            System.out.println("Exiting to Main Menu");
                        } 
            
            }
    }
    public void DisplayRecord(ArrayList<MaltesePlayers> F)
    {
        String text = " ";
        
        for (int i=0; i < F.size(); i++)
        {
            MaltesePlayers mc = F.get(i);
            text = text + "\n"+ (i+1) + ". ID: "+ mc.getID() + " Full Name: " + mc.getSurname() + " " + mc.getName() + " Locality: " + mc.getLocality() + " Age" + mc.getAge() + " Division" + mc.getDivision() + " No" + mc.getPlayerNo() + " Height: " + mc.getHeight() + "cm Goals: " + mc.getGoals()+ " Assists: " + mc.getAssists();
        }
        
        JOptionPane.showMessageDialog(null, text, "Display", JOptionPane.INFORMATION_MESSAGE);
    }
    
    public void DeleteRecord(ArrayList<MaltesePlayers> F) 
    {
        String choice = JOptionPane.showInputDialog("Please enter ID to delete");
        
        for (int i=0; i<F.size(); i++)
        {
            MaltesePlayers mc = F.get(i);
        
            {
                String c = JOptionPane.showInputDialog("Are you certain if you want to delete?\n\nEnter:\n1 for Yes\n2 for No");
                int option = Integer.parseInt(c);
                
                if (option == 1)
                {
                    F.remove(i);
                    JOptionPane.showMessageDialog(null, "Record deleted", "Deletion", JOptionPane.INFORMATION_MESSAGE);
                }
                else 
                {
                    JOptionPane.showMessageDialog(null, "Record not deleted", "Deletion", JOptionPane.INFORMATION_MESSAGE);

                }
                }
            }
        }
        
    public void SearchRecord(ArrayList<MaltesePlayers> F) 
    {
        boolean searchflag = false;
        String choice = JOptionPane.showInputDialog("Please enter ID to search");
        
        for (int i=0; i<F.size(); i++)
        {
            MaltesePlayers mc = F.get(i);
            
            if (mc.getID().equals(choice))
            {
                JOptionPane.showMessageDialog(null, mc.getID() + " " + mc.getSurname() + " " + mc.getName() + " " + mc.getLocality() + " " + mc.getAge() + " " + mc.getDivision() + " " + mc.getPlayerNo() + " " + mc.getHeight() + " " + mc.getGoals() + " " + mc.getAssists(), "Search", JOptionPane.INFORMATION_MESSAGE);
                searchflag = true;
            }
        }
        
        if (searchflag == false)
        {
            JOptionPane.showMessageDialog(null, "Sorry, record not found", "Error Message" , JOptionPane.ERROR_MESSAGE);
        }
    }
    
    public void SortRecord(ArrayList<MaltesePlayers> F) 
    {
        int len = F.size() - 1;
        boolean sortflag = true;
        String s = JOptionPane.showInputDialog(null, "Sort by:\n 0. Return to Main Menu\n 1. Surname\n 2. Division\n 3. Player No.\n 4. Goals");
        int choice1 = Integer.parseInt(s);
        
        switch (choice1)
        {
            case 0: System.out.println("Returning to Main Menu"); break;
            case 1: while (sortflag) 
                    {
                        sortflag = false;
                        
                        for (int i=0; i<len; i++)
                        {
                            MaltesePlayers f = F.get(i);
                            MaltesePlayers f1 = F.get(i+1);
                            
                            if (f.getSurname().compareTo(f1.getSurname()) > 0)
                            {
                                F.set(i,f1);
                                F.set(i+1,f);
                                sortflag = true;
                            }
                            len--;
                        }
                        JOptionPane.showMessageDialog(null, "List has been sorted successfully", "Sorted", JOptionPane.INFORMATION_MESSAGE);
                    }
                    break;
            case 2: while (sortflag) 
                    {
                        sortflag = false;
                        
                        for (int i=0; i<len; i++)
                        {
                            MaltesePlayers f = F.get(i);
                            MaltesePlayers f1 = F.get(i+1);
                            
                            if (f.getDivision() > (f1.getDivision()))
                            {
                                F.set(i,f1);
                                F.set(i+1,f);
                                sortflag = true;
                            }
                            len--;
                        }
                        JOptionPane.showMessageDialog(null, "List has been sorted successfully", "Sorted", JOptionPane.INFORMATION_MESSAGE);
                    }
                    break;
            case 3: while (sortflag) 
                    {
                        sortflag = false;
                        
                        for (int i=0; i<len; i++)
                        {
                            MaltesePlayers f = F.get(i);
                            MaltesePlayers f1 = F.get(i+1);
                            
                            if (f.getPlayerNo() > (f1.getPlayerNo()) )
                            {
                                F.set(i,f1);
                                F.set(i+1,f);
                                sortflag = true;
                            }
                            len--;
                        }
                        JOptionPane.showMessageDialog(null, "List has been sorted successfully", "Sorted", JOptionPane.INFORMATION_MESSAGE);
                    }
                    break;
            case 4: while (sortflag) 
                    {
                        sortflag = false;
                        
                        for (int i=0; i<len; i++)
                        {
                            MaltesePlayers f = F.get(i);
                            MaltesePlayers f1 = F.get(i+1);
                            
                            if (f.getGoals() > (f1.getGoals()) )
                            {
                                F.set(i,f1);
                                F.set(i+1,f);
                                sortflag = true;
                            }
                            len--;
                        }
                        JOptionPane.showMessageDialog(null, "List has been sorted successfully", "Sorted", JOptionPane.INFORMATION_MESSAGE);
                    }
                    break;
            default: JOptionPane.showMessageDialog(null, "Incorrect Option", "Error", JOptionPane.ERROR_MESSAGE); 
                     break;
        
        }
        
    }
    
    public void EditRecord(ArrayList<MaltesePlayers> F)
    {
        String choice = JOptionPane.showInputDialog("Please enter ID to edit");
        
        for (int i=0; i<F.size(); i++)
        {
            MaltesePlayers mc = F.get(i);
            
            if (mc.getID().equals(choice)) 
            {
                String s = JOptionPane.showInputDialog(null, "0. Return to Main Menu\n1. Edit ID\n2. Edit Surname\n3. Edit Name\n4. Edit Locality\n5. Edit Age\n6. Edit Player Number\n7. Edit Height\n8. Edit Goals Scored\n9. Edit Assists Made");
                int choice1 = Integer.parseInt(s);
                
                switch (choice1)
                {
                    case 0: JOptionPane.showMessageDialog(null, "Returning to Main Menu", "Exit", JOptionPane.INFORMATION_MESSAGE); break;
                    case 1: String id = JOptionPane.showInputDialog("Please enter new ID"); 
                            mc.setID(id); break;
                    case 2: String sn = JOptionPane.showInputDialog("Please enter new Surname"); 
                            mc.setSurname(sn); break;
                    case 3: String n = JOptionPane.showInputDialog("Please enter new Name"); 
                            mc.setName(n); break;
                    case 4: String loc = JOptionPane.showInputDialog("Please enter new Locality"); 
                            mc.setLocality(loc); break;
                    case 5: JComboBox<Integer> comboBox2 = new JComboBox<>();
                    for (int j = 7; j < 18; j++) {
                        comboBox2.addItem(j);
                    }
                    int option1 = JOptionPane.showOptionDialog(null, comboBox2, "Select player age", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, new Object[]{"OK", "Exit"}, "OK");
                            if (option1 == JOptionPane.OK_OPTION) {
                            int age = (int) comboBox2.getSelectedItem();
                            mc.setAge(age);
                                switch(age) {
                                    case 6: int six = 8;
                                    mc.setDivision(six); break;
                                    case 7: int seven = 8;
                                    mc.setDivision(seven); break;
                                    case 8: int eight = 10;
                                    mc.setDivision(eight); break;
                                    case 9: int nine = 10;
                                    mc.setDivision(nine); break;
                                    case 10: int ten = 12;
                                    mc.setDivision(ten); break;
                                    case 11: int eleven = 12;
                                    mc.setDivision(eleven); break;
                                    case 12: int twelve = 4;
                                    mc.setDivision(twelve); break;
                                    case 13: int thirteen = 14;
                                    mc.setDivision(thirteen); break;
                                    case 14: int fourteen = 16;
                                    mc.setDivision(fourteen); break;
                                    case 15: int fifteen = 16;
                                    mc.setDivision(fifteen); break;
                                    case 16: int sixteen = 18;
                                    mc.setDivision(sixteen); break;
                                    case 17: int seventeen = 18;
                                    mc.setDivision(seventeen); break;
                                    default: break;
                        
                                        }
                            String ID = JOptionPane.showInputDialog("Please enter ID");
                            mc.setID(ID);
                            String Surname = JOptionPane.showInputDialog("Please enter Surname");
                            mc.setSurname(Surname);
                            String Name = JOptionPane.showInputDialog("Please enter Name");
                            mc.setName(Name);
                            String Locality = JOptionPane.showInputDialog("Please enter Locality");
                            mc.setLocality(Locality);                        
                            String PN = JOptionPane.showInputDialog("Please enter Player Number");
                            int PlayerNo = Integer.parseInt(PN);
                            mc.setPlayerNo(PlayerNo);
                            String H = JOptionPane.showInputDialog("Please enter Height in cm");
                            int Height = Integer.parseInt(H);
                            mc.setHeight(Height);
                            String G = JOptionPane.showInputDialog("Please enter no. of Goals Scored");
                            int Goals = Integer.parseInt(G);
                            mc.setGoals(Goals);
                            String A = JOptionPane.showInputDialog("Please enter no. of Assists Made");
                            int Assists = Integer.parseInt(A);
                            mc.setAssists(Assists);
                            F.add(mc);
                        }
                        else {
                            System.out.println("Exiting to Main Menu");
                        } 
                            break;
                    case 6: String pn = JOptionPane.showInputDialog("Please enter new Player Number");
                            int PN = Integer.parseInt(pn);
                            mc.setPlayerNo(PN);  break;
                    case 7: String h = JOptionPane.showInputDialog("Please enter new Height in cm");
                            int H = Integer.parseInt(h);
                            mc.setHeight(H); break;
                    case 8: String g = JOptionPane.showInputDialog("Please enter new no. of Goals Scored");
                            int G = Integer.parseInt(g);
                            mc.setGoals(G);break;
                    case 9: String a = JOptionPane.showInputDialog("Please enter new no. of Assists Made");
                            int A = Integer.parseInt(a);
                            mc.setAssists(A); break;
                    default: JOptionPane.showMessageDialog(null, "Incorrect Option", "Error", JOptionPane.ERROR_MESSAGE); 
                             break;
            }
        }
    }
    }
}
    
    
    
    
    
    
    
    
    
    
    
    
    
    
   
Editor is loading...