Question: LAB 5 1. Class definition #1 Write a program which defines a class for cataloguing videogames. The class should have three properties: the game name,
LAB 5
1. Class definition #1
Write a program which defines a class for cataloguing videogames. The class should have three properties: the game name, the console name, and the year of production. All the properties are mandatory and must be provided.
Create 2 objects using the defined class. Provide the code below.
| Reply below (only code here): |
|
|
Now, make sure that all parameters are hidden and allow their retrieval with a getter method and their modification with a setter method.
Modify and display the properties of the two previously created objects. Provide the code below.
| Reply below (only code here): |
|
|
Create a method that provides the age of the video game by making a simple difference between the current year (2023) and the production year: game_age = curret_year production_year
In the previous code, use the method for calculating the game age for the two previously created objects.
Provide the code below.
| Reply below (only code here): |
|
|
Provide the screenshot of the run output (entire screen, no cuts).
2. Class definition #2
Write a program which defines a class for appliances. The class should have three properties: the device name, the power consumption, and the energy efficiency expressed as a percentage. The device name is a mandatory property, while the other two are optional and, therefore, can have a default value (e.g., 1 for 1 Watt and 50 for an efficiency of 50%).
Create 2 objects using the defined class. Provide the code below.
| Reply below (only code here): |
|
|
Now, make sure that all parameters are hidden and allow their retrieval with a getter method and their modification with a setter method.
Modify and display the properties of the two previously created objects. Provide the code below.
| Reply below (only code here): |
|
|
Create a method that provides the power losses as the product between the power consumption and the complement to 1 of the efficiency: power_losses = power_consuption * (100-efficiency)/100
In the previous code, use the method for calculating power losses for the two previously created objects.
Provide the code below.
| Reply below (only code here): |
|
|
Provide the screenshot of the run output (entire screen, no cuts).
3. Class modification
Consider the class created at the end of the first exercise. First, add a new parameter that indicates the number of plays of the user. Every time the user plays the video game, he will increase this property of one unit. Such a parameter must be optional, placed in the last position, hidden, and its default value is zero. Next, create a method to increase the number of plays and a getter method to display its current value.
Use the two previously created methods on the two objects.
Provide the code below.
| Reply below (only code here): |
|
|
Provide the screenshot of the run output (entire screen, no cuts).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
