Homework – 6 CMPSC 131 Spring 2023
Due date: April 30, 2023 (Sunday) at 11:59 PM
1
Answer all questions.
1. (70 points) OOP related.
Write a class named Car that has the following data attributes:
• year (for the car’s year model)
• make (for the make of the car)
• speed (for the car’s current speed). Speed should be private.
The Car class should have following methods:
• __init__ method
• Setters and getters methods
• Display method that will display the information of the car.
The class should also have the following methods:
• accelerate
- The accelerate method should add 5 to the speed data attribute each time it
is called.
• brake
- The brake method should subtract 5 from the speed data attribute each time
it is called.
Next, design a program (main) that creates two objects of a Car class then calls the
accelerate and brake methods for the two objects. After that call the display method for the
two objects.
Homework – 6 CMPSC 131 Spring 2023
Due date: April 30, 2023 (Sunday) at 11:59 PM
2
2. (30 points) Two-Dimensional List.
Task-2-(i): run the given codes (2D-list-class-Activity) in the Python IDE (IDLE).
You will get the following(similar) outputs:
Task-2(ii): (Try to understand the above codes) and do the following:
a. Display the random numbers in a matrix form.
b. Calculate the summation of all numbers in matrix.
c. Display the summation.
You will see the similar outputs:
Submission: Python files.
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。