beyondgrader.com Logo
DemoBrowseAboutTeamLogin

Course Equality

Geoffrey Challen // 2020.9.0

Create a class named Course. Course should define a primary constructor that accepts three fields: a String? (the department), a String? (the course number, and yes, this must be a String) and an Int (the enrollment). You are welcome to name these fields however you like, and they should be private. Your constructor should reject null departments and numbers and negative enrollments.

You do not need to provide any getters and setters! Instead, define a single method named equals. Your equals method accepts an Any? as a single parameter. It should return true if the passed object is a Course and has the same values for the department and number, and false otherwise.