Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For this coding exercise: Create an application that can be used to calculate th

ID: 3598137 • Letter: F

Question

For this coding exercise:

Create an application that can be used to calculate the cost of installing a fence around a rectangular area.

Create the application, using the following names for the solution and project, respectively: Fence Solution and Fence Project. Save the application in the VB2015Chap11 folder.

Use Windows to copy the Rectangle.vb file from the VB2015Chap11 folder to the Fence SolutionFence Project folder.

Use the Project menu to add the Rectangle.vb class file to the project.

Modify the class to use Double (rather than Integer) variables and properties.

Add a method named GetPerimeter to the Rectangle class. The method should calculate and return the perimeter of a rectangle. To calculate the perimeter, the method will need to add together the length and width measurements, and then multiply the sum by 2.

Create the interface shown in Figure 11-30 (zak, 2016). The image for the picture box is stored in the VB2015Chap11Fence.png file. Code the application and then test it appropriately. (Hint: Using 120 feet as the length, 75 feet as the width, and 10 as the cost per linear foot of fencing, the installation cost is $3,900.00.)

Assignment Deliverables:

The zip file containing the Visual Studio solution and project files.

Explanation / Answer

Main Form.vb

Public Class frmMain
    Private Sub btnCalcTotalCost_Click(sender As Object, e As EventArgs) Handles btnCalcTotalCost.Click

        Dim amountofFence As New Rectangle
        Dim TotalPermimeterofFence As Double
        Dim Price As Double
        Dim TotalCost As Double

        Double.TryParse(txtLength.Text, amountofFence.Length)
        Double.TryParse(txtWidth.Text, amountofFence.Width)
        Double.TryParse(txtCost.Text, Price)

        TotalPermimeterofFence = amountofFence.GetPerimeter
        TotalCost = TotalPermimeterofFence * Price

        lblTotalCost.Text = TotalCost.ToString("C2")
    End Sub

    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
End Class
===============================================================================

Rectangle.vb

Option Explicit On
Option Strict On
Option Infer Off

Public Class Rectangle
    Private _dblLength As Double
    Private _dblWidth As Double

    Public Property Length As Double
        Get
            Return _dblLength
        End Get
        Set(value As Double)
            If value > 0 Then
                _dblLength = value
            Else
                _dblLength = 0
            End If
        End Set
    End Property

    Public Property Width As Double
        Get
            Return _dblWidth
        End Get
        Set(value As Double)
            If value > 0 Then
                _dblWidth = value
            Else
                _dblWidth = 0
            End If
        End Set
    End Property

    Public Sub New()
        _dblLength = 0
        _dblWidth = 0
    End Sub

    Public Sub New(ByVal dblL As Double, ByVal dblW As Double)
        Length = dblL
        Width = dblW
    End Sub

    Public Function GetArea() As Double
        Return _dblLength * _dblWidth
    End Function

    Public Function GetPerimeter() As Double
        Return ((_dblLength + _dblWidth) * 2)
    End Function
End Class
======================================================================

