Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Scy on 03/12/2016.
- */
- public class Main3 {
- public static void main(String[] args){
- Company company=new Company();
- company.addEmployee(new Employee("Imie1", "Nazwisko1"));
- company.addEmployee(new Employee("Imie2", "Nazwisko2"));
- company.addEmployee(new Employee("Imie3", "Nazwisko3"));
- company.addEmployee(new Employee("Imie4", "Nazwisko4"));
- company.addEmployee(new Employee("Imie5", "Nazwisko5"));
- company.addEmployee(new Employee("Imie6", "Nazwisko6"));
- company.addEmployee(new Employee("Imie7", "Nazwisko7"));
- company.addEmployee(new Employee("Imie8", "Nazwisko8"));
- company.addEmployee(new Employee("Imie9", "Nazwisko9"));
- company.addEmployee(new Employee("Imie10", "Nazwisko10"));
- company.printCompanyEmployees();
- company.addEmployee(new Employee("Imie11", "Nazwisko11"));
- company.deleteEmployee(new Employee("Imie5", "Nazwisko5"));
- company.addEmployee(new Employee("Imie11", "Nazwisko11"));
- company.printCompanyEmployees();
- company.fireWholeCompany();
- company.printCompanyEmployees();
- company.deleteEmployee(new Employee("Imie11", "Nazwisko11"));
- company.addEmployee(new Employee("Imie9", "Nazwisko9"));
- company.addEmployee(new Employee("Imie10", "Nazwisko10"));
- company.addEmployee(new Employee("Imie3", "Nazwisko3"));
- company.addEmployee(new Employee("Imie4", "Nazwisko4"));
- company.addEmployee(new Employee("Imie5", "Nazwisko5"));
- company.addEmployee(new Employee("Imie6", "Nazwisko6"));
- company.addEmployee(new Employee("Imie7", "Nazwisko7"));
- company.printCompanyEmployees();
- }
- }
- /**
- * Created by Scy on 03/12/2016.
- */
- public class Employee {
- private String imie;
- private String nazwisko;
- public Employee(String imie, String nazwisko)
- {
- this.imie=imie;
- this.nazwisko=nazwisko;
- }
- public boolean compareTo(Employee emp)
- {
- if(this.imie.compareToIgnoreCase(emp.getImie())==0 && this.nazwisko.compareToIgnoreCase(emp.getNazwisko())==0)
- {
- return true;
- }
- else return false;
- }
- public String getImie() {
- return imie;
- }
- public String getNazwisko() {
- return nazwisko;
- }
- public String toString()
- {
- return this.imie+" "+this.nazwisko;
- }
- }
- /**
- * Created by Scy on 03/12/2016.
- */
- public class Company {
- private int maxEmployees=10;
- private int currentEmployeeCount=0;
- private Employee[] company= new Employee[this.getMaxEmployees()];
- public int getMaxEmployees()
- {
- return this.maxEmployees;
- }
- private boolean isFull()
- {
- if(this.currentEmployeeCount==this.maxEmployees)
- {
- return true;
- }
- else return false;
- }
- private boolean isEmpty()
- {
- if(this.currentEmployeeCount==0)
- {
- return true;
- }
- else return false;
- }
- public void addEmployee(Employee emp)
- {
- if(this.isFull())
- {
- System.out.println("Company is full.");
- }
- else
- {
- this.company[this.findFirstEmptySlot()] = emp;
- this.currentEmployeeCount++;
- }
- }
- public void deleteEmployee(Employee emp)
- {
- int counter=0;
- if(!this.isEmpty()) {
- for (int i = 0; i < this.company.length; i++) {
- if (emp.compareTo(this.company[i])) {
- counter++;
- this.company[i] = null;
- }
- }
- System.out.println("Usunieto "+counter+" pracowników.");
- this.currentEmployeeCount-=counter;
- }
- else System.out.println("Firma jest pusta");
- }
- public void fireWholeCompany()
- {
- if(!this.isEmpty()) {
- for (int i = 0; i < this.company.length; i++) {
- this.company[i] = null;
- }
- this.currentEmployeeCount = 0;
- }
- }
- private int findFirstEmptySlot()
- {
- int result=this.maxEmployees+1;
- for(int i=0; i<this.company.length; i++)
- {
- if(company[i]==null)
- {
- result=i;
- return result;
- }
- }
- return result;
- }
- public void printCompanyEmployees()
- {
- if(!this.isEmpty()) {
- for (Employee emp : this.company) {
- if (emp != null)
- System.out.println(emp.toString());
- }
- }
- else System.out.println("Firma jest pusta");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement