Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package workforce;
- import java.util.Scanner;
- public class WorkForce {
- static class Person
- {
- String name;
- String email;
- int age;
- public Person(){}
- public Person(String name, String email, int age)
- {
- this.name = name;
- this.email = email;
- this.age = age;
- }
- public void Identify()
- {
- System.out.println("Name " + name);
- System.out.println("Email: " + email);
- System.out.println("Age: " + age);
- }
- public String getName()
- {
- return name;
- }
- public String getEmail()
- {
- return email;
- }
- public int getAge()
- {
- return age;
- }
- }
- interface Worker
- {
- int getSalary();
- }
- interface AcademicInterest
- {
- String getInterest();
- }
- static class Student extends Person implements AcademicInterest
- {
- int avgrade;
- String interest;
- public Student(String name, String email, int age, int avgrade, String interest)
- {
- super(name, email, age);
- this.avgrade = avgrade;
- this.interest = interest;
- }
- @Override
- public String getInterest() {
- return interest;
- }
- public int getAvgrade()
- {
- return avgrade;
- }
- }
- static class Teacher extends Person implements Worker, AcademicInterest
- {
- int rating;
- int salary;
- String interest;
- public Teacher(String name, String email, int age, int rating, int salary, String interest)
- {
- super(name, email, age);
- this.interest = interest;
- this.rating = rating;
- this.salary = salary;
- }
- int getRating()
- {
- return rating;
- }
- @Override
- public int getSalary() {
- return salary;
- }
- @Override
- public String getInterest() {
- return interest;
- }
- @Override
- public void Identify()
- {
- System.out.println("Name " + name);
- System.out.println("Email: " + email);
- System.out.println("Age: " + age);
- System.out.println("S/He is a teacher.");
- }
- }
- static class Plummer extends Person implements Worker
- {
- int salary;
- public Plummer(String name, String email, int age, int salary)
- {
- super(name, email, age);
- this.salary =salary;
- }
- @Override
- public int getSalary() {
- return salary;
- }
- @Override
- public void Identify()
- {
- System.out.println("Name " + name);
- System.out.println("Email: " + email);
- System.out.println("Age: " + age);
- System.out.println("S/He is a plummer.");
- }
- }
- static void Menu()
- {
- System.out.println("Choose an option <enter its index>");
- System.out.println("1: Identify all workers with salary under 50k");
- System.out.println("2: Identify all Teachers with rating lesser than 8");
- System.out.println("3: Count people with the same academic interest");
- System.out.println("4: Group students and teachers that share the same academic interest and have average grade and rating lesser then 8");
- }
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- Person ppl[] = new Person[10];
- ppl[0] = new Person("Dan", "mit@gmail.com", 38);
- ppl[1] = new Plummer("John", "john@gmail.com", 48, 15000);
- ppl[2] = new Student("Jacob", "jacob@gmail.com", 24, 6, "Java");
- ppl[3] = new Student("Ian", "ian@gmail.com", 22, 8, "Java");
- ppl[4] = new Student("Coolio", "coolio@gmail.com", 25, 9, "Managment");
- ppl[5] = new Student("Mark", "Mark@gmail.com", 23, 8, "Java");
- ppl[6] = new Teacher("Fran", "fran@gmail.com", 48, 9, 80000, "Java");
- ppl[7] = new Teacher("Richie", "richie@gmail.com", 52, 8, 49900, "Java");
- ppl[8] = new Teacher("Roger", "roger@gmail.com", 39, 8, 70000, "Managment");
- ppl[9] = new Teacher("Homer", "homer@gmail.com", 42, 6, 40000, "Managment");
- int exit= 0;
- int choice = 0;
- for(;;)
- {
- if(exit != 0)
- {
- System.out.println("Do you like to list more? <1 - yes 2 - no");
- choice = s.nextInt();
- if (choice == 2)
- break;
- }
- Menu();
- choice = s.nextInt();
- if(choice == 1)
- {
- for(int i = 0; i < 10; i++)
- {
- if(ppl[i].isInstance(Plummer) || ppl[i].isInstance(Teacher))
- {
- if(ppl[i].getSalary < 50000)
- ppl[i].Identify();
- }
- }
- }
- if( choice == 2)
- {
- for(int i = 0; i < 10; i++)
- {
- if(ppl[i].isInstance(Teacher))
- {
- if(ppl[i].getRating < 😎
- ppl[i].Identify();
- }
- }
- }
- if(choice == 3)
- {
- int countJ = 0, countM = 0, countF = 0;
- for(int i = 0; i < 10; i++)
- {
- if(ppl[i].getInterest() == 'Java')
- {
- countJ++;
- }
- if(ppl[i].getInterest() == 'Managment')
- {
- countM++;
- }
- if(ppl[i].getInterest() == 'Finance')
- {
- countF++;
- }
- }
- System.out.println("Java: " + countJ);
- System.out.println("Managment: " + countM);
- System.out.println("Finance: " + countF);
- }
- if(choice == 4)
- {
- System.out.println("Teachers and Student with interest java and below 8");
- for(int i = 0; i < 9; i++)
- {
- if(ppl[i].isInstanceof(Teacher) && ppl[i].getRating < 8 && ppl[i].getInterest() == 'Java')
- {
- ppl[i].Identify();
- }
- if(ppl[i].isInstance(Student) && ppl[i].getAvgrade < 8 && ppl[i].getInterest() == 'Java')
- {
- ppl[i].Identify();
- }
- }
- System.out.println("Teachers and Student with interest managment and below 8");
- for(int i = 0; i < 9; i++)
- {
- if(ppl[i].isInstance(Teacher) && ppl[i].getRating < 8 && ppl[i].getInterest() == 'Managment')
- {
- ppl[i].Identify();
- }
- if(ppl[i].isInstance(Student) && ppl[i].getAvgrade < 8 && ppl[i].getInterest() == 'Managment')
- {
- ppl[i].Identify();
- }
- }
- System.out.println("Teachers and Student with interest finance and below 8");
- for(int i = 0; i < 9; i++)
- {
- if(ppl[i].isInstance(Teacher) && ppl[i].getRating < 8 && ppl[i].getInterest() == 'Finance')
- {
- ppl[i].Identify();
- }
- if(ppl[i].isInstance(Student) && ppl[i].getAvgrade < 8 && ppl[i].getInterest() == 'Finance')
- {
- ppl[i].Identify();
- }
- }
- }
- exit = 1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement