added in additional inherited parameters (I think all of them?)'

This commit is contained in:
2022-07-07 15:54:35 -05:00
parent 83a5e88553
commit ed5eedec21
+27 -14
View File
@@ -1,7 +1,6 @@
from abc import ABC, abstractmethod
# ABC is imported from the standard library since Python does not natively support abstract methods and classes.
class Fleet():
vehicles = ["7E19H2", "N9460G32581A3", "BN4681"]
def __init__(self, vtype, movspeed, travelmed, vehicleid):
self.vehicletype = vtype
@@ -49,23 +48,22 @@ class GroundVehicleInterface(ABC):
'''Resource on Python interfaces. This is duck typed. https://realpython.com/python-interface/ Interfaces make a contract that a method must be implemented if an interface is inherited and allows differing implementations of the same method.'''
@abstractmethod
def travel(self):
Vehicle.velocity = self.moveGroundVehicle
print("Traveling")
pass
class GroundVehicle(Vehicle, GroundVehicleInterface):
@abstractmethod
def __init__(self, _isModular, _moveGroundVehicle):
# default value set to true. Many ground vehicles will have trailers or train cars. Modified as needed
def __init__(self, _isModular, _moveGroundVehicle, _gpsPosition, _velocity, _weight, _velocityType, _weightType, _status):
super().__init__(_gpsPosition, _velocity, _weight, _velocityType, _weightType, _status)
self.isModular = _isModular
self.moveGroundVehicle = _moveGroundVehicle
class RoadVehicle(GroundVehicle):
@abstractmethod
def __init__(self, _axlecount, _isModular, _moveGroundVehicle):
def __init__(self, _axlecount, _isModular, _moveGroundVehicle, _gpsPosition, _velocity, _weight, _velocityType, _weightType, _status):
super().__init__(_isModular, _moveGroundVehicle, _gpsPosition, _velocity, _weight, _velocityType, _weightType, _status)
self.axleCount = _axlecount
super().__init__(_isModular, _moveGroundVehicle)
class Train(GroundVehicle):
def __init__(self, _noOfCarsAttached, _locomotiveCount):
@@ -73,9 +71,9 @@ class Train(GroundVehicle):
self.locomotiveCount = _locomotiveCount
def displayCarCount(self):
print(self.noOfCarsAttached)
print(f"The train has {self.noOfCarsAttached} cars attached.")
def displayLocomotiveCount(self):
print(self.locomotiveCount)
print(f"The train has {self.locomotiveCount} locomotives attached.")
def travel(self):
print("Speed 60mph, Direction E")
@@ -88,20 +86,35 @@ Train1.displayLocomotiveCount()
# Always encapsulate parent constructors into child classes to make those variables available
class semi_Truck(RoadVehicle):
def __init__(self, _noOfTrailersAttached, _axlecount, _isModular, _moveGroundVehicle):
def __init__(self, _noOfTrailersAttached, _axlecount, _isModular, _moveGroundVehicle, _gpsPosition, _velocity, _weight, _velocityType, _weightType, _status):
self.noOfTrailersAttached = _noOfTrailersAttached
# super in Python returns an object representing the parent class and
super().__init__(_axlecount, _isModular, _moveGroundVehicle)
super().__init__(_axlecount, _axlecount, _isModular, _moveGroundVehicle, _gpsPosition, _velocity, _weight, _velocityType, _weightType, _status)
# Don't modify passed in values unless absolutely necessary
def displaySemiAttributes(self):
print(self.noOfTrailersAttached, self.axleCount)
def travel(self):
print(Vehicle.status)
print(self.status)
Semi_Truck1 = semi_Truck(f"This truck has {2} trailers attached", f"and {4} axles.", True, [49.8900000, 50.900000])
# When possible, build your argument requirements from the top down so that by the time you implement your concrete classes, you know all the data points that you need to include.
# Remember to be careful to check that you are running the method on an instance of the class, not on the class definition.
# Semi_Truck1.displaySemiAttributes()
# Next - implement abstracted methods and constructor classes. Demonstrate use of super if Python supports it.
# Next - implement abstracted methods and constructor classes. Demonstrate use of super if Python supports it.
# Use these values in instances and show that values can be accessed regardless of what level they live on.
# Make vehicle objects, add them to the fleet, and then have displayAllVehicles show the newly added vehicle. Stretch/further off, have different types of vehicles travel regardless of type.
'''
Code scratchpad
For the travel method implemented from the interface
Vehicle.velocity = self.moveGroundVehicle
print("Traveling")
Object implementation
Semi_Truck1 = semi_Truck(f"This truck has {2} trailers attached", f"and {4} axles.", True, [49.8900000, 50.900000])
'''