Main Form.Designer.vb

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmMain
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.btnCalcTotalCost = New System.Windows.Forms.Button()
        Me.btnExit = New System.Windows.Forms.Button()
        Me.lblTotalCost = New System.Windows.Forms.Label()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.txtLength = New System.Windows.Forms.TextBox()
        Me.txtWidth = New System.Windows.Forms.TextBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.txtCost = New System.Windows.Forms.TextBox()
        Me.Label5 = New System.Windows.Forms.Label()
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnCalcTotalCost
        '
        Me.btnCalcTotalCost.Location = New System.Drawing.Point(327, 175)
        Me.btnCalcTotalCost.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
        Me.btnCalcTotalCost.Name = "btnCalcTotalCost"
        Me.btnCalcTotalCost.Size = New System.Drawing.Size(167, 33)
        Me.btnCalcTotalCost.TabIndex = 0
        Me.btnCalcTotalCost.Text = "Calculate &Total Cost"
        Me.btnCalcTotalCost.UseVisualStyleBackColor = True
        '
        'btnExit
        '
        Me.btnExit.Location = New System.Drawing.Point(500, 175)
        Me.btnExit.Margin = New System.Windows.Forms.Padding(3, 4, 3, 4)
        Me.btnExit.Name = "btnExit"
        Me.btnExit.Size = New System.Drawing.Size(86, 33)
        Me.btnExit.TabIndex = 1
        Me.btnExit.Text = "E&xit"
        Me.btnExit.UseVisualStyleBackColor = True
        '
        'lblTotalCost
        '
        Me.lblTotalCost.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.lblTotalCost.Location = New System.Drawing.Point(195, 175)
        Me.lblTotalCost.Name = "lblTotalCost"
        Me.lblTotalCost.Size = New System.Drawing.Size(110, 36)
        Me.lblTotalCost.TabIndex = 2
        Me.lblTotalCost.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(191, 155)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(76, 20)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Total cost:"
        '
        'PictureBox1
        '
        Me.PictureBox1.Image = Global.Fence_Project.My.Resources.Resources.Fence
        Me.PictureBox1.Location = New System.Drawing.Point(12, 9)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(173, 211)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox1.TabIndex = 4
        Me.PictureBox1.TabStop = False
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(191, 65)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(97, 20)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "&Length (feet):"
        '
        'txtLength
        '
        Me.txtLength.Location = New System.Drawing.Point(195, 88)
        Me.txtLength.Name = "txtLength"
        Me.txtLength.Size = New System.Drawing.Size(68, 27)
        Me.txtLength.TabIndex = 6
        '
        'txtWidth
        '
        Me.txtWidth.Location = New System.Drawing.Point(327, 88)
        Me.txtWidth.Name = "txtWidth"
        Me.txtWidth.Size = New System.Drawing.Size(68, 27)
        Me.txtWidth.TabIndex = 7
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(323, 65)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(92, 20)
        Me.Label4.TabIndex = 8
        Me.Label4.Text = "&Width (feet):"
        '
        'txtCost
        '
        Me.txtCost.Location = New System.Drawing.Point(463, 88)
        Me.txtCost.Name = "txtCost"
        Me.txtCost.Size = New System.Drawing.Size(68, 27)
        Me.txtCost.TabIndex = 9
        '
        'Label5
        '
        Me.Label5.AutoSize = True
        Me.Label5.Location = New System.Drawing.Point(459, 65)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(153, 20)
        Me.Label5.TabIndex = 10
        Me.Label5.Text = "&Cost: (per linear foot):"
        '
        'frmMain
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 20.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(627, 261)
        Me.Controls.Add(Me.Label5)
        Me.Controls.Add(Me.txtCost)
        Me.Controls.Add(Me.Label4)
        Me.Controls.Add(Me.txtWidth)
        Me.Controls.Add(Me.txtLength)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.PictureBox1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.lblTotalCost)
        Me.Controls.Add(Me.btnExit)
        Me.Controls.Add(Me.btnCalcTotalCost)
        Me.Font = New System.Drawing.Font("Segoe UI", 11.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.Margin = New System.Windows.Forms.Padding(3, 5, 3, 5)
        Me.Name = "frmMain"
        Me.Text = "All-Around Fence Company"
        CType(Me.PictureBox1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

    Friend WithEvents btnCalcTotalCost As Button
    Friend WithEvents btnExit As Button
    Friend WithEvents lblTotalCost As Label
    Friend WithEvents Label2 As Label
    Friend WithEvents PictureBox1 As PictureBox
    Friend WithEvents Label3 As Label
    Friend WithEvents txtLength As TextBox
    Friend WithEvents txtWidth As TextBox
    Friend WithEvents Label4 As Label
    Friend WithEvents txtCost As TextBox
    Friend WithEvents Label5 As Label
End Class

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote