CSYM025 Week 6 Lab Exercises
CSYM025 Week 6 Lab Exercises
Lab Exercises:
1. Design a class named Employee. The class should keep the following
information in fields:
Employee Name
Employee number In the format XXXX-L, where each X Is
a digit within the range 0-9 and the L is a letter within the
range A-M
Hire date
Write one or more constructors and the appropriate accessor and
mutator methods for the class.
Next, write a class named ProductionWorker that extends the
Employee class. The ProductionWorker class should have fields to
hold the following information:
Shift (an Integer)
Hourly pay rate (a double)
The workday is divided into two shifts:day and night. The shift field
will be an integer value representing the shift that the employee
works. The day shift is shift 1 and the night shift is shift 2. Write one
or more constructors and the appropriate accessor and mutator
methods for the class. Design class diagrams and demonstrate the
classes by writing a program that uses a ProductionWorker object.
The program should store this data in the three objects, compare any two
objects using the equals method, then display the data for each employee
on the screen using the toString method. Save the main program as
EmployeeData.java.
Part 2:
Rectangle Circle
Area width * height 3.1415 * radius *
radius
Perimeter 2(width * height) 2 * 3.1415 * radius
3. a. Create an abstract class named Book. Include a String field for the
book's title and a double field for the book's price. Within the class,
include a constructor that requires the book title, and two get methods-
one that returns the title and one that returns the price. Include an
abstract method named setPrice(). Create two child classes of Book:
Fiction and NonFiction. Each must include a setPrice() method that
sets the price for all Fiction Books to £24.99 and for all NonFiction
Books to £37.99. Write a constructor for each subclass, and include a
call to setPrice() within each. Write an application demonstrating that
you can create both a Fiction and a NonFiction Book, and display
their fields. Save the files as Book.java, Fiction.java, NonFiction.java,
and UseBook.java.
b. Think of two more objects that use turn(), create classes for them,
and then add objects to the DemoTurners application, renaming It
DemoTurners2.java. Save the files, using the names of new objects
that use turn().
Sample Run:
Enter an id: 3
Main menu
1: check balance
2: withdraw
3: deposit
4: exit
Enter a choice: 1
The balance is 50.0.
Main menu:
1: check balance
2:withdraw
3: deposit
4:exit
Enter a choice:4
Enter an id: