'''lecture_25_student.py Our very first class! Represents a Student Oliver W. Layton CS 151: Computational Thinking: Visual Media Fall 2020 TODO: Make Student class with methods: - Constructor with 2 parameters: name and year - get methods - set year method Main code: - Create two students - Get and print their names and years - Set one of their years - Print both years ''' # turtle.forward(100) means we call a function that lives in the turtle module. class Student: def __init__(self, name, gradYear, gpa=4.0): # self.name: There is a variable called name in the current object ("self") self.name = name self.year = gradYear self.gpa = 4.0 self.grades = [] # not all IVs need to be params. All IVs should be defined in constructor def getName(self): return self.name def getGradYear(self): return self.year def getGPA(self): return self.gpa def getGrades(self): return self.grades # def setYear(self, year): # self.year = year def setYear(self, newGradYear): self.year = newGradYear def addGrade(self, newGrade): self.grades.append(newGrade) def addBonusPoints(self, grades): for i in range(len(self.grades)): self.grades[i] = self.grades[i] + 5 # Student class here if __name__ == '__main__': # Symbol table example # jane = Student('Jane', 2024) # print(jane.getYear()) # jane.setYear(2023) jane = Student('Jane', 2024) # jane = Student('Jane', 2024, gpa=3.0) jim = Student('Jim', 2022) # Want: jane.getName() give me string: 'Jane' print('The first student\'s name is', jane.getName()) # print('The second student\'s name is', jim.getName()) # print('Looping thru students...') # students = [jane, jim] # for student in students: # print('The student name is:', student.getName()) # print('The first student\'s graduation year was', jane.getGradYear()) # jane.setYear(2023) # print('The first student\'s graduation year is now', jane.getGradYear()) # print(jane.setYear(2022)) # def funA(value): # value = value + 1 # # return value # print(funA(3)) # print('GPA is', jane.getGPA()) jane.addGrade(90) jane.addGrade(86) jane.addGrade(84) print('Jane\'s grades are:', jane.getGrades()) jane.addBonusPoints() print('Jane\'s grades are (after bonus points):', jane.getGrades())