Assignment 01 Fall 2020
Assignment 01 Fall 2020
37975
ITC 225 Programming II
Dr. Ahmad Aljanad
Fall 2020
Assignment 01 (ITC 225)
1) Imagine a company that has multiple levels of employees, from the managers,
executives down to clerk. Draw the object relationship diagram that shows a class of
Employees, where data like Employee No (integer), name, address and tel. no are
stored. Directly derived from the Employee class, are three other classes, which are
Managers, Executives and Clerks.
(1 mark)
a) From the object relationship diagram in the question above, program the class Employee. It
should have:
- (public) constructor: set the employeeNo to 0, name to “John Doe”, address to
“nowhere” and tel no to “n/a”.
- (public) insertData() function to insert all the data members from the user
- (public) and a displayData() function to display the value of all the data members.
(1 mark)
package assignment.pkg1;
import java.util.Scanner;
public Employee() {
employeeNo = 0;
name = "John Doe";
address = "nowhere";
telNo = "n/a";
}
Data members
a. (private) jobTitle : the title of the manager’s job i.e. “General Manager”
b. (private) companyCar: the company’s car the manager entitled to.
Function members
package assignment.pkg1;
public class Manager extends Employee{
private String jobTitle;
private String companyCar;
public Manager(){
jobTitle = "unknown";
companyCar = "unknown";
}
@Override
public void insertData(){
System.out.println("Enter Employee's jobTitle: ");
jobTitle = input.next();
System.out.println("Please Enter company‘s Car: ");
companyCar = input.next();
}
@Override
public void displayData(){
System.out.println("Employee's JobTitle: "+ jobTitle);
System.out.println("Company’s Car: "+ companyCar);
}
}
c) In the main function, create an object E of the class Employee. Use the displayData() function
and you should have this displayed on the screen:
(1 mark)
package assignment.pkg1;
public class Assignment1 {
public static void main(String[] args) {
Employee E = new Employee();
E.displayData();
Output:
d) Now create an object M of the class Managers. Use the insertData() function and later the
displayData function, refer to the screenshot below:
(1 mark)
package assignment.pkg1;
public class Assignment1 {
public static void main(String[] args) {
Manager M = new Manager();
M.insertData();
M.displayData();
Output:
e) Create a class Executives, which is also derived from the class Employee. For this class, include:
Data member
- (private) dept: the dept where the executive is assigned to i.e. “IT”
Function members
(1 mark)
package assignment.pkg1;
public class Executives extends Employee{
private String dept;
public Executives(){
dept = "unknown";
}
@Override
public void insertData(){
System.out.println("Executives: ");
super.insertData();
System.out.println("Enter Employee's Department: ");
dept = input.next();
}
@Override
public void displayData(){
System.out.println("Executives...........");
super.displayData();
System.out.println("Employee's department is: "+dept);
}
}
f) Create a class Clerks, which is also derived from the class Employee. For this class, include:
Data members
Function members
public Clerks(){
overTimeHour = 0;
overTimeHour = 0;
}
@Override
public void insertData(){
System.out.println("Clerks");
super.insertData();
System.out.println("Please enter overtime rate: ");
overTimeRate = input.nextDouble();
System.out.println("Please enter overtime hour: ");
overTimeHour = input.nextDouble();
}
@Override
public void displayData(){
System.out.println("Clerks...........");
super.displayData();
System.out.println("Employee's overtime Rate: "+overTimeRate);
System.out.println("Employee's overtime Hour: "+overTimeHour);
System.out.println("Employee's Total overtime:
"+overTimeHour*overTimeRate);
}
}
g) In the main function, create object Ex of the class Executives and object C of the Clerks object.
Display the data members of these objects right after you have created them. Example of result:
package assignment.pkg1;
Ex.displayData();
C.displayData();
Output:
h) Now use the insertData() function to insert data into the object Ex and C.
Executives -----
Ahmed
Kabul
0709
IT
Clerks -----
99
Ali
88
90
Executives -----
Employee's Number : 1
Employee's department: IT
Clerks -----
Employee's Number : 99
Employee's Name : 88
(1 mark)
package assignment.pkg1;
public class Assignment1 {
public static void main(String[] args) {
Executives Ex = new Executives();
Clerks C = new Clerks();
Ex.insertData();
C.insertData();
Ex.displayData();
C.displayData();
}
}
Output:
2) Create an abstract class MotorVehicle with the following details:
Data Members:
(a) modelName (b) modelNumber (c) modelPrice
Methods:
(a) display() to show all the details :
(2 Marks)
package assignement.pkg11;
Create a subclass of this class Car that inherits the class MotorVehicle and add the following
details:
Data Members:
(a) discountRate
Methods:
(a) display() method to display the Car name, model number, price and the discount rate.
(b) discount() method to compute the discount.
package assignement.pkg11;
Output: