<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">"""Car, Device, and Vehicle classes

Used to demonstrate object oriented techniques in Java vs Python
"""


class Vehiculo:
    """The Vehicle class is the parent for all vehicles."""

    def __init__(self, color, modelo):
        """Define the color and model of our vehicle"""
        self.color = color
        self.modelo = modelo


class Dispositivo:
    """The Device class defines objects which have a battery."""

    def __init__(self):
        """Define the base voltage for our device."""
        self._voltaje = 12


class Carro(Vehiculo, Dispositivo):
    """The Car class is both a Vehicle and a Device."""

    ruedas = 0

    def __init__(self, color, modelo, anio):
        """Call our parent classes, then define the year."""
        Vehiculo.__init__(self, color, modelo)
        Dispositivo.__init__(self)
        self.anio = anio

    def add_ruedas(self, ruedas):
        """Change the number of wheels we have."""
        self.ruedas = ruedas

    @property
    def voltaje(self):
        """Allow us to access the Device._voltage property as voltage"""
        return self._voltaje

    @voltaje.setter
    def voltaje(self, volts):
        """Warn the user before resetting the voltage"""
        print("Aviso: esto puede causar problemas!")
        self._voltaje = volts

    @voltaje.deleter
    def voltaje(self):
        """Warn the user before deleting the voltage"""
        print("Aviso: la radio puede dejar de funcionar!")
        del self._voltaje

    def __str__(self):
        """Improved human readable version of the object"""
        return f"Car {self.color} : {self.modelo} : {self.anio}"

    def __eq__(self, other):
        """Do these objects have the same year?"""
        return self.anio == other.anio

    def __lt__(self, other):
        """Which object was made earlier than the other?"""
        return self.anio &lt; other.anio

    def __add__(self, other):
        """Add the objects together in our predefined way."""
        return Car(
            self.color + other.color,
            self.modelo + other.modelo,
            int(self.anio) + int(other.anio),
        )
</pre></body></html>