Inheritance and Composition The focus of this practical is to use inheritance, create base classes, and...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Inheritance and Composition The focus of this practical is to use inheritance, create base classes, and how to create corresponding derived classes. Create a Python class for the following UML class diagram. This diagram captures three classes: Vehicle, Bus, and Engine. Bus is a child (subclass) of Vehicle and therefore inherits its members. Vehicle becomes the parent (superclass) of Bus. Engine is composite to vehicle. Steps 1. Vehicle + wheelCount: int #doorCount: int VIN: str 4. 5. - getVIN(): str + setVIN(vin: str) + showEngineDetails(): str Bus - seatCount: int + getSeatCount(): int + setSeatCount(seatCount: int) 1 Engine Task 1: Vehicle and Buss Classes (1 mark) You are required to create these classes in Python - correctly representing the concept of the relationships. In addition a property, VIN should be created for Vehicle that is using the getter and setter method for the private VIN (vehicle identification number) attribute. A seatCount property should also be created for Bus. -type: str + setType(type: str) + showDetails(): str Create the Vehicle class including an initialiser method. Assign values to the attributes, wheelCount, door Count, and VIN. Note: Correctly apply the attributes' visibilities in code. 2. Implement a getter method which returns the VIN attribute. 3. Implement a setter method which takes a new vin variable as a parameter. Assign the objects attribute VIN to this parameter. Create a property called vin which utilises the getter and setter methods for the attribute VIN. Create the Bus class including an initialiser method. Assign values to the attribute seatcount. Note: Remember to override the parent initialiser. Check Tutorial 3.2 Slide 13 for information on how to do this. 6. Implement a getter method which returns the seatCount attribute. 7. Implement a setter method which takes a new seatCount variable as a parameter. Assign the objects attribute seatCount to this parameter. This method should only set the count if the number is between 0 and 200, otherwise it will set it to 0 by default. 8. Create a property called seatCount which utilises the getter and setter methods for the attribute seatCount. 9. Test your code with the following: vehicle Vehicle(4, 4, "ZE1D4") Bus (8, 2, "BOTW", 40) bus = print("VIN number of Vehicle: " + vehicle.vin) print("VIN number of Bus: + bus.vin) 11 print("Seat Count of Bus: + str (bus.seatCount)) Your output must match the following: VIN number of Vehicle: ZE1D4 VIN number of Bus: BOTW Seat Count of Bus: 40 Task 3: Encapsulation (1 mark) Steps 1. Test and execute the following code. Note down in a commented line what happened and why. print(vehicle._VIN) print (bus._doorCount) Task 4: Engine Class (1 mark) Steps 1. Create the Engine class including an initialiser method. Assign values to the attribute type. 2. Implement a setter method which takes a new type variable as a parameter. Assign the objects attribute type to this parameter. 3. Implement a method showDetails that returns a string detailing the type of engine. 4. Test your code with the following: engine Engine("Diesel") = print("-Engine Details- " + engine.showDetails()) Your output must match the following: -Engine Details- The engine is type: Diesel Task 5: Refining Classes (1 mark) Modify the Vehicle and Bus classes to correctly implement the composition relationship. Steps 1. Modify the Vehicle class to implement the relationship correctly. 2. You should include an engine attribute. This should be instantiated as a new engine with empty quotes ("") as the parameter. (le. No engine was set) 3. Bus should set the type of engine to be "Diesel". 4. Modify the Vehicle class by adding a new method, showEngine Details that calls the showDetails method of the Engine to obtain its information. 5. Test your code with the following: vehicle bus = = Vehicle(4, 4, "ZE1D4") Bus (8, 2, "BOTW", 40) print("Engine details of vehicle. + vehicle.showEngineDetails()) 11 print("Engine details of bus. + bus.showEngineDetails()) Your output must match the following: Engine details of vehicle. The engine is type: Engine details of bus. The engine is type: Diesel Inheritance and Composition The focus of this practical is to use inheritance, create base classes, and how to create corresponding derived classes. Create a Python class for the following UML class diagram. This diagram captures three classes: Vehicle, Bus, and Engine. Bus is a child (subclass) of Vehicle and therefore inherits its members. Vehicle becomes the parent (superclass) of Bus. Engine is composite to vehicle. Steps 1. Vehicle + wheelCount: int #doorCount: int VIN: str 4. 5. - getVIN(): str + setVIN(vin: str) + showEngineDetails(): str Bus - seatCount: int + getSeatCount(): int + setSeatCount(seatCount: int) 1 Engine Task 1: Vehicle and Buss Classes (1 mark) You are required to create these classes in Python - correctly representing the concept of the relationships. In addition a property, VIN should be created for Vehicle that is using the getter and setter method for the private VIN (vehicle identification number) attribute. A seatCount property should also be created for Bus. -type: str + setType(type: str) + showDetails(): str Create the Vehicle class including an initialiser method. Assign values to the attributes, wheelCount, door Count, and VIN. Note: Correctly apply the attributes' visibilities in code. 2. Implement a getter method which returns the VIN attribute. 3. Implement a setter method which takes a new vin variable as a parameter. Assign the objects attribute VIN to this parameter. Create a property called vin which utilises the getter and setter methods for the attribute VIN. Create the Bus class including an initialiser method. Assign values to the attribute seatcount. Note: Remember to override the parent initialiser. Check Tutorial 3.2 Slide 13 for information on how to do this. 6. Implement a getter method which returns the seatCount attribute. 7. Implement a setter method which takes a new seatCount variable as a parameter. Assign the objects attribute seatCount to this parameter. This method should only set the count if the number is between 0 and 200, otherwise it will set it to 0 by default. 8. Create a property called seatCount which utilises the getter and setter methods for the attribute seatCount. 9. Test your code with the following: vehicle Vehicle(4, 4, "ZE1D4") Bus (8, 2, "BOTW", 40) bus = print("VIN number of Vehicle: " + vehicle.vin) print("VIN number of Bus: + bus.vin) 11 print("Seat Count of Bus: + str (bus.seatCount)) Your output must match the following: VIN number of Vehicle: ZE1D4 VIN number of Bus: BOTW Seat Count of Bus: 40 Task 3: Encapsulation (1 mark) Steps 1. Test and execute the following code. Note down in a commented line what happened and why. print(vehicle._VIN) print (bus._doorCount) Task 4: Engine Class (1 mark) Steps 1. Create the Engine class including an initialiser method. Assign values to the attribute type. 2. Implement a setter method which takes a new type variable as a parameter. Assign the objects attribute type to this parameter. 3. Implement a method showDetails that returns a string detailing the type of engine. 4. Test your code with the following: engine Engine("Diesel") = print("-Engine Details- " + engine.showDetails()) Your output must match the following: -Engine Details- The engine is type: Diesel Task 5: Refining Classes (1 mark) Modify the Vehicle and Bus classes to correctly implement the composition relationship. Steps 1. Modify the Vehicle class to implement the relationship correctly. 2. You should include an engine attribute. This should be instantiated as a new engine with empty quotes ("") as the parameter. (le. No engine was set) 3. Bus should set the type of engine to be "Diesel". 4. Modify the Vehicle class by adding a new method, showEngine Details that calls the showDetails method of the Engine to obtain its information. 5. Test your code with the following: vehicle bus = = Vehicle(4, 4, "ZE1D4") Bus (8, 2, "BOTW", 40) print("Engine details of vehicle. + vehicle.showEngineDetails()) 11 print("Engine details of bus. + bus.showEngineDetails()) Your output must match the following: Engine details of vehicle. The engine is type: Engine details of bus. The engine is type: Diesel
Expert Answer:
Related Book For
Intermediate Accounting
ISBN: 978-0077400163
6th edition
Authors: J. David Spiceland, James Sepe, Mark Nelson
Posted Date:
Students also viewed these programming questions
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
The focus of this case is the situation described in Case 10-9. What is the appropriate accounting for R&D costs? Do you believe that (1) Capitalization is the correct treatment of R&D costs, (2)...
-
Let y vary directly with x. Complete the following. Find y when x = 1.3, if y = 7.2 when x = 5.2.
-
In a film projector, the film acts as the object whose image is projected on a screen (Fig. 23-59). If a 105-mmfocal- length lens is to project an image on a screen 25.5 m away, how far from the lens...
-
A researcher collects data on married couples to see whether men and women differ in their mean levels of marital satisfaction. For each married couple, both the husband and wife fill out a scale...
-
Consider the Michaelis-Menten model introduced in Eq. (12.23). Graph the expectation function for \(\theta_{1}=100,150,200,250\) for \(\theta_{2}=0.06\). Overlay these curves on the same set of...
-
You plan to open a small business for manufacturing pet collars, leashes, and harnesses. You have found a workshop space you can use for sewing your products. After some research and planning, you...
-
Find the zeros of the quadratic function using the square root method. What are the x-intercepts of the graph of the function? 9(x)=(x-4)-9
-
Federal Semiconductors issued 11% bonds, dated January 1, with a face amount of $800 million on January 1, 2024. The bonds sold for $739,813,200 and mature on December 31, 2043 (20 years). For...
-
Write a Rust program to add,subtract,multiply and divide two numbers.
-
a. Define the term average collection period (ACP). b. How is ACP used to monitor overall revenue cycle performance? c. What is an aging schedule? d. How is an aging schedule used to monitor overall...
-
How do Eurocurrency markets differ from internal credit markets?
-
a. What is meant by the term revenue cycle? b. What are the three sets of activities that make up the revenue cycle? c. What is the overall goal of revenue cycle management?
-
What is the Eurocurrency market and what is its function?
-
Explain briefly how healthcare providers typically obtain secured short-term financing.
-
Last year Kinslow Company's cash account increased by $16,000 Net cash flows from investing activities were $(39,000) Net cash flows from financing activities were $17,000 On the statement of cash...
-
Keating & Partners is a law firm specializing in labour relations and employee-related work. It employs 25 professionals (5 partners and 20 managers) who work directly with its clients. The average...
-
The following questions are used in the Kaplan CPA Review Course to study the statement of cash flows while preparing for the CPA examination. Determine the response that best completes the...
-
Each of the three independent situations below describes a capital lease in which annual lease payments are payable at the end of each year. The lessee is aware of the lessor's implicit rate of...
-
EDGAR, the Electronic Data Gathering, Analysis, and Retrieval system, performs automated collection, validation, indexing, and forwarding of submissions by companies and others who are required by...
-
What is the change in velocity of \((a)\) cart 1 (b) cart 2 in Figure 4.6? (c) What do you notice about your two answers? Figure 4.6 Velocity-versus-time graph for two identical carts before and...
-
(a) Are the accelerations of the motions shown in Figure 4.1 constant? (b) For which surface is the acceleration largest in magnitude? Figure 4.1 Velocity-versus-time graph for a wooden block sliding...
-
The \(x\) component of the final velocity of the standard cart in Figure 4.8 is positive. Can you make it negative by adjusting this cart's initial speed while still keeping the half cart initially...
Study smarter with the SolutionInn App