Problem Statement You are to create a Visual Basic(VB) project for a census bure
ID: 3868228 • Letter: P
Question
Problem Statement
You are to create a Visual Basic(VB) project for a census bureau to obtain and analyze household income survey data within the Pittsburgh area (including Morgantown Ky).
Data Collected:
Home identification code (4 alphanumeric characters) – required
Program should generate it using a random number generator. You won’t use this anywhere it just need to be generated. Generate the first number in the Form Load event and then each subsequent number in the button click. See attached code as example.
Date of the survey – required (try using the datetime picker control), must be a valid date. You do not need to use the date anywhere just have it available on your form to select.
County and State (1 input only) they reside in - required
Hamilton, Pa
Butler, Pa
Clermont, Pa
Warren, Pa
Campbell, Ky
Boone, Ky
Kenton, Ky
The household yearly income – required, must be numeric, must be greater than 0.
Events:
There should be 4 buttons on the screen:
1.Submit: This event will validate all data and save the data to the necessary arrays for processing.
2.Exit: This event will exit the application
3.Total Households Surveyed: This event will process the arrays and display the total households surveyed by state and then by county in a Message box (see below for example).
4.Average Household Income: This event will process the arrays and display the average household income by state and then by county in a Message box (see below for example).
Instructions:
1)Create a well designed modular program based on design techniques taught.
2)Use good naming conventions on all objects, variables, procedures, functions, etc.
3)Option Strict and Option Explicit must be on
4)All survey information must be saved to an array(s).
5)When the user clicks the button “Total Households Surveyed”, do the necessary calculations and display in a Message box the Total Households Surveyed by county for all that were surveyed (see below for example).
6)When the user clicks the button “Average Household Income”, do the necessary calculations and display in a Message box the Average Household Income by county for all that were surveyed (see below for example).
Average Household Income (Output as example only)
Pensylvania: $30,000
Hamilton: $40,000
Butler: $20,000
Clermont: $30,000
Warren: $0
Kentucky: $35,000
Boone: $0
Campbell: $35,000
Kenton: $35,000
Number of Households Surveyed (Output as example only)
Pensylvania: 4
Hamilton: 2
Butler: 1
Clermont: 1
Warren: 0
Kentucky: 3
Boone: 0
Campbell: 2
Kenton: 1
Explanation / Answer
Imports System.Math
Imports System
Public Class Form1
Private arrayIncome(,) As String
Dim i As Integer = 0
Dim j As Integer = 0
Dim ran As Random = New Random()
Dim id As Integer
Dim avgSalaryResult As String
Dim countyResult As String
Dim stateCount As Integer
Dim countyCount As Integer
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnAvgIncome_Click(sender As Object, e As EventArgs) Handles btnAvgIncome.Click
Dim totalSalary As Integer = 0
Dim countySalary As Integer = 0
Dim avgSalary As Integer
Dim countyName As String
Dim totalSurveyed As Integer
Dim diffState As String = String.Empty
For iValue As Integer = 0 To i - 1
Dim tempState As String
tempState = arrayIncome(iValue, 0).Substring(arrayIncome(iValue, 0).LastIndexOf(",") + 1)
If Not diffState.Contains(tempState) Then
diffState = diffState + "," + tempState
End If
Next
diffState = diffState.Trim()
diffState = diffState.Trim(",")
Dim processedCounty As String = String.Empty
For iValue As Integer = 0 To diffState.Split(",").Length
Dim st As String = String.Empty
Dim county As String = String.Empty
st = diffState.Split(",")(iValue)
arrayIncome(iValue, 0).Substring(arrayIncome(iValue, 0).LastIndexOf(",") + 1)
For jValue As Integer = 0 To i - 1
If st = arrayIncome(jValue, 0).Substring(arrayIncome(jValue, 0).LastIndexOf(",") + 1) Then
totalSalary = totalSalary + arrayIncome(jValue, 1)
county = arrayIncome(jValue, 0).Substring(0, arrayIncome(jValue, 0).LastIndexOf(","))
If Not county.Contains(processedCounty) Then
processedCounty = processedCounty + "," + county
For kValue As Integer = 0 To i - 1
countyCount = countyCount + 1
If county = arrayIncome(kValue, 0).Substring(0, arrayIncome(kValue, 0).LastIndexOf(",")) Then
countySalary = countySalary + arrayIncome(kValue, 1)
countyCount = countyCount + 1
countyName = arrayIncome(kValue, 0).Substring(0, arrayIncome(kValue, 0).LastIndexOf(",")) + ": " + countySalary + "/n"
Else
countySalary = arrayIncome(kValue, 1)
countyName = arrayIncome(kValue, 0).Substring(0, arrayIncome(kValue, 0).LastIndexOf(",")) + ": " + countySalary + "/n"
End If
county = arrayIncome(jValue, 0).Substring(0, arrayIncome(kValue, 0).LastIndexOf(","))
Next
End If
stateCount = stateCount + 1
countyCount = 0
countyResult = countyResult + countyName
End If
Next
avgSalary = totalSalary stateCount
avgSalaryResult = st + avgSalary.ToString() + " "
Next
End Sub
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
arrayIncome(i, j) = txtIncome.Text REM (0,0)
arrayIncome(i, ++j) = txtCounty.Text() REM (0,1)
i = i + 1
j = j + 1
id = ran.Next(1000, 9999)
txtId.Text = id.ToString()
txtCounty.Text = ""
txtIncome.Text = ""
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
id = ran.Next(1000, 9999)
txtId.Text = id.ToString()
End Sub
End Class
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.