2. Objects
Feel free to use your laptop
You are strongly encourage to work with others
When you get stuck, ask those sitting around you for help
Get used to working together in the labs
Peer teaching and peer learning has been empirically shown to be very effective
2.1. Creating Objects
The goal is to make a program that will keep track of a suite of courses. To do this, two classes will be written —
one for keeping track of the information about a single course, and another for keeping track of multiple courses. In
this lab, the Course
class will be created.
2.1.1. Course Class
A Course
is a simple object to keeps track of data.
Refer to the objects review topic for guidance on creating this class.
Create a class called
Course
that has three private fields:programCode
,courseCode
, andcourseTitle
For example, a data structures course could have the following values for the fields
programCode
—"CS"
courseCode
—"102"
courseTitle
—"Programming and Data Structures"
Write a single constructor to take and assign values to the fields
Write accessor methods for the three fields
For example,
getCourseCode
Write a
toString
method that returns a string representation of the objectThe string should be of the form
"Course(programCode, courseCode, courseTitle)"
Write an
equals
method that checks if twoCourse
objects are equivalentTwo
Course
objects are considered equal if all their fields matchRemember, do not check string equality with
==
Write a
hashCode
methodTest the
Course
class by making instances of them and calling the methods to see if they work as expectedCreate a few instances of the
Course
class inmain
Call their methods and check if their behaviour is as expected
Be sure to check all methods