Criei a classe carros
Public Class carros
Private _combustivel As
Double
Private _km As Double
Public Property
combustivel() As Double
Get
Return _combustivel
End Get
Set(ByVal value As Double)
_combustivel = value
End Set
End Property
Public Property km() As Double
Get
Return _km
End Get
Set(ByVal value As Double)
_km = value
End Set
End Property
Public Sub abastecer(ByVal L As Double)
If (combustivel() + L) > 50 Then
MsgBox("Não é possível abastecer")
Else
combustivel() = combustivel + L
MsgBox("abastecimento
ok")
End If
End Sub
Public Sub move(ByVal distancia As Double)
Dim litros_necessarios As
Double
litros_necessarios = distancia / 15
If
(combustivel() < litros_necessarios) Then
MsgBox("Impossível
mover esta distância, combustível insuficiente.")
Else
km() = km() + distancia
combustivel() = combustivel() -
litros_necessarios
MsgBox("Movimento
ok")
End If
End Sub
End Class
Aqui é o programa principal
Public Class Form1
Dim c As New carros
Private Sub
Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
atualiza()
End Sub
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
c.abastecer(TextBox1.Text)
atualiza()
End Sub
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
c.move(TextBox2.Text)
atualiza()
End Sub
Public Sub atualiza()
TextBox4.Text = c.combustivel
TextBox3.Text = c.km
End Sub
End Class
Pegue o projeto neste link: http://www.mediafire.com/?k72av1ld0t7199g
Espero ter ajudado, até mais... Abraços!
0 comentários:
Postar um comentário