Back to .md Directory

OOP Calculator Part 2 - Work in Progress (WIP)

Defines an OOP calculator assignment rubric with grading criteria, vocabulary, and step-by-step instructions for implementing encapsulation, inheritance, polymorphism, and abstraction.

May 2, 2026
0 downloads
2 views
ai
View source

What this file does

Defines an OOP calculator assignment rubric with grading criteria, vocabulary, and step-by-step instructions for implementing encapsulation, inheritance, polymorphism, and abstraction.

When to use it

  • Creating a rubric for an OOP programming assignment in Python
  • Teaching factory pattern and class/static/instance methods
  • Setting up automated grading via GitHub Actions with pytest
  • Providing students with a structured assignment guide including video links

Assumes this stack

PythonpytestPyCharmGitHub Actions

OOP Calculator Part 2 - Work in Progress (WIP)

Introduction

The purpose of this assignment is to introduce you to the implementation of encapsulation, inheritance, polymorphism, and abstraction. You will learn how to implement static, class, and instance methods as well as be introduced to your first OOP design pattern that is called the "factory pattern." You must write the implementation code to pass the teacher calculation and teacher calculator tests. THIS WILL NOT WORK AT ALL WITHOUT YOU WRITING CODE. YOU ARE GOING TO NEED TO KNOW HOW TO WRITE THE CODE AND LEARN BY FIXING ERROR MESSAGES. IF YOU NEED HELP POST A SCREENSHOT TO SLACK OR THE DISCUSSION BOARD FOR THE UNIT.

Grading Rubric

  • 50 Points for calculator teacher tests passing
  • 50 Points for calculation teacher tests passing

Note: You will receive a 0 if you do not follow the Object Oriented Designs ideas in the unit.

Assignment Instructions

  1. Create a calculation abstract class
  2. Add a create factory method that returns a class instance on the calculation class
  3. Add a get result method on the calculation class that returns the result property
  4. Add a set result method on the calculation class that sets the result property
  5. Add get/set methods for val1 and val2 respectively
  6. Add a constructor to the calculation class to set val1 and val2 properties
  7. Create addition, subtraction, division and multiplication concrete classes that extend the calculator class
  8. Add a constructor to each operation class .i.e. Addition, Multiplication, Division, and Subtraction that sets the result based on calling the correct operation

Module Readings:

  1. Is Instance https://pynative.com/python-isinstance-explained-with-examples/#h-how-to-use-isinstance-function-in-python
  2. Class Method Factor - https://dev.to/danyson/how-classmethod-in-python-helps-in-implementing-factory-methods-23gl

Vocabulary

Class : Schematic for an object or an organizational tool like a folder to organize methods and properties into logical groups like a directory. Classes are the blueprints / design of your program

Objects : Objects are copies of a class; however, in OOP languages usually every keyword is itself an object.

Instantiation : The process of taking class and making a copy of it.

Instance : Copy of a class with its own data

Class Members : The methods and properties of a class. Think of the class as a club and the properties and methods are the members

Property / Attribute : Data i.e. variable that describes the class

Method : Actions that can be taken by the class

Abstract Class a.k.a. Parent Class although not all parent classes are abstract : Generic representation of a class type i.e. pet

Concrete Class : Specific representation of a class type i.e Dog, Cat, etc...

Factory Method : Generic method that returns an instance of a class

Constructor Method : The first method automatically called when a class is instantiated into an object / instance

Namespace : Equivalent to the files and folders that are used to logically organize a programs code

Static Method / Property : Used to namespace properties and methods that don't need to operate on the class or an instance of a class

Class Method : Used to operate on class data that is not a copy / instance uses the cls keyword

Instance Method : Used to operate on the properties and methods of a class instance i.e. copy uses the self keyword

Override : When a child's class member replaces a parents member

Inheritance : Class Extension to connect e.g. connecting the calculation class to the Addition class to inherit the members of the calculation class

Abstraction : Layering from simple to complex e.g. how the calculator add method creates an addition instance and returns the result of the calculation

Polymorphism : Many shapes - think of how we are using the get result method from the abstract calculation class to set the result for an addition

Encapsulation : Think of how we are creating multiple instances of Addition in the calculation test and each instance is independent of the other

Prerequisite Knowledge

Note: Previously completed on static methods

Steps to Complete the Assignment

  1. Open Pycharm Pro / Pycharm Community and clone the assignment repository. Open up a terminal in Pycharm, run "pip install -r requirements.txt" and then run "pytest". If pycharm shows you an error about pip / requirements when you clone the repo just skip/cancel/dismiss the error and run the command in the terminal like I said above
  2. You will need to complete the requirements for the assignment and remove/replace the tests that are meant to fail that I placed in each file.
  3. When your pytest passes just commit and push it back to the origin and the assignment will be graded automatically by GitHub running the test that you run locally.
  4. Check that your tests pass on GitHub after you push the assignment and then submit a link to your repository to the assignment in Canvas. In GitHub on the repository, click the actions tab on GitHub to see your tests run. You will need to click on the autograding workflow to inspect that screen to see the detail test results.

What's inside

1 introduction, 1 grading rubric, 8 assignment instructions, 1 vocabulary list with 18 terms, 1 prerequisite section, 4 completion steps

Change this for your project

  • Replace NJIT-WIS/calculator_part_2 with your own repository URL
  • Replace tests/test_calculation_teacher.py and tests/test_calculator_teacher.py with your own test file paths
  • Replace instructor video links https://youtu.be/hXqD_jbfCwQ and https://youtu.be/scowyVU0wZw with your own

Where it goes

Keep it in your repository where the agent or team that needs it will read it.

Worth borrowing

  • Using a factory method on an abstract class to return concrete instances
  • Separating grading criteria into test-based points for automated evaluation

Related Documents