# File: python_1e_classes.py -- solutions of review 1E

# 1.  Chunk class

class Chunk:

    def __init__ (self, type, weight, price):
        self.type = type
        self.weight = weight
        self.price = price

    def price_per_ounce (self):
        return self.price / self.weight

def make_cheese ():
    cheese = [Chunk("Swiss", 10, 25.00),
              Chunk("Mozzarella", 5, 6.00),
              Chunk("Extra Sharp Cheddar", 3, 18.00)]
    for c in cheese:
        print(c.type, c.price_per_ounce())


# 2.  Student class

class Student:

    def __init__ (self):
        self.courses = []

    def add_course (self, course):
        if not (course in self.courses):
            self.courses.append(course)
        else:
            print("Already taking that course.")

    def drop_course (self, course):
        if (course in self.courses):
            self.courses.remove(course)
        else:
            print("Can't drop a course you're not taking.")

    def get_courses (self):
        return self.courses[:] # [:] creates a copy of self.courses

def test_student (student=Student()):
    student.add_course("Philosophy")
    student.add_course("History")
    student.add_course("English")
    student.add_course("Informatics")
    print("This student is taking these courses:")
    print(student.get_courses())

    student.drop_course("English")
    print("This student is now taking these courses:")
    print(student.get_courses())

# Test: 
# test_student()

# 3.  GraduateStudent class

class GraduateStudent (Student):

    def __init__ (self):
        Student.__init__(self)
        self.thesis = None

    def set_thesis(self, title):
        self.thesis = title

    def get_thesis (self):
        return self.thesis

def test_grad_student (student=GraduateStudent()):
    test_student(student)

    student.set_thesis("The Character of Tarzan")
    # And this student dropped English!

    print("This student's thesis title is", student.get_thesis())

# Test:
# test_grad_student()

