posted 3 years ago
First I had addEmployee() to create employees. The output was:
Type: ENGINEER, id: 1, monthly salary: 1000.0, commission: 0.0, bonus: 0.0, manager: 4.
Type: ENGINEER, id: 2, monthly salary: 1000.0, commission: 0.0, bonus: 0.0, manager: 4.
Type: SALESMAN, id: 3, monthly salary: 1000.0, commission: 100.0, bonus: 0.0, manager: 4.
Type: MANAGER, id: 4, monthly salary: 2000.0, commission: 0.0, bonus: 1000.0.
Because of inheritance I splitted up to addEngineer(), addSalesman() and addManager(). Now the output is:
Type: ENGINEER, id: 1, monthly salary: 1000.0, manager: 3.
Type: ENGINEER, id: 2, monthly salary: 1000.0, manager: 3.
Type: ENGINEER, id: 1, monthly salary: 1000.0, manager: 3. <-- must actually be skipped
Type: SALESMAN, id: 3, monthly salary: 1000.0, commission: 100.0.
Type: MANAGER, id: 4, monthly salary: 2000.0, bonus: 1000.0.
But the duplicate engineer must actually be skipped if instance already exists. I already wrote an if..else statement.
How can I skip creating an object when an object already exists?