Java

OOP GUIDE / WORK

 

LATESLIP CLASS

 

Topics

  • Encapsulation
  • Simple class design
  • Using objects

 

 

TASK – PART 1 – LATESLIP CLASS: INSTANCE VARIABLES

 

You will create and test a LateSlip class that represents a typical late slip from the office.

 

Your class should have the following instance variables.

 

private String name;        //student's name

private String date;        //date issued

private String time;        //time issued

private char code;          //'L', 'A' or 'E'  (Late, Admit or Excused)

private String author;      //person giving the slip

private boolean detention;  //whether the student is getting detention or not

 

 

TASK – PART 2 – LATESLIP CLASS: CONSTRUCTORS

 

The class should have two constructors.

 

One constructor should get a value for each of the instance variables.

 

The other constructor should get a value for the first five instance variables (not detention) and simply set detention to false. 

 

 

TASK – PART 3 – LATESLIP CLASS: METHODS

 

Create get methods for all instance variables (6 methods). 

 

Create a addDetention() method that sets the detention instance variable to true.

Create a toString() method that returns a String that represents the form of a late slip (see example below).  Note that placing “\n” in a string actually places an ENTER character so that your string can be on multiple lines.

 

 

LOCKERBY COMPOSITE SCHOOL SLIP

Student: Pat Camp

Date: Oct 11, 2022

Time: 9:26AM

LATE   Admit   Excused

Authorized by: Mr. Lafraniere

HAS DETENTION

 

 

 

TASK – PART 4 – TESTING

 

In the main of a Tester class, give yourself a lateslip from the vice principal.  Output it to screen.

 

Also in the main, create another late slip that initially has no detention.  Output it to screen.  Then use the addDetention() method and re-output it to screen to see how the slip is different.