0% found this document useful (0 votes)
37 views

OOP1 Assignment 5

This document provides instructions for an OOP1 assignment due on March 27th. It includes two programming tasks: 1. Create an Employee class with fields for name, ID number, department, and position. Include various constructors and accessor/mutator methods. Then create three Employee objects to test the class. 2. Create a Car class with fields for year, make, and speed. Include a constructor that sets initial values and methods to accelerate, brake, and get the speed. Then write a program that accelerates and brakes a Car object to test it.

Uploaded by

hexa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views

OOP1 Assignment 5

This document provides instructions for an OOP1 assignment due on March 27th. It includes two programming tasks: 1. Create an Employee class with fields for name, ID number, department, and position. Include various constructors and accessor/mutator methods. Then create three Employee objects to test the class. 2. Create a Car class with fields for year, make, and speed. Include a constructor that sets initial values and methods to accelerate, brake, and get the speed. Then write a program that accelerates and brakes a Car object to test it.

Uploaded by

hexa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

OOP1 Assignment 5

Due on March 27th

1. Employee Class
Write a class named Employee that has the following fields:
 name. The name field references a String object that holds the employee’s name.
 idNumber. The idNumber is an int variable that holds the employee’s ID number.
 department. The department field references a String object that holds the name of the department where the
employee works.
 position. The position field references a String object that holds the employee’s job title.
The class should have the following constructors:
 A constructor that accepts the following values as arguments and assigns them to the appropriate fields:
employee’s name, employee’s ID number, department, and position.
 A constructor that accepts the following values as arguments and assigns them to the appropriate fields:
employee’s name and ID number. The department and position fields should be assigned an empty string ("").
 A no-arg constructor that assigns empty strings ("") to the name, department, and position fields, and 0 to the
idNumber field.
Write appropriate mutator methods that store values in these fields and accessor methods that return the values in
these fields. Once you have written the class, write a separate program that creates three Employee objects to hold the
following data:

2. Car Class
Write a class named Car that has the following fields:
 yearModel. The yearModel field is an int that holds the car’s year model.
 make. The make field references a String object that holds the make of the car.
 speed. The speed field is an int that holds the car’s current speed.

In addition, the class should have the following constructor and other methods.
 Constructor. The constructor should accept the car’s year model and make as arguments. These values
should be assigned to the object’s yearModel and make fields. The constructor should also assign 0 to the
speed field.
 Accessors. Appropriate accessor methods should get the values stored in an object’s yearModel, make, and
speed fields.
 accelerate. The accelerate method should add 5 to the speed field each time it is called.
 brake. The brake method should subtract 5 from the speed field each time it is called.

Demonstrate the class in a program that creates a Car object, and then calls the accelerate method five times. After
each call to the accelerate method, get the current speed of the car and display it. Then call the brake method five
times. After each call to the brake method, get the current speed of the car and display it.

Submission guides:
- Submit your code as a .java or .txt file for each question.
- Screenshots of the outputs.

You might also like