Skip to content

Commit 65c5720

Browse files
committed
caracteristicas das heranças
1 parent 6f2555e commit 65c5720

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

classes/herancas.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
class Car():
22
"""Uma tentativa simples de representar um carro."""
3+
34
def __init__(self, make, model, year):
45
self.make = make
56
self.model = model
67
self.year = year
78
self.odometer_reading = 0
9+
self.gas_tank = 0
810

911
def get_descriptive_name(self):
1012
long_name = f"{self.year} {self.make} {self.model}"
@@ -22,6 +24,12 @@ def update_odometer(self, mileage):
2224
def increment_odometer(self, miles):
2325
self.odometer_reading += miles
2426

27+
def fill_gas_tank(self, filled):
28+
self.gas_tank = filled
29+
30+
def read_gas_tank(self):
31+
print(f"This car has {self.gas_tank} liters of gas.")
32+
2533

2634
carro = Car('Honda', 'Acura', 2019)
2735
carro.get_descriptive_name()
@@ -30,10 +38,14 @@ def increment_odometer(self, miles):
3038
carro.read_odometer()
3139
carro.increment_odometer(100)
3240
carro.read_odometer()
41+
carro.read_gas_tank()
42+
carro.fill_gas_tank(50)
43+
carro.read_gas_tank()
3344

3445

3546
class EletricCar(Car):
3647
"""Presenta aspectos especificos de veiculos elétricos"""
48+
3749
def __init__(self, make, model, year):
3850
"""Inicializa os atributos da classe-pai"""
3951
super().__init__(make, model, year)
@@ -43,9 +55,18 @@ def describe_battery(self):
4355
"""Exibe uma frase que descreve a capacidade da bateria"""
4456
print(f"This car has a {self.battery_size} kwh battery.")
4557

58+
def read_gas_tank(self):
59+
print("This car doesn't need a gas tank!")
60+
61+
def fill_gas_tank(self):
62+
"""Veiculos elétricos não tem tanques de gasolina"""
63+
print("This car doesn't need a gas tank!")
64+
4665

4766
carro_eletrico = EletricCar('Tesla', 'Model S', 2019)
4867
print(carro_eletrico.get_descriptive_name())
4968
carro_eletrico.describe_battery()
5069
carro_eletrico.battery_size = 100
5170
carro_eletrico.describe_battery()
71+
carro_eletrico.fill_gas_tank()
72+
carro_eletrico.read_gas_tank()

0 commit comments

Comments
 (0)