EX10 - Basic Classes


In Exercise 10, we will be constructing a basic class to model a basketball game.

0. Pull the skeleton code

You will find the starter files needed by “pulling” from the course workspace repository. Before beginning, be sure to:

  1. Be sure you are in your course workspace. Open the file explorer and you should see your work for the course. If you do not, open your course workspace through File > Open Recent.
  2. Open the Source Control View by clicking the 3-node (circles) graph (connected by lines) icon in your sidebar or opening the command palatte and searching for Source Control.
  3. Click the Ellipses in the Source Control pane and select “Pull” from the drop-down menu. This will begin the pulling process from the course repository. It should silently succeed.
  4. Return to the File Explorer pane and open the exercises directory. You should see it now contains the directory named ex10. If you expand those directories, you will see the starter files for this exercise. You should notice the ex10 directory appear.

If the above did not work, try the following:

  1. Click the Ellipses in the Source Control pane and select “Pull, Push” from the drop-down menu. Then select “Pull from”. Then select “upstream” and the main option. This will begin the pulling process from the course repository. It should silently succeed.
  2. Return to the File Explorer pane and open the exercises directory. You should see it now contains another directory named ex10. If you expand that directory, you should see the starter files

Part 1. Class Writing

Write a class called BBallGame with the following specifications:

  1. Each BBallGame object should have 4 attributes including:
    • a boolean attribute called biscuits
    • an int attribute called points
    • a str attribute called winning_team
    • a str attribute called losing_team
  2. The BBallGame class should have a constructor that takes in points, winning_team, and losing_team, in this order. This means it will have ** 4 parameters including self**.
    The constructor should also initalize biscuits to be False through a direct access.

  3. Your class should also have 3 methods: check_points, winner, and reset_points. The functionality of these methods should be as described below.

    3.1 check_points

    • This method does not have any parameters (besides self) and returns None.
    • check_points should check if there are at least 100 points, in which case biscuits should be set to True.

    (If UNC basketball scores over 100 points in a game, Bojangles gives out free biscuits!)

    3.2 winner

    • This method does not have any parameters (besides self) and returns a str.
    • If the winning team is "UNC" and the losing team is "Dook", then the string "GTHD!!" should be returned. In the case that UNC wins, but Duke is not the opposing team, winner should return "woohoo".
    • If UNC doesn’t win, return "daggum".

    3.3 reset_points

    • This method does not have any parameters (besides self) and returns an int.
    • reset_points should return the current number of points, and reset the points to be 0.

2. Make a Backup Checkpoint “Commit”

As you make progress on this exercise, making backups is encouraged. Note that you do not have to make a backup in order to submit your work, though you are encouraged to before each submission so that you can revert back to a previous point in your project if you accidentally change something you did not intend to.

  1. Open the Source Control panel (Command Palette: “Show SCM” or click the icon with three circles and lines on the activity panel).
  2. Notice the files listed under Changes. These are files you’ve made modifications to since your last backup.
  3. Move your mouse’s cursor over the word Changes and notice the + symbol that appears. Click that plus symbol to add all changes to the next backup. You will now see the files listed under “Staged Changes”.
    • If you do not want to backup all changed files, you can select them individually. For this course you’re encouraged to back everything up.
  4. In the Message box, give a brief description of what you’ve changed and are backing up. This will help you find a specific backup (called a “commit”) if needed. In this case a message such as, “Progress on Exercise 3” will suffice.
  5. Press the Check icon to make a Commit (a version) of your work.
  6. Finally, press the Ellipses icon (…), look for “Pull/Push” submenu, and select “Push to…”, and in the dropdown select your backup repository.

3. Submit to Gradescope for Grading

Login to Gradescope and select the assignment named “EX10 - Basic Classes”. You’ll see an area to upload a zip file. To produce a zip file for autograding, return back to Visual Studio Code.

If you do not see a Terminal at the bottom of your screen, open the Command Palette and search for “View: Toggle Integrated Terminal”.

To produce a zip file for ex10, type the following command (all on a single line):

python -m tools.submission exercises/ex10

In the file explorer pane, look to find the zip file named “21.mm.dd-hh.mm-exercises-ex10.zip”. The “mm”, “dd”, and so on, are timestamps with the current month, day, hour, minute. If you right click on this file and select “Reveal in File Explorer” on Windows or “Reveal in Finder” on Mac, the zip file’s location on your computer will open. Upload this file to Gradescope to submit your work for this exercise.