Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package eleven1;
- public class Employee {
- public String name;
- public int workID, salary;
- public Employee(String n, int wid, int s) {// constructor for employee
- this.name = n;
- if (wid > 1000) {// checking if work id is over 1000
- this.workID = wid;
- }
- this.salary = s;
- }
- public String toString() {// output for employee
- return "Employee name " + this.name + " work ID " + this.workID + " salary " + this.salary;
- }
- public int calcBonus() {// adding bonus to employee
- return this.salary + 0;
- }
- public void updateSalary(int r) {// updating employee salary
- this.salary = r;
- }
- }
- ------------------------------------------------------------------------------------------------------------------------
- package eleven1;
- public class Programmer extends Employee {
- public Programmer(String n, int wid, int s) {// constructor for programmer
- super(n, wid, s);
- }
- public String toString() {// output for programmer
- return super.toString();
- }
- public int calcBonus() {// adding bonus to programmer
- return (int) (super.salary * 1.5);
- }
- }
- ------------------------------------------------------------------------------------------------------------------------
- package eleven1;
- public class Secratry extends Employee {
- public int numOfLetters;
- public Secratry(String n, int wid, int s, int nof) {// constructor for secratry
- super(n, wid, s);
- this.numOfLetters = nof;
- }
- public String toString() {// output for secratry
- return super.toString();
- }
- public int calcBonus() {// adding bonus to secratry
- return super.salary + 500;
- }
- }
- ------------------------------------------------------------------------------------------------------------------------
- package eleven1;
- public class MainWorker {
- public static void main(String[] args) {
- Programmer e1 = new Programmer("Chai", 9193, 7500);// creating programmer
- Secratry e2 = new Secratry("Tal", 5555, 7000, 100);// creating secratry
- System.out.println(e1);// output for programmer
- System.out.println(e2);// output for secratry
- e1.updateSalary(8000 + e1.calcBonus());// updating salary with bonus for programmer
- e2.updateSalary(7500 + e2.calcBonus());// updating salary with bonus for secratry
- System.out.println(e1);// output for programmer
- System.out.println(e2);// output for secratry
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement