Question mplement the following class diagrams as follows. Note that you CANNOT
ID: 3601428 • Letter: Q
Question
Question mplement the following class diagrams as follows. Note that you CANNOT use any classes in the Collections Frameworks such as ArrayList, LinkedList etc Each class implement the Displayable interface and the display method should display all the current object's and its superclass object's information. Define appropriate parameters properly so that all the objects can be created properly Define appropriate set and get methods if needed in other classes' methods Displayable ants + display0:void + MAX-EMPLOYEES: 1000 : int Company - empld: int #employees : Employee # numEmployees : int salary : double * +Company( + addEmployee(employee) : void +getSalary0:double url: String + getEmployeesHighSalary(double limit) : Employee! /. employees who have salary more than limitExplanation / Answer
//Defining interface
interface Displayable{
public void display();
}
//Implementing Employee class
class Employee implements Displayable{
//declaring the specified instance variables
int empid;
double salary;
//defining constructor for Employee class
Employee(int empid,double salary){
this.empid=empid;
this.salary=salary;
}
//defining getSalary() method
double getSalary(){
return this.salary;
}
//Implementing method of Displayable Interface
public void display(){
System.out.println("Employee Id is"+this.empid);
System.out.println("Employee Salary is "+this.salary);
}
}
//Implementing CompanyConstants class
class CompanyConstants{
final int MAX_EMPLOYEES=1000;
}
//Implementing Company class
class Company extends CompanyConstants implements Displayable{
String compName;
Employee employees[];
int numEmployees;
//defining constructor for Company class
Company(String compName,Employee employees[],int numEmployees){
this.compName=compName;
this.employees=employees;
this.numEmployees=numEmployees;
}
Company(String compName){
this.compName=compName;
this.numEmployees=0;
}
//defining addEmployee() method
void addEmployee(Employee employee){
if(numEmployees>=MAX_EMPLOYEES){
System.out.println("Maximum Employees reached");
}
else{
this.employees[numEmployees]=employee;
numEmployees++;
}
}
//defining display method
public void display(){
System.out.println("Max employees is "+MAX_EMPLOYEES);
System.out.println("Company Name:"+this.compName);
System.out.println("Number of employees:"+this.numEmployees);
System.out.println("Employees are:");
for(int i=0;i<this.numEmployees;i++){
System.out.print("Employee"+i);
employees[i].display();
}
}
}
class InternetCompany extends Company{
String url;
//constructor
InternetCompany(String url,String compName){
super(compName);
this.url=url;
}
//defining the method to get employees whose salary is above the limit
Employee[] getEmployeesHighSalary(double limit){
int current=0;
Employee aboveLimit[]=new Employee[this.numEmployees];
for(int i=0;i<this.numEmployees;i++){
if(this.employees[i].salary>limit){
aboveLimit[current]=this.employees[i];
current++;
}
}
return aboveLimit;
}
}
I edited the code and cleared all the errors,please check it and if you want to perform any operation using this please specify it or define your own class to implement the main method to use all the above classses and functionalities.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.