Home Page > > Details

Lab 4 Requirements

Lab 4 Requirements
Create a new Eclipse workspace named "Lab4_1234567890" on the desktop of your computer (replace 
1234567890 with your student ID number). For each question below, create a new project in that workspace. Call 
each project by its question number: "Question1", "Question2", etc. If you do not remember how to create a 
workspace or projects, read the "Introduction to Eclipse" document which is on iSpace. Answer all the questions below.
At the end of the lab, create a ZIP archive of the whole workspace folder. The resulting ZIP file must be called 
"Lab4_1234567890.zip" (replace 1234567890 with your student ID number). Upload the ZIP file on iSpace.
Question 1
Create a class Employee that contains the following things:
• a private integer ID number; • a constructor that takes as argument an ID number and uses this ID number to initialize the object's ID number; • a public method getID that takes zero argument and returns the ID number of the employee; • a public static method testEmployee that contains tests for your class.
Here is the corresponding UML diagram (remember that + means public and - means private):
+--------------------------+
| Employee | +--------------------------+
| - ID: int |
+--------------------------+
| + Employee(int ID) |
| + getID(): int |
| + testEmployee():void | +--------------------------+
The Employee class does not have a setID method because the ID number of an employee never changes.
How many tests should the testEmployee method contain?
Once you have written the Employee class, you can test it by adding the following code in a new class called Start in 
the same project:
public class Start {
public static void main(String[] args) {
Employee.testEmployee();
} }
This code calls the static testEmployee method of the Employee class, which should then run all your tests.
What is the problem if you make the ID instance variable public?
Question 2
Modify the constructor of the Employee class so that negative ID numbers or ID numbers larger than 10000 are not 
allowed when creating an Employee object. If the constructor is given a negative ID number or a ID number larger than 
10000 as the argument, then the constructor should use 0 for the ID number.
Modify your testEmployee method to test the new code. How many tests should the testEmployee method now 
contain?
Question 3
Add to your Employee class a string representing the position of the employee. The constructor for the class should 
now take the position of the employee as an extra argument. Also add to your class two methods getPosition and 
setPosition to get and change the position of an employee (an employee is allowed to change position).
Here is the corresponding UML diagram:
+------------------------------------+
| Employee | +------------------------------------+
| - ID: int |
| - position: String | +------------------------------------+
| + Employee(int ID, String position)|
| + getID(): int |
| + getPosition(): String |
| + setPosition(String position):void|
| + testEmployee(): void | +------------------------------------+
Note: we have not talked much about the String type in class yet. For now just use it like you use any other type (like 
int or float).
Do not forget to modify your testEmployee method to test the new code. In Java you can use == to compare 
constant strings.
Question 4
Add to your Employee class an integer representing the salary of the employee. The default salary when an employee 
is created is 3000. Also add to your class two methods getSalary and setSalary to get and change the salary of 
an employee.
Here is the corresponding UML diagram:
+------------------------------------+
| Employee | +------------------------------------+
| - ID: int |
| - position: String |
| - salary: int | +------------------------------------+
| + Employee(int ID, String position)|
| + getID(): int |
| + getPosition(): String |
| + setPosition(String position):void|
| + getSalary(): int |
| + setSalary(int salary): void |
| + testEmployee(): void | +------------------------------------+
Do not forget to modify your testEmployee method to test the new code.
Question 5
Add a new constructor to your Employee class that takes three arguments as input: an ID number, a position, and an 
initial salary. Using this second constructor it becomes possible to create Employee objects with an initial salary which 
is different from 3000.
Here is the corresponding UML diagram:
+------------------------------------------------+
| Employee | +------------------------------------------------+
| - ID: int |
| - position: String |
| - salary: int | +------------------------------------------------+
| + Employee(int ID, String position) |
| + Employee(int ID, String position, int salary)|
| + getID(): int |
| + getPosition(): String |
| + setPosition(String position):void |
| + getSalary(): int |
| + setSalary(int salary): void |
| + testEmployee(): void | +------------------------------------------------+
Do not forget to modify your testEmployee method to test the new code.
Question 6
Add to your Employee class a Boolean indicating whether the employee is currently playing the mobile phone during 
working hours. When an employee is created, the employee is working and not playing the mobile phone. Also add to 
your class three methods:
• one method isPlaying that returns a Boolean indicating whether the employee is currently playing the phone or 
not. • one method goToPlay that makes the employee stops working and starts to play the mobile phone. When an
employee starts to play the mobile phone, the salary of the employee decreases by 100 (if the current salary is less 
than 100, then the salary decreases to 0).
• one method goTOWork that makes the employee stop playing the mobile phone and start working. The salary of an
employee does not increase.
Here is the corresponding UML diagram:
+------------------------------------------------+
| Employee | +------------------------------------------------+
| - ID: int |
| - position: String |
| - salary: int |
| - playing: Boolean | +------------------------------------------------+
| + Employee(int ID, String position) |
| + Employee(int ID, String position, int salary)|
| + getID(): int |
| + getPosition(): String |
| + setPosition(String position):void |
| + getSalary(): int |
| + setSalary(int salary): void |
| + isPlaying():Boolean |
| + goToPlay():void |
| + goToWork():void |
| + testEmployee(): void | +------------------------------------------------+
Do not forget to modify your testEmployee method to test the new code.
Contact Us - Email:99515681@qq.com    WeChat:codinghelp
Programming Assignment Help!