Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package labtest;
- class Employee
- public class Employee {
- protected String name;
- protected double salary;
- Employee() {
- this.name = "Unknown";
- }
- Employee(String name) {
- this.name = name;
- }
- public int getHours() {
- return 40; // works 40 hours / week
- }
- public double getSalary() {
- return 40000.0; // $40,000.00 / year
- }
- public int getVacationDays() {
- return 10; // 2 weeks' paid vacation
- }
- public String getVacationForm() {
- return "yellow"; // use the yellow form
- }
- }
- class HarvardLawyer
- package labtest;
- public class HarvardLawyer extends Employee{
- @Override
- public int getVacationDays() {
- return super.getVacationDays() + 3; // 3 weeks vacation
- }
- @Override
- public String getVacationForm() {
- return super.getVacationForm() + super.getVacationForm();
- }
- @Override
- public double getSalary() {
- double x;
- x= (super.getSalary() * 20/100);
- return super.getSalary()+x; // 20% more make salary / year
- }
- }
- class Lawyer
- package labtest;
- public class Lawyer extends Employee{
- @Override
- public int getVacationDays() {
- return super.getVacationDays() + 5; // 3 weeks vacation
- }
- @Override
- public String getVacationForm() {
- return "pink";
- }
- public void sue() {
- System.out.println("I'll see you in court!");
- }
- }
- class LegalSecretary
- package labtest;
- public class LegalSecretary extends Secretary {
- @Override
- public double getSalary() {
- return super.getSalary() + 5000.0; // $45,000.00 / year
- }
- public void fileLegalBriefs() {
- System.out.println("I could file all day!");
- }
- }
- class Manager
- package labtest;
- public class Manager extends Employee {
- Employee employees[];
- Manager(String name) {
- super(name);
- this.employees = new Employee[4];
- }
- public void manage() {
- System.out.println("Follow my order");
- }
- @Override
- public double getSalary() {
- int i;
- double sum=0;
- for(i=0;i<employees.length;i++)
- {
- sum = sum+employees[i].salary;
- }
- return sum; // Write your code here
- }
- }
- class Secretary
- package labtest;
- public class Secretary extends Employee{
- public void takeDictation(String text) {
- System.out.println("Taking dictation of text: " + text);
- }
- }
- Main Class........
- package labtest;
- import java.util.Random;
- public class Test {
- public static void main(String[] args) {
- Manager managers[] = new Manager[2];
- managers[0] = new Manager("Pele");
- managers[1] = new Manager("Zidane");
- managers[0].employees[0] = new Employee("Mbappe");
- managers[0].employees[1] = new Employee("Ronaldo");
- managers[0].employees[2] = new Employee("Ballack");
- managers[0].employees[3] = new Employee("Messi");
- managers[1].employees[0] = new Employee("Kylian");
- managers[1].employees[1] = new Employee("Cristiano");
- managers[1].employees[2] = new Employee("Michael");
- managers[1].employees[3] = new Employee("Lionel");
- Random random = new Random();
- for(int i =0; i<2; i++){
- for (int j=0; j<4; j++) {
- int randomMark = random.nextInt(100000);
- managers[i].employees[j].salary = randomMark; // randomMark is an integer from 0 to 99999
- // assign mark to the jth Employee of ith Manager here
- System.out.print(randomMark + " ");
- }
- System.out.println();
- }
- System.out.println(managers[0].getSalary());
- System.out.println(managers[1].getSalary());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement