Source Code

Source Code

import counter
import dog
import bug
import recipe
import bankaccount
import collegecourse

def main():
    done = False
    print("Main Function")
    print("E1 - Example 1")
    choice = input("Choice: ").upper()
    match choice:
        case "E1":
            example1()
        case "E2":
            example2()
        case "E3":
            example3()
        case "E4":
            example4()
        case "E5":
            example5()
        case "E6":
            example6()
        case "E7":
            example7()
        case "E8":
            example8()
        case "Q":
            print("Quitting!")
            done = True
        case _:
            print("Invalid, try again!")

# define Example 1 Function
def example1():
    print("Example 1")
    # create counter object
    tally = counter.Counter()
    # call the click method on the object
    tally.click()
    tally.click()
    # print tally
    print(tally)
    # call the reset method on the object
    tally.reset()
    # print tally
    print(tally)

# define Example 2 Function
def example2():
    print("Example 2")
    c1 = counter.Counter()
    c2 = counter.Counter()
    for i in range(3):
        c1.click()
    for i in range(5):
        c2.click()
    print(c1)
    print(c2)

# define Example 3 Function
def example3():
    print("Example 3")
    # create dog object
    rocky = dog.Dog("Rocky", "Bulldog", 5)
    rocky.bark()

    # print the object
    print(rocky)

# define Example 4 Function
def example4():
    # create dog object
    spunky = dog.Dog("Spunky", "Poodle", 10)

    # print spunky's attributes
    print("Name: " + spunky.name)
    print("Breed: " + spunky.breed)
    print("Age: " + str(spunky.age))

# example5 function definition
def example5():
    print("Example 5")
    # create first bug
    fly = bug.Bug("Ms. Fly", 6, True)
    fly.make_sound("buzz")

    # create second bug
    mosquito = bug.Bug("Mr. Mosquito", 6, True)
    mosquito.make_sound("bite")

    # create a third bug
    ant = bug.Bug("The Ant", 6, False)
    ant.make_sound("march")

    # add the bugs to a list
    list = [fly, mosquito, ant]
    for bugs in list:
        print(bugs)

# example6 function definition
def example6():
    pancakes = recipe.Recipe("Pancakes")
    pancakes.add_ingredient("Flour")
    pancakes.add_ingredient("Eggs")
    pancakes.add_ingredient("Milk")
    pancakes.add_ingredient("Sugar")
    print(pancakes)

    fried_rice = recipe.Recipe("Fried Rice")
    fried_rice.add_ingredient("Rice")
    fried_rice.add_ingredient("Eggs")
    fried_rice.add_ingredient("Chicken")
    fried_rice.add_ingredient("Onions")
    fried_rice.add_ingredient("Scallions")
    print(fried_rice)

# example7 function definition
def example7():
    print("Example 7")
    sam = bankaccount.BankAccount("Sam", 1000)
    print(sam.get_balance())

    # Accessing the private attribute via name mangling
    print(sam._BankAccount__balance)

    # Modifying the private attribute via name mangling
    sam._BankAccount__balance = 2000
    print(sam.get_balance())

    print(sam)

# example8 function definition
def example8():
    print("Example 8")
    # Example of usage:
    semester = input("Semester: ")
    course_number = input("Course Number: ")
    course_name = input("Course Name: ")
    course_instructor = input("Instructor: ")
    course_daytime = input("Course Day/Time: ")
    cps3320 = collegecourse.CollegeCourse(semester, course_number, course_name, course_instructor, course_daytime)
    for x in range(3):
        assignment = input("Name of Assignment: ")
        grade = input("Grade: ")
        cps3320.add_grade(assignment, grade)

    print(cps3320)

main()

counter.py

dog.py

bug.py

recipe.py

bankaccount.py

collegecourse.py

Last updated