Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help modularizing this Visual Basic Program. its for this project https://www.chegg.com/homework-help/carpet-price-calculatorthe-westfield-carpet-company-asked-wr-chapter-12-problem-2pc-solution-9780132155656-exc So I have the code done and it works properly but my

I need help modularizing this Visual Basic Program.

its for this project

https://www.chegg.com/homework-help/carpet-price-calculatorthe-westfield-carpet-company-asked-wr-chapter-12-problem-2pc-solution-9780132155656-exc

So I have the code done and it works properly but my teacher gave me a low grade because I didn't use modules and put the code in the calculate could someone please modualize this so I know what exactly he wants and can do it in the future myself?

Form 1

Option Strict On

Public Class frmCarpetPrice ' Declare local variables 'Dim objRectangle As Rectangle ' objRectangle is an object of class Rectangle 'Dim objCarpet As Carpet ' objCarpet is an object of class Carpet Dim validWidth As Boolean = False ' variable to determine if input is valid Dim validLength As Boolean = False ' variable to determine if input is valid Dim validPrice As Boolean = False ' variable to determine if input is valid

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click Dim totalPrice As Double = 0

Dim objRectangle As Rectangle ' objRectangle is an object of class Rectangle Dim objCarpet As Carpet ' objCarpet is an object of class Carpet

txtColor.BackColor = Color.White txtStyle.BackColor = Color.White txtPrice.BackColor = Color.White txtWidth.BackColor = Color.White txtLength.BackColor = Color.White

Try

If Validation() = True Then

' do everything else

'objRectangle = New Rectangle() ' create an instance of rectangle 'objCarpet = New Carpet() ' create an instance of carpet

If validWidth And validLength And validPrice Then totalPrice = objCarpet.Price * objRectangle.Area lblTotalCost.Text = (totalPrice).ToString("C") End If

' break display out and call here

End If

Catch ex As Exception MessageBox.Show(ex.Message) End Try

End Sub

Public Function Validation() As Boolean

If txtColor.Text = "" Then MessageBox.Show("Please enter a color.") txtColor.Focus() txtColor.BackColor = Color.Yellow Return False End If

If txtStyle.Text = "" Then MessageBox.Show("Please enter a color.") txtStyle.Focus() txtStyle.BackColor = Color.Yellow Return False End If

If txtPrice.Text = "" Then MessageBox.Show("Please enter a Price.") txtPrice.Focus() txtPrice.BackColor = Color.Yellow Return False End If

If txtWidth.Text = "" Then MessageBox.Show("Please enter a Width.") txtWidth.Focus() txtWidth.BackColor = Color.Yellow Return False End If

If txtLength.Text = "" Then MessageBox.Show("Please enter a Length.") txtLength.Focus() txtLength.BackColor = Color.Yellow Return False End If

Return True

End Function

Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click ' Clears previous input from the form txtColor.Text = "" txtStyle.Text = "" txtPrice.Text = "" txtWidth.Text = "" txtLength.Text = "" lblArea.Text = "" lblTotalCost.Text = "" txtColor.Focus() End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click ' Ends the program when the user clicks on the exit button End End Sub

Sub GetRoomData(objRectangle As Rectangle) ' Assigns values from the form to the instance of Rectangle validWidth = False ' initialize to false in case of prior input validLength = False ' initialize to false in case of prior input Try If (CDbl(txtWidth.Text) > 0) Then objRectangle.Width = CDbl(txtWidth.Text) validWidth = True Else MessageBox.Show("Please enter a positive number for width.") txtWidth.Text = "" validWidth = False End If Catch ex As Exception

validWidth = False End Try Try If (CDbl(txtLength.Text) > 0) Then objRectangle.Length = CDbl(txtLength.Text) validLength = True Else MessageBox.Show("Please enter a positive number for length.") txtLength.Text = "" validLength = False End If Catch ex As Exception

validLength = False End Try If validWidth And validLength Then lblArea.Text = CStr(objRectangle.Area) End If End Sub

Sub GetCarpetData(objCarpet As Carpet) ' Assigns values from the form to the instance of Carpet validPrice = False ' initialize to false in case of prior input objCarpet.Color = txtColor.Text objCarpet.Style = txtStyle.Text Try If (CDbl(txtPrice.Text) >= 0) Then objCarpet.Price = CDbl(txtPrice.Text) validPrice = True Else MessageBox.Show("Price cannot be negative.") txtPrice.Text = "" validPrice = False End If Catch ex As Exception

validPrice = False End Try End Sub End Class

Carpet.vb

Option Strict On

Public Class Carpet Private m_Color As String Private m_Style As String Private m_Price As Double

Public Sub New() m_Color = "" m_Style = "" m_Price = 0.0 End Sub

Public Property Color As String Get Return m_Color End Get Set(value As String) m_Color = value End Set End Property

Public Property Style As String Get Return m_Style End Get Set(value As String) m_Style = value End Set End Property

Public Property Price As Double Get Return m_Price End Get Set(value As Double) m_Price = value End Set End Property End Class

Option Strict On

Public Class Rectangle Private m_Width As Double Private m_Length As Double Private m_Area As Double

Public Sub New() m_Width = 0.0 m_Length = 0.0 m_Area = 0.0 End Sub

Public Property Width As Double Get Return m_Width End Get Set(value As Double) m_Width = value End Set End Property

Public Property Length As Double Get Return m_Length End Get Set(value As Double) m_Length = value End Set End Property

ReadOnly Property Area As Double Get CalcArea() Return m_Area End Get End Property

Sub CalcArea() m_Area = m_Width * m_Length End Sub

End Class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Power Of Numbers In Health Care A Students Journey In Data Analysis

Authors: Kaiden

1st Edition

8119747887, 978-8119747887

Students also viewed these Databases questions

Question

Briefly explain two breakthroughs in the history of computing.

Answered: 1 week ago