Question: Write code for Employee class. Assume the following code is given. class Employee ( private int id; private String name; private int age: //

Write code for Employee class. Assume the following code is given. class Employee ( private int id; private

Write code for Employee class. Assume the following code is given. class Employee ( private int id; private String name; private int age: // employee id // employee name // employee age public int getAge() { return age; } // return age // In (a) and (b) below, you need to write 2 methods // for the Employee class here (a) Write a constructor method with no input arguments for the Employee class. Set the default id to 0, the default name to "Unknown", the default age to 1. Show the method header clearly. // write your code here (b) Write the set() method for the Employee class (see header below); set id to newID, name to new Name, age to newAge. You must check that newAge is > 0. If newAge is not in the correct range, print an error message and return immediately, without changing any of the member variables of the Employee object. void set(int newID, String newName, int newAge) // your code go here 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The Below is the code for the Employee class with the requested constructor and set method pub... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!