Homework 7: Object Oriented Programming (OOP)¶
Submit this homework via Dropbox. For the deadline please consult the schedule posted on Blackboard.
Python-scripts are submitted in one file called:
homework7.py
Exercise 1¶
Define a student class. A student has the following attributes: firstname,
lastname, gender which can be male or female, status which can be
equal to freshman, sophomore, junior, and senior and gpa.
Then define the following methods for the student class.
The
show_myselfmethod will simply print all the attribute variables when called upon the object. This method has no input arguments.The
study_timemethod will increment thegpaof the student according to the following formula:` gpa = gpa + log(study_time)`. The only input argument of this method is the variablestudy_time. In addition make sure that thegpavariable never exceeds 4.0 even if the student studies for a very long time.
Exercise 2¶
Now define 5 student objects and store the objects in a list called
student_list. The five students are: Mike Barnes, Jim Nickerson,
Jack Indabox, Jane Miller and Mary Scott.
Mike is a freshman, Jim a sophomore, Jack a junior, Jane and Mary are seniors.
Their respective GPAs are: 4, 3, 2.5, 3.6 and 2.7. Make sure you assign the
gender when you instantiate the objects.
Then call the show_myself method on all of them. I suggest you use a loop
for making the objects and a separate loop for showing the objects.
Exercise 3¶
Use your objects from above and let each one of the 5 students study for
60, 100, 40, 300, 1000 minutes, respectively. So the first student
studies 60 minutes, the second studies 100 minutes, etc.
After that call the show_myself methods on all 5
again and check whether their new gpa reflects how much they studied.