Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
The Below is the code for the Employee class with the requested constructor and set method pub...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started