CSC148-Winter-2023-A0
README.md

CSC148-Winter-2023-A0

Assignment 0: The Gym

Learning goals This assignment is called “Assignment 0” because it is considerably smaller than Assignments 1 and 2. Its purpose is to make sure that you have understood the basics of object-oriented programming in Python and are ready to move on with the more advanced topics in the course. By the end of this assignment you should be able to:

Implement a class in Python from a provided interface, including:

  • Using instance attributes that enable the class methods to provide their services to client code,
  • Enforcing representation invariants that record important facts about implementation decisions, and
  • Implementing initializers and other methods
  • Choose unit tests that can convincingly demonstrate that a method works according to its docstring for all possible inputs
  • Implement those test cases in pytest
  • Interpret the results of doctests and unit tests to assess the correctness of methods

You should also have developed these habits: -Implementing tests for a method before implementing the method -Running your test suite throughout the development of your code

The domain In this assignment, you will work with three Python classes that manage the schedule of a gym. A Gym consists of many rooms and each room has a maximum capacity. The gym follows a Schedule where, at different times in the day, a room may have a Workout Class scheduled in it. A workout class is taught by an Instructor provided they have the proper qualifications (in the form of certificates) to teach it. A gym offering is a workout class taking place in a specific room, at a specific time, and taught by a specific instructor. Clients can register for these offerings provided there is enough space in the room.

We will assume that all offerings begin on the hour and last for 1 hour. We will also assume that all rooms have a fixed capacity (i.e., the room capacity does not change for different workout classes).

The program The code consists of three Python classes:

-An instance of WorkoutClass represents a type of workout class that can be offered at a gym, such as advanced pilates. It is worthy of being a Python class rather than just a string because it stores information about the qualifications required for teaching that type of workout class.

-An instance of Instructor represents an instructor who may teach classes at a gym.

-An instance of Gym represents a gym, with all of its instructors and its schedule of workout classes. It contains instances of the other classes.

The code for WorkoutClass has been completed for you, but many methods for the Gym class are missing their implementation, and you will need to complete the Instructor class to ensure that it is compatible with the rest of the provided code. The only public attribute of the Instructor class should be its name attribute; any other attributes you choose to add must be made private.

Representing the data We have already decided how data will be represented for you in this assignment. For example, clients are represented as strings and instructors are represented as a custom Python class. You should read the provided starter code carefully to see how all the data is stored.

Input to the program Input to the program comes from a file in a format called yaml. Yaml (rhymes with “camel”) is a syntax for storing data for programs to use, and is designed to be easy for people to read. You can open the provided file athletic-centre.yaml to see what a yaml file looks like, and read the docstring of function gym_from_yaml in gym.py to find out how we used yaml to store data for a gym.

We have provided the code for reading the data into the program from a yaml file, but we encourage you to take the time to familiarize yourself with the basic structure of the code.

Your tasks are to:

  1. Write the Instructor class.

You must define the class so that it provides the public methods needed by the provided function gym_from_yaml, by the methods in the Gym class, and by the tests in gym_sample_tests.py. You may find it helpful to add more public methods to your Instructor class later. For example, when implementing some of the methods in class Gym, you may find you require certain information that is stored in instances of your Instructor class. You must include one public attribute called name to hold the instructor’s name, and that must be the only public attribute. You get to decide what private attributes to use to store additional information.

  1. Implement the methods defined in class Gym. You must use the attributes that we defined in the class docstring, and must ensure that the representation invariants hold at all times in between method calls.

Do not add any new attributes or public methods to this class. Class Gym will use instances of class Instructor and WorkoutClass heavily, but it must not use any of their private attributes. If a docstring does not specify what to do in a particular scenario, you may decide what the method will do (we won’t test that scenario). You are welcome, and encouraged, to add private helper methods as you see fit. Include a docstring and doctest examples for any private methods you write.

The main block in gym.py calls a function that provides a small demo showing how to read the data for a gym from a yaml file, and use some of the services provided by your classes. It also calls a function we provided to make and display a webpage showing the whole schedule for a gym. Once your code is complete, try running the main block to see how your code supports this!

This project was completed on Pycharm. It was given a 83.1% (Class Average: 75.1%)