COMP 139 - Lab 1 - OOP Review

Learning Outcomes and Introduction

This assignment reviews the coding techniques and concepts that should already be familiar to you from COMP 132 or equivalent courses. If this material is new to you or is very difficult, you should not be taking this course. If this material is familiar but a little difficult, you're in the right place!

Topics covered by this lab include:

Do not add any public fields or methods to the classes in this assignment beyond those listed in the UML. However, you may add as many private fields and methods as you see fit.

Task 1: class Person

Create the Person class as described below.

Person


Each Person should be assigned a unique ID value when created, starting from 1 for the first instance, and increasing by 1 for each subsequent instance.

The givenName and surname properties store this person's personal and family names respectively (eg. "George" and "Smith"). Either of these fields may be left blank (null).

The toString() method should return a String displaying the person's full name and ID, for example "John Jones (ID# 0003)". If a name field is null, it should not be included in the output.

Remember to use JavaDoc to document all public fields, constructors, and methods!

Task 2: Employees and Patients

Create the Employee, Nurse, Doctor, and Patient classes described below.

Employee extends Person


The unit property describes the area or department where an employee works, for example: "Emergency", "Human Resources", or "Radiology".

The annualSalary field records this employee's base annual earnings, in dollars. It should be set to an appropriate amount by every subclass. The getAnnualSalary() method should return this amount.

Nurse extends Employee


Nurses are assigned a shift number that indicates the time of day and number of hours that they work. The default shift for new instances is SHIFT_A.

Nurses have a default annual salary of $80,000. However, if assigned to SHIFT_B they will earn $85,000 and if assigned to SHIFT_C they will earn $90,000.

The toString() method should be overridden by this class to include the nurse's unit and assigned shift number (eg. "Martha McGee (ID# 1234) (Radiology unit, shift 5)").

Doctor extends Employee


The specialty field describes this doctor's main area of medicine, such as "Family Practice", "Neurology", or "Surgury".

All doctors earn an annual salary of $250,000.

The toString() method should be overridden by this class to prefix the doctor's name with "Dr." and include their specialty (eg. "Dr. Brenda Freeman (ID# 0023) (Podiatry)").

Patient extends Person

Every patient must be assigned a physician who is the Doctor primarily responsible for their care.

The Patient class does not override the toString() method that it inherits from Person.

Task 3: Main Program

Create a main program class that:

  1. Creates three or more Nurse instances assigned to different shifts.
  2. Creates three or more Doctor instances.
  3. Creates three or more Patient instances with pre-determined names and manually assigned physicians chosen from the pool of Doctor instances previously created.
  4. Generates another 20 Patient instances using randomly generated names and randomly assigns them physicians chosen from the pool of Doctor instances previously created.
  5. Prints the toString() values for all employees.
  6. Prints the toString() value and physician ID for each patient.
  7. Calculates and prints the total annual cost to employ all of the created doctors and nurses.
  8. Calculates and prints the number of patients assigned to each Doctor.

Use arrays to store all of your Patient, Nurse, and Doctor objects.

You can generate names by randomly choosing a combination of first and last names from pre-set lists of possibilities.

Sample Names

				// source: https://nameberry.com/unisex-names
				String[] givenNames = {
					"Avery", "Riley", "Jordan", "Angel", "Peyton",
					"Quinn", "Hayden", "Taylor", "Alexis", "Rowan",
					"Charlie", "Emerson", "Finley", "River", "Emery",
					"Morgan", "Elliot", "London", "Eden", "Elliott",
					"Karter", "Dakota", "Reese", "Remington", "Payton",
					"Amari", "Phoenix", "Kendall", "Harley", "Rylan",
					"Marley", "Dallas", "Skyler", "Spencer", "Sage",
					"Kyrie", "Ellis", "Rory", "Remi", "Justice",
					"Ali", "Haven", "Tatum", "Arden", "Linden",
					"Devon", "Rebel", "Rio", "Ripley", "Frankie"
				};

				// source: http://www.locatemyname.com/topsurnames.php?country=canada
				String[] surnames = {
					"Smith", "Brown", "Tremblay", "Martin", "Roy",
					"Wilson", "Macdonald", "Gagnon", "Johnson", "Taylor",
					"Cote", "Campbell", "Anderson", "Leblanc", "Lee",
					"Jones", "White", "Williams", "Miller", "Thompson",
					"Gauthier", "Young", "Van", "Morin", "Bouchard",
					"Scott", "Stewart", "Belanger", "Reid", "Pelletier",
					"Moore", "Lavoie", "King", "Robinson", "Levesque",
					"Murphy", "Fortin", "Gagne", "Wong", "Clark",
					"Johnston", "Clarke", "Ross", "Walker", "Thomas",
					"Boucher", "Landry", "Kelly", "Bergeron", "Davis"
				};
			

Do not use input from System.in for any part of your program.

Use static methods as appropriate to organize your code.

Try to keep all output at the end of your program.

Submission

Completing all tasks in this lab should result in 6 separate Java files within a single package named like LastnameFirstname_lab1. Compress the package directory into a ZIP archive and upload it to the D2L assignment.

The marks for this lab are heavily weighted towards good coding practice and style. Pay attention to your code formatting, make sure you have documented all public members using JavaDoc, and make sure you are using constants, arrays, loops, and methods effectively.

NOTE: This assignment is to be done individually. You can help one another with problems and questions, but in the end everyone must do their own work.

CriteriaMarks
Programs compile and run without error 2
Good coding style 2
Task requirements met or exceeded 2
Total 6