Difference between revisions of "Java Desktop App - Zoo Management System"

From Sinfronteras
Jump to: navigation, search
(A look at the GUI)
(Replaced content with "~ Migrated")
(Tag: Replaced)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<br />
+
~ Migrated
==Project description==
 
<span style="background:#E6E6FA ">'''In this project, we have created a GUI Java (Swing) Application for a Zoo Management System:'''</span>
 
* You can try the application by downloading the Java Jar file from this link: http://perso.sinfronteras.ws/images/2/27/ZooManagementSystem.jar
 
* You can also see or download the Java Project from our Github repository at: https://github.com/adeloaleman/JavaDesktopApp-ZooManagementSystem
 
* If you just want to take a look to the Application GUI, [[Java Desktop App - Zoo Management System#A look at the GUI|here]] we show some images that try to describe the most important features of the application.
 
 
 
 
 
 
 
<span style="background:#E6E6FA ">'''Our Management System allows users (Zoo Administrators) to manage Animals and Zoo Keepers. Some of the functionalities that have been added to the system are:'''</span>
 
* Search for Animals:
 
:: Refine by: Type, Specie, Name, etc.
 
* Search for Keepers
 
* Add new animals to the database
 
* Add new keepers
 
* Update animals
 
:: Manage aspects such as Medications, Vaccines, Offsprings, etc
 
* Update keepers
 
 
 
 
 
 
 
<span style="background:#E6E6FA ">'''The most important concepts we have applied to build this applications are:'''</span>
 
* '''Design Patters:'''
 
:* We have implemented a [[Object Orientation with Design Patterns#Model-View-Controller MVC|Model-View-Controller MVC]]
 
:* To facilitate communication between GUI components we have implemented a [[Object Orientation with Design Patterns#Mediator Pattern|Mediator Pattern]]
 
* [[Java GUI Programming|GUI Java Swing]]
 
* [[Object-Oriented Concepts and Constructs#Inheritance|Inheritance]], [[Object-Oriented Concepts and Constructs#Polymorphism|Polymorphism]], [[Object-Oriented Concepts and Constructs#Upcasting - Downcasting|Upcasting - Downcasting]]: These were the most important concepts we have learned and implemented in this project. Because animals are broken down into different types (see example below) we had implemented a class-based inheritance model where <Animal> is the super class. We often had to use Downcasting in order to get access to specific behaviors of a subclass into the Animal hierarchy.
 
* [[Object-Oriented Concepts and Constructs#Abstraction|Abstraction]]
 
* [[Object-Oriented Concepts and Constructs#Encapsulation|Encapsulation]]
 
* [[Object-Oriented Concepts and Constructs#Serialization|Serialization]]: We have implemented data persistence through a file using serialization.
 
 
 
 
 
The Zoo has a number of Animals. These Animals are broken down into types: Mammal, Reptile, Avian, Aquatic, Insect. For example:
 
* Mammal:
 
:* Avian
 
::* Bat
 
:::* date of birth, date of arrival, fight, gender, ofspring, medication, vaccine, exhibit number
 
 
 
 
 
<!--
 
 
 
'''Each Animal has a Zoo keeper that looks afer it:'''
 
*Zoo keepers are only allowed to care for animals if they are qualified to do so.
 
*A zoo keeper can look afer a max of 3 Animal types for a max of 10 animals.
 
 
 
 
 
 
 
'''Your system must be run on test data before the Zoo will accept it.
 
 
 
 
 
 
 
'''You are required to have a data set of at least 100 animals and 40 zoo keepers.'''
 
 
 
-->
 
 
 
 
 
<br />
 
 
 
==Class diagram==
 
<div style="text-align: center;">
 
<figure id="fig:Fake_news_dataset_example">
 
<pdf width="2000" height="700">File:ClassDiagramCCTZoo.pdf</pdf>
 
<caption>Data example</caption>
 
 
 
[[File:ClassDiagramCCTZoo.pdf]] [[Media:ClassDiagramCCTZoo.png]]
 
</figure>
 
</div>
 
 
 
 
 
<br />
 
 
 
==An example of one of the classes==
 
src/cctzoo/model/SetUp.java
 
<syntaxhighlight lang="java">
 
package cctzoo.model;
 
 
 
import cctzoo.model.animals.Animal;
 
import cctzoo.model.animals.Aquatic;
 
import cctzoo.model.animals.Avian;
 
import cctzoo.model.animals.CreateAquatic;
 
import cctzoo.model.animals.CreateAvian;
 
import cctzoo.model.animals.CreateMammal;
 
import cctzoo.model.animals.CreateMammalAquatic;
 
import cctzoo.model.animals.CreateReptile;
 
import cctzoo.model.animals.CreateReptileAquatic;
 
import cctzoo.model.animals.Insect;
 
import cctzoo.model.animals.Mammal;
 
import cctzoo.model.animals.Medication;
 
import cctzoo.model.animals.Reptile;
 
import cctzoo.model.animals.Vacine;
 
import cctzoo.model.keepers.Keeper;
 
import java.io.Serializable;
 
import java.util.ArrayList;
 
import java.util.Arrays;
 
import java.util.Random;
 
 
 
 
 
public class SetUp implements Serializable {
 
    private ArrayList<Animal> myAnimals;
 
    private ArrayList<Medication> myMedication;
 
    private ArrayList<Vacine> myVacines;
 
    private ArrayList<Keeper> myKeepers;
 
   
 
    private String[] mammalSpecies = {"Tiger", "Elephant", "Bear", "Deer", "Squirrel", "Armadillo", "Ape", "Hyena", "Lemur", "Simian", "Jirafe", "Leopard", "Ocelot"};
 
    private String[] reptileSpecies = {"Lizard", "Geckos", "Skink", "Gekkota", "Iguanidae", "Chamaleons", "Turtle", "Snake", "Lacertid", "Gila Monster", "Viper", "Tuatara"};
 
    private String[] avianSpecies = {"Parrot", "Owl", "Tucan", "Swallow", "Sparrow", "Goose", "Potoo", "Heron", "Tern", "Bustard", "Kingfisher", "Turaco", "Eagle"};
 
    private String[] mammalAquaticSpecies = {"Dolphin", "Wale","Pinguin", "See Cow", "Otter", "Pinniped", "Rhinoceros", "Seal", "American Beaver", "Manatee", "Capibara", "Hippopotamus" };
 
    private String[] reptileAquatic = {"Crocodile", "Anaconda", "Coral Snake", "North Watter Snake", "Emydidae", "Homalopsis Snake", "Salamander", "Turtle", "Busmaster"};
 
    private String[] names = {"Charlene", "Benny", "Della", "Herietta", "Dixie", "Guadalupe", "Nancy", "Byron", "Cora", "Nora", "Jody", "Blanca", "Sara", "Jeannie", "Ginger", "Dwight", "Bennie", "Ana", "Rex", "Eleanor", "Danielle", "Mack", "Verna", "Erik", "Leona"};
 
    private String[] medication = {"Lovetoin", "Trandoronate", "Afanuma", "Cortimadin", "Tetapitant", "Ablastral", "Bactaxime", "Allokyn", "Sublamin", "Nornex", "Adiline", "Veratasol"};
 
    private String[] vacine = {"AVA-BioThrax", "DTaP", "PCV13", "Rabies", "RV1", "RV5", "Vaccinia", "Tenivac", "MMRV", "Typhoid-Oral", "Flulaval", "MenACWY", "MenB", "Fluzone", "Zostavax"};
 
   
 
    private String[] dates = {"03/09/2003", "13/06/1991", "17/02/1988", "09/01/2009", "28/10/1996", "02/08/2002", "31/08/1989", "22/11/1997", "29/06/2014", "10/02/1992", "12/09/2004",
 
            "23/07/2003", "30/09/1993", "22/03/2016", "21/10/1988", "13/02/1990", "07/09/2008", "23/01/2011", "09/11/2015", "14/05/1998", "24/12/2008", "22/12/2011", "21/07/2016",
 
            "25/08/1992", "26/10/2017", "24/04/1988", "14/10/2010", "15/09/1992", "29/01/2015", "09/12/1989", "12/12/1999", "02/05/2003", "17/12/1989", "05/03/2003"};
 
   
 
    private String[] keepersNames = {"Jerold Rowser", "Anabelle Lilie", "Tory Linbdlon", "Elli Rinhaldo", "Lemuel Burget", "Jermaine Luong", "Manuela Forester", "Jeannie Yuen", "Bonita Ito", "Chery Meredith", "Gay Kettler", "Wendel Goldner", "Erika Luoma", "Lin Millighan"};
 
    private String[] animalTypes = {"Mammal", "Reptile", "Avian", "Aquatic", "Insect"};
 
   
 
    public SetUp() {
 
        myAnimals = new ArrayList<Animal>();
 
        myMedication = new ArrayList<>();
 
        myVacines = new ArrayList<>();
 
        myKeepers = new ArrayList<>();
 
    }
 
       
 
   
 
    public void setListMedication(int numMed) {
 
        Random r = new Random();
 
        for(int i = 0; i < numMed ; i++) {
 
            myMedication.add(new Medication());
 
            for(int j = 0 ; j < r.nextInt(4); j++) {
 
                myMedication.get(i).addMedication(medication[r.nextInt(medication.length)]);
 
            }
 
        }
 
    }
 
   
 
    public void setListVacine(int numbVac) {
 
        Random r = new Random();
 
        for(int i = 0; i < numbVac ; i++) {
 
            myVacines.add(new Vacine());
 
            for(int j = 0 ; j < r.nextInt(4); j++) {
 
                myVacines.get(i).addVacine(vacine[r.nextInt(vacine.length)]);
 
            }
 
        }
 
    }
 
   
 
    public void setListAnimals (int numAnimals) {
 
        try {
 
           
 
            Random r = new Random();
 
            for (int i = 0; i< numAnimals; i++) {
 
               
 
                switch (r.nextInt(5)) {
 
                    case 0:
 
                        myAnimals.add(new CreateMammal(mammalSpecies[r.nextInt(mammalSpecies.length)], names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                        dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size()))));
 
 
 
                        // Down Casting to acces the mammal method furry
 
                        CreateMammal c;
 
                        c = (CreateMammal) myAnimals.get(myAnimals.size()-1);
 
                        c.setFurry(r.nextInt(2));
 
 
 
                        //Create Offsprings
 
                        for (int j = 0; j < r.nextInt(4); j++) {
 
                            c.createOffpring(names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                            dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size())));
 
                           
 
                        //Down Casting to set furry to the Offsprings
 
                        CreateMammal d;
 
                        d = (CreateMammal) c.getOffsprings().get(j);
 
                        d.setFurry(r.nextInt(2));
 
                        myAnimals.add(d);
 
                        }
 
                    break;
 
 
 
                    case 1:
 
                        myAnimals.add(new CreateMammalAquatic(mammalAquaticSpecies[r.nextInt(mammalAquaticSpecies.length)], names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                        dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size()))));
 
 
 
                        // Down Casting to acces the mammal Aquatic properties
 
                        CreateMammalAquatic mAq;
 
                        mAq =  (CreateMammalAquatic) myAnimals.get(myAnimals.size()-1);
 
                        mAq.setCanBeOutSideWatter(r.nextInt(2));
 
                        mAq.setFurry(r.nextInt(2));
 
 
 
                        //Create Offsprings
 
                        for (int j = 0; j < r.nextInt(4); j++) {
 
                            mAq.createOffpring(names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                            dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size())));
 
 
 
                        //Down Casting to set unique fields to the Offsprings
 
                        CreateMammalAquatic mA2;
 
                        mA2 =  (CreateMammalAquatic) mAq.getOffsprings().get(j);
 
                        mA2.setCanBeOutSideWatter(r.nextInt(2));
 
                        mA2.setFurry(r.nextInt(2));
 
                        myAnimals.add(mA2);
 
                       
 
                        }
 
                    break;
 
                       
 
                    case 2:
 
                        myAnimals.add(new CreateReptile(reptileSpecies[r.nextInt(reptileSpecies.length)], names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                        dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size()))));
 
 
 
                        // Down Casting to acces the Reptile Method
 
                        CreateReptile rept; 
 
                        rept =  (CreateReptile) myAnimals.get(myAnimals.size()-1);
 
                        rept.setIsVennon(r.nextInt(2));
 
 
 
                        //Create Offsprings
 
                        for (int j = 0; j < r.nextInt(4); j++) {
 
                            rept.createOffpring(names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                            dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size())));
 
 
 
                       
 
                        CreateReptile rept2;
 
                        rept2 = (CreateReptile) rept.getOffsprings().get(j);
 
                        rept2.setIsVennon(r.nextInt(2));
 
                        myAnimals.add(rept2);
 
                        }
 
                    break;
 
                   
 
                    case 3:
 
                        myAnimals.add(new CreateAvian(avianSpecies[r.nextInt(avianSpecies.length)], names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                        dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size()))));
 
                       
 
                       
 
                        // Down Casting to acces the Avian Method
 
                        CreateAvian av; 
 
                        av =    (CreateAvian) myAnimals.get(myAnimals.size()-1);
 
                        av.setCanFligh(r.nextInt(2));
 
                        av.setHasFeeders(r.nextInt(2));
 
 
 
                        //Create Offsprings
 
                        for (int j = 0; j < r.nextInt(4); j++) {
 
                            av.createOffpring(names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                            dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size())));
 
 
 
                        CreateAvian av2;
 
                        av2 = (CreateAvian) av.getOffsprings().get(j);
 
                        av2.setCanFligh(r.nextInt(2));
 
                        av2.setHasFeeders(r.nextInt(2));
 
                        myAnimals.add(av2);
 
                        }
 
                        break;
 
                       
 
                    case 4:
 
                        myAnimals.add(new CreateReptileAquatic(reptileSpecies[r.nextInt(reptileSpecies.length)], names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                        dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size()))));
 
                       
 
                       
 
                        // Down Casting to acces
 
                        CreateReptileAquatic ra; 
 
                        ra =    (CreateReptileAquatic) myAnimals.get(myAnimals.size()-1);
 
                        ra.canBeOutsideWatter(r.nextInt(2));
 
                        ra.isVennon(r.nextInt(2));
 
 
 
                        //Create Offsprings
 
                        for (int j = 0; j < r.nextInt(4); j++) {
 
                            ra.createOffpring(names[r.nextInt(names.length)], dates[r.nextInt(dates.length)],
 
                            dates[r.nextInt(dates.length)], r.nextInt(2), myMedication.get(r.nextInt(myMedication.size())), myVacines.get(r.nextInt(myVacines.size())));
 
 
 
                        CreateReptileAquatic ra2;
 
                        ra2 =  (CreateReptileAquatic) ra.getOffsprings().get(j);
 
                        ra2.canBeOutsideWatter(r.nextInt(2));
 
                        ra2.isVennon(r.nextInt(2));
 
                        myAnimals.add(ra2);
 
                        }
 
                }
 
            }
 
        } catch(Exception e) {
 
            System.out.println("An Error has ocurred" + e);
 
           
 
        }
 
    }
 
   
 
   
 
    public void setListKeepers(int numKeepers) {
 
        Random r = new Random();
 
        String type;
 
        for(int i = 0; i < numKeepers ; i++) {
 
            getMyKeepers().add(new Keeper(names[r.nextInt(names.length)], dates[r.nextInt(dates.length)]));
 
            // Every keeper will have at least 2 Qualifications (max 3)
 
            int numero = r.nextInt(3)+1;
 
            for(int j = 0 ; j < numero ; j++) {
 
                do {
 
                    type = animalTypes[r.nextInt(animalTypes.length)];
 
                }while(getMyKeepers().get(i).getQualification().contains(type));
 
                getMyKeepers().get(i).addQualification(type);
 
            }
 
           
 
            ArrayList<String> repetido = new ArrayList<String>();
 
            int max = r.nextInt(5) + 5;
 
            for(int k = 0 ; k < max; k++) {
 
                ArrayList<String> noqualify = new ArrayList<>(Arrays.asList(animalTypes));
 
                noqualify.removeAll(getMyKeepers().get(i).getQualification());
 
               
 
                Animal a = null;
 
                boolean asignado = false;
 
                int c = 0;
 
                while (asignado == false && c < getMyAnimals().size()){
 
                    int animalRan = r.nextInt(myAnimals.size());
 
                    a = getMyAnimals().get(animalRan);
 
                    boolean calificado = true;
 
                    int l=0;
 
                    while (l < noqualify.size() && calificado == true) {
 
                        String noquali = noqualify.get(l);
 
                        switch (noquali) {
 
                            case "Mammal" :
 
                                if(a instanceof Mammal){
 
                                    calificado = false;
 
                                }
 
                                break;
 
                            case "Reptile" :
 
                                if(a instanceof Reptile){
 
                                    calificado = false;
 
                                }
 
                                break;
 
                            case "Avian" :
 
                                if(a instanceof Avian){
 
                                    calificado = false;
 
                                }
 
                                break;
 
                            case "Aquatic" :
 
                                if(a instanceof Aquatic){
 
                                    calificado = false;
 
                                }
 
                                break;
 
                            case "Insect" :
 
                                if(a instanceof Insect){
 
                                    calificado = false;
 
                                }
 
                                break;
 
                        }
 
                        l++;
 
                    }
 
                    if (calificado == true && !repetido.contains(String.valueOf(animalRan))){
 
                        getMyKeepers().get(i).addAnimal(a);
 
                        repetido.add(String.valueOf(animalRan));
 
                        asignado=true;
 
                    }
 
                    c++;
 
                }
 
            }
 
        }
 
    }
 
   
 
    public ArrayList<Animal> getMyAnimals() {
 
        return myAnimals;
 
    }
 
 
 
    public void setMyAnimals(ArrayList<Animal> myAnimals) {
 
        this.myAnimals = myAnimals;
 
    }
 
 
 
    public ArrayList<Medication> getMyMedication() {
 
        return myMedication;
 
    }
 
   
 
    public ArrayList<Vacine> getMyVacines() {
 
        return myVacines;
 
    }
 
 
 
    public void setMyMedication(ArrayList<Medication> myMedication) {
 
        this.myMedication = myMedication;
 
    }
 
 
 
    public ArrayList<Keeper> getMyKeepers() {
 
        return myKeepers;
 
    }
 
   
 
}
 
</syntaxhighlight>
 
 
 
 
 
<br />
 
 
 
==Take a look at the GUI==
 
<gallery mode=packed-overlay>
 
File:ZooManagementSystem_GUI_1.png|Main Menu
 
File:ZooManagementSystem_GUI_2.png|View Animals Panel
 
File:ZooManagementSystem_GUI_3.png|View Animals Panel - Refine by...
 
File:ZooManagementSystem_GUI_4.png|Add Animals Panel
 
File:ZooManagementSystem_GUI_5.png|View Keeper Panel - Refine by...
 
File:ZooManagementSystem_GUI_6.png|Add Zoo Keaper Panel
 
</gallery>
 
 
 
 
 
<!--
 
[[File:ZooManagementSystem_GUI_1.png|600px|thumb|center|]]
 
 
 
 
 
[[File:ZooManagementSystem_GUI_2.png|900px|thumb|center|]]
 
 
 
 
 
[[File:ZooManagementSystem_GUI_3.png|900px|thumb|center|]]
 
 
 
 
 
[[File:ZooManagementSystem_GUI_4.png|900px|thumb|center|]]
 
 
 
 
 
[[File:ZooManagementSystem_GUI_5.png|900px|thumb|center|]]
 
 
 
 
 
[[File:ZooManagementSystem_GUI_6.png|600px|thumb|center|]]
 
-->
 

Latest revision as of 15:31, 1 March 2026

~ Migrated