Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this assignment. This is for Visual Basic and I put the code below that I did, but it is not working.

I need help with this assignment. This is for Visual Basic and I put the code below that I did, but it is not working. Can you help me with the code for this Assignment. Thank You.

image text in transcribedimage text in transcribed

Option Strict On

Public Class frmSmartHome ' Class Variables Private _intMonthsOfSmartSavings As Integer = 12 Public Shared _intSizeOfArray As Integer = 7 Public Shared _strSavings(_intSizeOfArray) As String Private _strSavingsMonth(_intSizeOfArray) As String Private _decInitialBill(_intSizeOfArray) As Decimal Private _intMonth(_intSizeOfArray) As Integer

Private Sub frmSmartHome_Load(sender As Object, e As EventArgs) Handles MyBase.Load ' The frmSmartHome load event reads the savings text file and ' fills the cboLocation box with 12 months.

' Initialize an instance streamReader object and declare variables Dim objReader As IO.StreamReader Dim strLocationAndNameOfFile As String = "F:\chapter 8 ungided 1\savings.txt" Dim intCount As Integer = 0 Dim intFill As Integer Dim strFileError As String = "The FIle is not available. Restart when the file is available."

' Verify the file existance If IO.File.Exists(strLocationAndNameOfFile) Then objReader = IO.File.OpenText(strLocationAndNameOfFile) 'Read the file line by the line until the file is completed Do While objReader.Peek -1 _strSavings(intCount) = objReader.ReadLine() _strSavingsMonth(intCount) = objReader.ReadLine() _decInitialBill(intCount) = Convert.ToDecimal(objReader.ReadLine()) _intMonth(intCount) = Convert.ToInt32(objReader.ReadLine()) intCount += 1 Loop objReader.Close()

' The Monthly Savings Combo Box object is filled with the months of the savings For intFill = 0 To (_strSavingsMonth.Length - 1) cboMonths.Items.Add(_strSavingsMonth(intFill)) Next Else MsgBox(strFileError, , "Error") Close() End If End Sub

Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click ' The btnDisplay click event handler displays the monthly savings, average monthly savings ' and the best monthly savings Dim intSelectedMonth As Integer Dim strMissingSelection As String = "Missing Selection" Dim strSelectedMonthError As String = "Select a Month" Dim intMonthChoice As Integer

' If the Month Savings Combo Box is selected, then display the statistics If cboMonths.SelectedIndex >= 0 Then intSelectedMonth = cboMonths.SelectedIndex Else MsgBox(strSelectedMonthError, , strMissingSelection) End If End Sub

Private Sub cboMonths_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboMonths.SelectedIndexChanged ' This Sub procedure computes and displays the savings for the month selected ' Declare variables Dim intDoublePresentMonth As Integer Dim decDoubleSavings As Decimal Dim decAverageSavings As Decimal Dim decTotal As Decimal Dim decDoubleTotal As Decimal = 0.0D Dim strPresentSavingsMonth As String = "" Dim decAverageSavingsOfMonth As Decimal Dim decSignificantSavingsOfMonth As Decimal

' The procedure MakeObjectsVisible is called to display the Form objects MakeObjectsVisible() 'Display the values and quantity of the selected values lblElectricSavings.Text = "The electric savings for " & strPresentSavingsMonth & " is " & _strSavings(_intSizeOfArray) lblAverageSavings.Text = "The average monthly savings: " & decAverageSavings.ToString("C0") lblMontlySavings.Text = _decInitialBill(_intSizeOfArray) & " had the most significant monthly savings"

' The loop repeats for the life of the values For intDoublePresentMonth = 1 To _intMonthsOfSmartSavings ' The formula for the average monthly savings inside the loop to repeat the process decAverageSavings = decDoubleTotal / _intMonthsOfSmartSavings ' Displays the savings amounts cboMonths.Items.Add(intDoublePresentMonth.ToString()) ' Accumulates the total of the savings decTotal += decDoubleSavings Next End Sub Private Sub MakeObjectsVisible() ' This procedure displays the objects showing the results lblElectricSavings.Visible = True btnDisplay.Visible = True lblAverageSavings.Visible = True lblMontlySavings.Visible = True ' The previous data is removed cboMonths.Items.Clear() lblElectricSavings.Text = "" lblAverageSavings.Text = "" lblMontlySavings.Text = "" End Sub End Class

tere une or more of the following case programuning assignment. Submit the wima and tiaterials you create to your instructor. The level of difficulty is indicated if the cise programming assignment. 1 SMART HOME MONTHLY ELECTRIC SAVINGS Deign Windows Desktop application and write the code that will exccute acconding to the program requirements aigsor 8-100 and the Use Case Definition in Figure 8-101. Before writing the code, create an event-planning deament for each event in the program. The completed program is shown in Figure 8-102. REQUIREMENTS DOCUMENT Dute: April 2, 2019 Date Subnitted: Afplication Tide: Smart Home Monthly Electric Savings Puroue: This Windows application opens 2 tot file that lias the monthly uvings of a smart home's electric bill in comparison to a provious year wishout imart derise activation. A smar thermostat, lighting wntem, and water heater were lnitalled one year ago and the text file lists the avingr cuch month. The user selectsa month read from the text fle and displass that monehi clectric bill iavings A Button object displays the average monthly wings with the samar home derices and the moeth with the most aignificant savinge. Program Procedures: In a Wiedom application, a vier cas view the isdividual moothly uving of a unat home's cloctric bill, Agrorithms, Processing 1. The user views a Window appliestion that contiin a titte, graphic, and a and Conditions: ComboBex object diplaying the months of the year. The ComboBex object. is filled fom a text file named lavings out that is opened and read by the application from the USB drive (drive d). The teat file contaim each month with the electrie bill uving from that monch. 2. After the user selects the month from the ComboBox object, that month's kavings is displyed and the Disply Statisici button is shomn. Wben the user dido the button, the merage monthly awings and the moeth with the moit significant saving is displyed. Notes and Restrictions The uier must seleet a month from the ComboBex object before the Battan object is displayed. Comments: 1. The avings, tot file is avalable on CengageBrin.coen. 2. Obtain an image for this program from Cengagetrain.com. The oume of the picture on the Window form is smarthome. FIGURE 8-100 USE CASE DEFIITTON FtGuAE B-101

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

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

More Books

Students also viewed these Databases questions