ITZone

Programming OOP with Java

OOP stands for Object-Oriented Programming. Meaning object-oriented programming.

There are 4 properties in OOP:

  1. Abstraction
  2. Inheritance
  3. Polymorphism
  4. Packing properties

To understand more about OOP, we do the following problem:

A university managing staff information (including lecturers and administrative staff) in the school. With lecturers need to manage information: name, faculty, level (bachelor, master, doctor), allowance, number of lessons taught in the month, salary coefficient. For administrative staff to manage: Full name, department, number of working days, salary, allowance, position (head, deputy, staff). Staff allowance is calculated according to the table: Bachelor of 300. Master of 500. Doctor of 1000. Head of Department 2000. Deputy Head of Division 1000. Employee 500. The salary of lecturers is calculated as follows: Salary coefficient x 730 + allowance + number of lessons x 45. Staff salaries are calculated as follows: Salary x 730 + allowances + number of work days x 30;

Write a school information management program that includes the following functions:

  1. Data entry for school officials.
  2. Search for staff by name and department and print out a detailed information screen for this employee.
  3. Export a list of all teachers in the school and arrange alphabetically, if the names are the same, sort by the salary received from high to low. (Note, the list of lecturers and staff is printed with the salary information column) Requirements: Applying knowledge of object-oriented programming to build the program. Proficient in abstraction, packaging, polymorphism, inheritance and applying abstract class and interface in the lesson. The main function only makes calls to functions without writing any other business.

This is my code to handle the problem on: https://github.com/nguyenvanthieub/OOP

Here, I created interface ICanBo with abstract method tinhLuong ()

Let 2 classes subclass JiangVien and NhanVien to be redundant (implements ICanBo) (expressing inheritance).

Because both GiangVien and NhanVien have the same attributes: hoTen, heSoLuong, phuCap, luong. I have created abstract class CanBo, let GiangVien class and NhanVien inherit to avoid being duplicated code for both GiangVien and NhanVien classes to write (expressing abstraction)

From there, 2 subclasses GiangVien and NhanVien process themselves (override) method tinhLuong () to suit the problem. (represents polymorphism) The example below is the NhanVien class

To ensure packing, I have left the properties to private, other classes want to access the properties of NhanVien, then getter, setter I created.

ITZone via Viblo.asia

Share the news now