-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlista8-ex3.py
61 lines (51 loc) · 1.86 KB
/
lista8-ex3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
class BombaCombustivel:
__tipoCombustivel = None
__valorLitro = None
__quantidadeCombustivel = None
def __init__(self, tipoComb="G", valorLitro=3.00, qtdeCombust=0):
self.__tipoCombustivel = tipoComb
self.__valorLitro = valorLitro
self.__quantidadeCombustivel = qtdeCombust
def abastecerPorValor(self, valor):
qtdeLitros = valor / self.__valorLitro
if qtdeLitros <= self.__quantidadeCombustivel:
self.__quantidadeCombustivel -= qtdeLitros
return qtdeLitros
else:
return 0 #nao abasteceu -> 0 litros
def abastecerPorLitro(self, qtdeLitros):
if qtdeLitros <= self.__quantidadeCombustivel:
self.__quantidadeCombustivel -= qtdeLitros
#calculando o preço:
return qtdeLitros * self.__valorLitro
else:
return 0 #nao abasteceu -> 0 reais
def alterarValor(self, novoPreco):
self.__valorLitro = novoPreco
def alterarCombustivel(self, novoTipo):
self.__tipoCombustivel = novoTipo
def alterarQuantidadeCombustivel(self, novaQuantidade):
self.__quantidadeCombustivel = novaQuantidade
def getQuantidadeCombustivel(self):
return self.__quantidadeCombustivel
def getTipoCombustivel(self):
return self.__tipoCombustivel
def getValorLitro(self):
return self.__valorLitro
##>>>
##>>> b = BombaCombustivel("A", 2.30, 5000)
##>>> b.abastecerPorValor(100)
##43.47826086956522
##>>> b.getQuantidadeCombustivel()
##4956.521739130435
##>>> b.getTipoCombustivel()
##'A'
##>>> b.getValorLitro()
##2.3
##>>> b.__valorLitro
##
##Traceback (most recent call last):
## File "<pyshell#21>", line 1, in <module>
## b.__valorLitro
##AttributeError: BombaCombustivel instance has no attribute '__valorLitro'
##>>>