Create shape class as abstract class having area function.Create rectangle, triangle, square class based on this class in VB.NET.
Here this program we use MustInherit Class, MustOverride Function and how to create class, create object of class and import statement in VB.NET.
Shape.vb
Public MustInherit Class Shape
Public MustOverride Function Area(ByVal a As Integer, ByVal b As Integer) As Integer
End Class
square.vbPublic MustOverride Function Area(ByVal a As Integer, ByVal b As Integer) As Integer
End Class
Public Class square
Inherits Shape
Public Overrides Function Area(ByVal a As Integer, ByVal b As Integer) As Integer
Return a * b
End Function
End Class
rectangle.vbInherits Shape
Public Overrides Function Area(ByVal a As Integer, ByVal b As Integer) As Integer
Return a * b
End Function
End Class
Public Class rectangle
Inherits Shape
Public Overrides Function Area(ByVal a As Integer, ByVal b As Integer) As Integer
Return a * b
End Function
End Class
triangle.vbInherits Shape
Public Overrides Function Area(ByVal a As Integer, ByVal b As Integer) As Integer
Return a * b
End Function
End Class
Public Class triangle
Inherits Shape
Public Overrides Function Area(ByVal a As Integer, ByVal b As Integer) As Integer
Return (a * b) / 2
End Function
End Class
Form1.vbInherits Shape
Public Overrides Function Area(ByVal a As Integer, ByVal b As Integer) As Integer
Return (a * b) / 2
End Function
End Class
Imports area_of_shape.square
Imports area_of_shape.rectangle
Imports area_of_shape.triangle
Public Class Form1
Dim S As New square
Dim R As New rectangle
Dim T As New triangle
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If RadioButton1.Checked Then
Label3.Text = "Area of Square is :" & S.Area(Val(TextBox1.Text), Val(TextBox1.Text))
ElseIf RadioButton2.Checked Then
Label3.Text = "Area of Rectangle is :" & R.Area(Val(TextBox1.Text), Val(TextBox2.Text))
ElseIf RadioButton3.Checked Then
Label3.Text = "Area of Triangle is :" & T.Area(Val(TextBox1.Text), Val(TextBox2.Text))
End If
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged
If RadioButton1.Checked Then
Label1.Text = "Side"
TextBox1.Visible = True
TextBox2.Visible = False
Label2.Text = ""
ElseIf RadioButton2.Checked Then
Label1.Text = "Length"
TextBox1.Visible = True
Label2.Text = "Width"
TextBox2.Visible = True
Else
Label1.Text = "Base"
TextBox1.Visible = True
Label2.Text = "Height"
TextBox2.Visible = True
End If
TextBox1.Clear()
TextBox2.Clear()
Label3.Text = "Enter Number in Box"
End Sub
End Class
DESIGNING:Imports area_of_shape.rectangle
Imports area_of_shape.triangle
Public Class Form1
Dim S As New square
Dim R As New rectangle
Dim T As New triangle
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If RadioButton1.Checked Then
Label3.Text = "Area of Square is :" & S.Area(Val(TextBox1.Text), Val(TextBox1.Text))
ElseIf RadioButton2.Checked Then
Label3.Text = "Area of Rectangle is :" & R.Area(Val(TextBox1.Text), Val(TextBox2.Text))
ElseIf RadioButton3.Checked Then
Label3.Text = "Area of Triangle is :" & T.Area(Val(TextBox1.Text), Val(TextBox2.Text))
End If
End Sub
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged, RadioButton2.CheckedChanged, RadioButton3.CheckedChanged
If RadioButton1.Checked Then
Label1.Text = "Side"
TextBox1.Visible = True
TextBox2.Visible = False
Label2.Text = ""
ElseIf RadioButton2.Checked Then
Label1.Text = "Length"
TextBox1.Visible = True
Label2.Text = "Width"
TextBox2.Visible = True
Else
Label1.Text = "Base"
TextBox1.Visible = True
Label2.Text = "Height"
TextBox2.Visible = True
End If
TextBox1.Clear()
TextBox2.Clear()
Label3.Text = "Enter Number in Box"
End Sub
End Class
Comments
Post a Comment