En visual basic.net 2013, creamos una clase llamada Cilindro. Menu Proyecto/Agregar clase y le asigamos el nombre de Cilindro. Le agregamos el siguiente codigo:
Public Class Cilindro
Private Radio, Altura As Double
Sub New(Ra As Double, Al As Double)
Me.Radio = Ra
Me.Altura = Al
End Sub
Public Function getAreaLateral() As Double
Return 2 * Math.PI * Me.RADIO
End Function
Public Function getAreaTotal() As Double
Return 2 * Math.PI * Me.Radio + 2 * Math.PI * Me.Radio ^ 2
End Function
Public Function getVolumen() As Double
Return Math.PI * Me.Radio ^ 2 * Altura
End Function
End Class
Diseñamos el formulario para comprobar el funcionamiento de la clase Cilindro.
Programando los botones de comando.
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim RADIO, ALTURA As Double
Dim AREAT, AREAL, VOLUMEN As Double
RADIO = TextBox1.Text
ALTURA = TextBox2.Text
Dim C As New Cilindro(RADIO, ALTURA)
TextBox3.Text = C.getAreaLateral()
TextBox4.Text = C.getAreaTotal
TextBox5.Text = C.getVolumen
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox1.Focus()
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
No hay comentarios:
Publicar un comentario