CT044-3-1-IOOP Lab 10 – Classes and Constructors Page 1 of 2
1. Car Class
Create a class named Car that has the following properties:
Year – The Year property holds the car’s year model
Make- The Make property holds the make of the car
Speed- The Speed property holds the car’s current speed
In addition, class should have the following constructor and other methods:
Constructor- The constructor should accept the car’s year and model and make them as
arguments. These values should be assigned to the backing fields for the object’s Year and Make
properties. The constructor should also assign 0 to the backing field for the Speed property.
Accelerate- The Accelerate method should add 5 to the Speed property’s backing field each time
it is called
Brake- The Brake method should subtract 5 from the Speed property’s backing field each time it
is called
Demonstrate the class in an application that creates a Car object. The application’s form should have an
Accelerate button that calls the Accelerate method and then displays the car’s current speed each time it is
clicked. The application’s form should also have a Brake button that calls the Brake method and then
displays the car’s current speed each time it is clicked.
2. Employee Class
Write a class named Employee that has the following properties:
Name- The Name property holds the employee’s name
IdNumber- The IdNumber property holds the employee’s ID number
Department- The Department property holds the name of the department in which the employee
works
Position- The Position property holds the employee’s job title
The class should have the following overloaded constructors:
A constructor that accepts the following values as arguments and assigns them to the appropriate
properties: employee’s name, employee’s ID number, department and position
Level 1 Asia Pacific University of Technology and Innovation
CT044-3-1-IOOP Lab 10 – Classes and Constructors Page 2 of 2
A constructor that accepts the following values as arguments and assigns them to the appropriate
properties: employee’s name and ID number. The Department and Position properties should be
assigned an empty string (“ “)
A parameterless constructor that assigns empty strings (“ “) to the Name, Department and
Position properties, and 0 to the IdNumber property
In an application, create three Employee objects to hold the following data:
Name ID Number Department Position
Susan Meyers 47899 Accounting Vice President
Mark Jones 39119 IT Programmer
Joy Rogers 81774 Manufacturing Engineer
The application should store this data in the three objects and display the data for each employee on the
screen.
Level 1 Asia Pacific University of Technology and Innovation