This is the task we looked at in class today.
Notes:
- Don’t get mixed up between returning a value and printing a value. Your methods should only print if the questions explicitly tells you to print.
- Notice that definition of the Employee (the class) is totally separate from the instantiation of Employees (objects).
- There is no constructor here, but you will be expected to create them in your quiz.
- You will also need to correctly specify method headers. The method header for the isTeacher method, for example, is boolean isTeacher(). Method headers always have the form [return type] methodName (parameter 1, parameter 2, …), where you need to decide what the return type is, you need to decide what the name is, and you need to decide what, if any, parameters there are.
Here is the code that I would consider to be a perfect answer.
package employeemain; public class EmployeeMain { public static void main(String[] args) { Employee e = new Employee(); e.name = "Mr Robertson"; e.jobTitle = "teacher"; e.department = "Computer Science"; e.salary = 10000; if (e.isTeacher()){ e.sayHello(); } } } class Employee{ String name; String jobTitle; String department; double salary; void sayHello(){ System.out.println("Hello. My name is " + name + ". I am a " + jobTitle + " and I work in the " + department + " department."); } boolean isTeacher(){ return jobTitle.equalsIgnoreCase("teacher"); } }