Docsity

Java programming. Exercise session III, Slides of Java Programming

Toggle sidebar
bg1
Java programming. Exercise session III
(based on MIT 6.092 Assignment 2)
In this exercise session, you will use data and the program created in exercise session II. The Database of employees
in FooCorporation has to be created. The database has to contain 2 types of employees: Employee and Manager.
Exercise instructions:
1. Create a new class called FooCorporation.
2. Create a new class called Employee in the same package with FooCorporation.
3. Write a constructor for Employee class with the following parameters:
- name;
- professional level;
- base pay;
- hours worked.
4. Extend method salary, that takes Employee parameters and prints the total pay, with following rules:
• For every hour over 40, they get overtime = (base pay) × 1.5.
• The base pay must not be less than the minimum wage ($8.00 an hour). If it is, print an error.
5. Define method office that defines type of working place based on professional level:
• An employee with professional level ‘A’ possesses a individual office room.
• An employee with professional level ‘B’ possesses a cubicle.
6. Create a class called Manager that inherits parameters (fields) and methods from class Employee. Add
hasOffice method to Manager class that checks if the manager has an individual room.
7. Create an employee database (using ArrayList) with the following data:
Professional level
Base Pay
Hours Worked
Employee John
B
$8.50
35
Employee Graham
B
$9.00
37
Employee Annabel
A
$9.20
43
Employee Margaret
B
$7.80
45
Professional level
Base Pay
Hours Worked
Manager Bill
A
$15.00
49
Manager Gregory
A
$16.50
47
Core structure of FooCorporation class:
import java.util.*;
public class FooCorporation {
public static void main(String[] args) {
// Define parameters of employees given in the table
(define array list) employeeList;
for ( ) {
// Create an object for each employee with relevant parameters
employeeList.add(newEmployee);
}
for () { // Use enhance looping
System.out.println("The employee name is " + employee.name + "\n");
// Compute salary and define a working place for each employee
}
}
}
pf2

Partial preview of the text

Download Java programming. Exercise session III and more Slides Java Programming in PDF only on Docsity!

Java programming. Exercise session III

(based on MIT 6.092 Assignment 2)

In this exercise session, you will use data and the program created in exercise session II. The Database of employees in FooCorporation has to be created. The database has to contain 2 types of employees: Employee and Manager.

Exercise instructions:

  1. Create a new class called FooCorporation.
  2. Create a new class called Employee in the same package with FooCorporation.
  3. Write a constructor for Employee class with the following parameters:
    • name;
    • professional level;
    • base pay;
    • hours worked.
  4. Extend method salary, that takes Employee parameters and prints the total pay, with following rules:
    • For every hour over 40, they get overtime = (base pay) × 1.5.
    • The base pay must not be less than the minimum wage ($8.00 an hour). If it is, print an error.
  5. Define method office that defines type of working place based on professional level:
    • An employee with professional level ‘A’ possesses a individual office room.
    • An employee with professional level ‘B’ possesses a cubicle.
  6. Create a class called Manager that inherits parameters (fields) and methods from class Employee. Add hasOffice method to Manager class that checks if the manager has an individual room.
  7. Create an employee database (using ArrayList ) with the following data:

Professional level Base Pay Hours Worked

Employee John B $8.50 35

Employee Graham B $9.00 37

Employee Annabel A $9.20 43

Employee Margaret B $7.80 45

Professional level Base Pay Hours Worked Office number

Manager Bill A $15.00 49 A

Manager Gregory A $16.50 47 A

Core structure of FooCorporation class:

import java.util.*;

public class FooCorporation {

public static void main(String[] args) { // Define parameters of employees given in the table ( define array list ) employeeList; for ( ) { // Create an object for each employee with relevant parameters employeeList.add(newEmployee); } for () { // Use enhance looping System. out .println("The employee name is " + employee.name + "\n"); // Compute salary and define a working place for each employee } } }

public class Employee { // Store the class in separate file // Create a constructor for the class with 2 methods: salary, office }

public class Manager extends Employee { // Create a constructor for the class with a method hasOffice }