Module student
[hide private]
[frames] | no frames]

Source Code for Module student

 1  ''' 
 2  Created on Aug 26, 2011 
 3   
 4  @author: santtu 
 5  ''' 
 6   
7 -class Student(object):
8 ''' 9 The class C{Student} represents students in an excursion 10 signup system. Each student is characterized by its name and "year of 11 study" (i.e., 1 for freshmen, 2 for sophomores, etc.). A student 12 object is immutable after creation (we don't need to change, say, 13 the year of study in the context of this program). 14 ''' 15 16
17 - def __init__(self, name, year_of_study):
18 ''' 19 Creates a new student with the given name and year of study. 20 21 @param name: the student's name 22 @param year_of_study: the student's year of study 23 ''' 24 self.name = name # fixed value 25 self.year_of_study = year_of_study # fixed value
26 27 28
29 - def get_name(self):
30 ''' 31 Returns the student's name. 32 33 @return: student name 34 ''' 35 return self.name
36 37 38
39 - def get_year_of_study(self):
40 ''' 41 Returns the student's year of study. 42 43 @return: year of study 44 ''' 45 return self.year_of_study
46 47 48
49 - def is_older_than(self, another_student):
50 ''' 51 Determines if this student is "older", in terms of years studied, 52 than another, given student. 53 54 @param another_student: another student to compare to 55 @return: a boolean value indicating if this student is "older" than the given one 56 ''' 57 return self.get_year_of_study() > another_student.get_year_of_study()
58 59 60
61 - def get_description(self):
62 ''' 63 Returns a string description of the student. The description is of the form 64 "StudentName (YearOfStudy)". E.g. "Bob (3)". 65 66 @return: string description of student 67 ''' 68 return self.get_name() + " (" + str(self.get_year_of_study()) + ")"
69 70 71 72 if __name__ == '__main__': 73 pass 74