0% found this document useful (0 votes)
8 views1 page

Employee Management System Code

The document defines an interface IEmployee and its implementations, including MTEmployee and ConsEmployee, which manage collections of employee objects. It also includes abstract class AEmployee and its subclasses Admin, Doctor, and Technician, each with specific attributes and methods for salary calculation and service identification. Additionally, there is a test class IEmployeeTest that verifies the functionality of these classes through various assertions.

Uploaded by

pmdien000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Employee Management System Code

The document defines an interface IEmployee and its implementations, including MTEmployee and ConsEmployee, which manage collections of employee objects. It also includes abstract class AEmployee and its subclasses Admin, Doctor, and Technician, each with specific attributes and methods for salary calculation and service identification. Additionally, there is a test class IEmployeeTest that verifies the functionality of these classes through various assertions.

Uploaded by

pmdien000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

package test_thi;

public interface IEmployee {


int countDoctors();
IEmployee findByService(String service);
IEmployee insert(AEmployee other);
IEmployee sortBySalary();
}
package test_thi;
public class MTEmployee implements IEmployee {
@Override
public int countDoctors() {
return 0;
}
@Override
public IEmployee findByService(String service) {
return new MTEmployee();
}
@Override
public IEmployee insert(AEmployee other) {
return new ConsEmployee(other, new MTEmployee());
}
@Override
public IEmployee sortBySalary() {
return new MTEmployee();
}
@Override
public String toString() {
return "";
}
}
package test_thi;
public class ConsEmployee implements IEmployee {
AEmployee first;
IEmployee rest;
public ConsEmployee(AEmployee fisrt, IEmployee rest) {
[Link] = fisrt;
[Link] = rest;
}
@Override
public int countDoctors() {
if ([Link]()) {
return 1 + [Link]();
}
else {
return [Link]();
}
}
@Override
public IEmployee findByService(String service) {
if ([Link]() && [Link]().equals(service))
return new ConsEmployee([Link], [Link](service));
else return [Link](service);
}
@Override
public IEmployee insert(AEmployee other) {
if ([Link]() < [Link]())
return new ConsEmployee(other, this);
else return new ConsEmployee([Link], [Link](other));
}
@Override
public IEmployee sortBySalary() {
return [Link]().insert([Link]);
}
@Override
public String toString() {
return [Link]() + ([Link] instanceof MTEmployee ? "":", " + [Link]());
}
}
package test_thi;
public abstract class AEmployee {
String name;
String address;
double baseSalary;
public AEmployee(String name, String address, double baseSalary) {
[Link] = name;
[Link] = address;
[Link] = baseSalary;
}
public String getAddress() {
return address;
}
abstract boolean isDoctor();
abstract double getSalary();
abstract String getService();
@Override
public String toString() {
return [Link];
}
}
package test_thi;
public class Admin extends AEmployee {
int workDays;
public Admin(String name, String address, double baseSalary, int workDays) {
super(name, address, baseSalary);
[Link] = workDays;
}
@Override
boolean isDoctor() {
return false;
}
@Override
double getSalary() {
return [Link] * [Link];
}
@Override
String getService() {
return "";
}
}
package test_thi;
public class Doctor extends AEmployee {
String service;
int surgeries;
public Doctor(String name, String address, double baseSalary, String service, int surgeries) {
super(name, address, baseSalary);
[Link] = service;
[Link] = surgeries;
}
@Override
boolean isDoctor() {
return true;
}
@Override
double getSalary() {
return [Link] + [Link] * 100;
}
@Override
String getService() {
return [Link];
}
}
package test_thi;
public class Technician extends AEmployee {
int equipment;
public Technician(String name, String address, double baseSalary, int equipment) {
super(name, address, baseSalary);
[Link] = equipment;
}
@Override
boolean isDoctor() {
return false;
}
@Override
double getSalary() {
return [Link] + [Link] * 50;
}
@Override
String getService() {
return "";
}
}
package test_thi;
import [Link];
public class IEmployeeTest extends TestCase {
public void testConstructor() {
AEmployee nv1 = new Admin("Cô Hạnh", "Quận 1", 100, 20);
AEmployee nv2 = new Technician("Chú Ba", "Quận 5", 1000, 5);
AEmployee nv3 = new Doctor("Bác sĩ Tuấn", "Quận 3", 2000, "Nhi", 5);
AEmployee nv4 = new Doctor("Bác sĩ Hoa", "Quận 7", 3000, "Tim", 2);
IEmployee mt = new MTEmployee();
IEmployee l = new ConsEmployee(nv1, new ConsEmployee(nv2, new ConsEmployee(nv3, new ConsEmployee(nv4, mt))));
assertEquals("Quận 1", [Link]());
assertEquals("Quận 5", [Link]());
assertEquals("Quận 3", [Link]());
assertEquals("Quận 7", [Link]());
assertFalse([Link]());
assertFalse([Link]());
assertTrue([Link]());
assertTrue([Link]());
assertEquals(2000, [Link](), 0.001);
assertEquals(1250, [Link](), 0.001);
assertEquals(2500, [Link](), 0.001);
assertEquals(3200, [Link](), 0.001);
assertEquals(2, [Link]());
[Link]([Link]("Nhi"));
[Link]([Link]());
}
}

You might also like