Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //------------------ Employee - Base class ------------------
- public class Employee {
- protected String name;
- private static int idGenerator = 1000;
- protected double salary;
- protected int employID;
- public Employee(String name, double salary) {
- this.name = name;
- this.salary = salary;
- this.employID = idGenerator;
- idGenerator++;
- }
- public double getSalary() {
- return salary;
- }
- @Override
- public String toString() {
- return "Employee name is: " + this.name + ", his ID is: " + this.employID + ", and his salary is: " + this.salary + ".";
- }
- public double calcBonus() {
- return 0;
- }
- public void updateSalary(double newSalary) {
- this.salary = newSalary;
- }
- }
- //-------------------- Programmer ---------------------------------
- public class Programmer extends Employee{
- public Programmer(String name, double salary) {
- super(name, salary);
- }
- @Override
- public double calcBonus() {
- return super.getSalary()*1.5;
- }
- }
- //------------------------ Secretary -----------------------------
- public class Secretary extends Employee{
- private int wordsTypedPerMin;
- public Secretary(String name, double salary, int wordsTypedPerMin) {
- super(name, salary);
- this.wordsTypedPerMin = wordsTypedPerMin;
- }
- @Override
- public double calcBonus() {
- return super.getSalary()+500;
- }
- @Override
- public String toString() {
- return super.toString() + " In Addition, the secretary types: " + this.wordsTypedPerMin + " words per minute.";
- }
- }
- //------------------------------- Main class -------------------------
- public class EmpMain {
- public static void main(String[] args) {
- Programmer pr = new Programmer("Benny", 1200);
- Secretary sec = new Secretary("Gilad", 1000, 74);
- System.out.println(pr.toString());
- System.out.println(sec.toString());
- pr.updateSalary(pr.calcBonus());
- sec.updateSalary(sec.calcBonus());
- System.out.println(pr.toString());
- System.out.println(sec.toString());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement