VB。 Net 2012处理课程

问题描述:

问题是我没有得到输出和正确的程序设置。如果您还需要表格,请告诉我。该计划旨在计算手机数据计划的成本。我正在使用Visual Studio 2012.



这是两个问题的表格。我试图从屏幕截图中返回表格本身的最终成本



我尝试过:



The issue is I am not getting output and the correct setup of the classes to program. If you need the form as well, please let me know. This program is to calculate the costs of data plans for mobile phones. Visual Studio 2012 is what I am using.

Here is the form with the two issues. I am trying to return the final cost to the form itself from the screen shot

What I have tried:

'Form Portion of the program
Public Class frmMobilePhoneReg
    

   
    Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
        Dim objBuyer As Buyer
        ' Dim objDataPlan As DataPlan
        Dim InputError As Boolean = False

        If txtLName.TextLength < 1 Or txtLName.Text < "A" Then
            MsgBox("Enter your Last Name in the Last Name box", , "Error")
            txtLName.Clear()
            txtLName.Focus()
            InputError = True
        ElseIf txtStreetAddr.Text = "" Then
            MsgBox("Enter your Street Address box", , "Error")
            txtStreetAddr.Clear()
            txtStreetAddr.Focus()
            InputError = True
        ElseIf txtZipCode.TextLength < 1 Or txtZipCode.TextLength > 5 Then
            MsgBox("Enter your Zip Code in the box", , "Error")
            txtZipCode.Clear()
            txtZipCode.Focus()
            InputError = True
        ElseIf cboPlanChoice.SelectedIndex < 0 Then
            MsgBox("Please select a plan", , "Error")
            cboPlanChoice.Focus()
            InputError = True
        ElseIf cboHotSpot.SelectedIndex < 0 Then
            MsgBox("Please select a hotspot", , "Error")
            cboHotSpot.Focus()
            InputError = True
        End If
        If Not InputError Then


            If rdoInternet.Checked Then

                lblEmailAddr.Visible = True
                txtEmailAddr.Visible = True
                If txtLName.TextLength < 1 Or txtLName.Text < "A" Then
                    MsgBox("Enter your email in the box", , "Error")
                    txtEmailAddr.Clear()
                    txtEmailAddr.Focus()
                    InputError = True
                End If
            ElseIf rdoInStore.Checked Then
                txtEmailAddr.Text = ""

            End If
        End If
        objBuyer = New Buyer(txtLName.Text, txtStreetAddr.Text, txtZipCode.Text, txtEmailAddr.Text, cboPlanChoice.SelectedItem, cboHotSpot.SelectedItem)


        lblCustCost.Visible = True
        lblCustCost.Text = "Total costs are: " & objBuyer.ComputeCosts()



    End Sub

    Private Sub cboPlanChoice_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboPlanChoice.SelectedIndexChanged

    End Sub

    Private Sub cboHotSpot_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboHotSpot.SelectedIndexChanged

    End Sub

    Private Sub rdoInStore_CheckedChanged(sender As Object, e As EventArgs) Handles rdoInStore.CheckedChanged

    End Sub

    Private Sub rdoInternet_CheckedChanged(sender As Object, e As EventArgs) Handles rdoInternet.CheckedChanged

    End Sub

    Private Sub frmMobilePhoneReg_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cboPlanChoice.SelectedIndex = 0
        cboHotSpot.SelectedIndex = 0
        txtLName.Focus()
    End Sub
End Class


'Buyer Clsss
Option Strict On
Public Class Buyer
    Protected _strBLName As String
    Protected _strBAddress As String
    Protected _strBZipCode As String
    Protected _strBEmail As String
    Protected _strBPlCho As String
    Protected _strHotSpot As String
    Dim objBuyerCostsFile As BuyerCost
    Dim decCost As Decimal


    Sub New(ByVal strBLName As String, ByVal strBAddress As String, ByVal strBZipCode As String, ByVal strBEmail As String, _
            ByVal strBPlCho As String, ByVal strHotSpot As String)
        _strBLName = strBLName
        _strBAddress = strBAddress
        _strBZipCode = strBZipCode
        _strBEmail = strBEmail
        _strBPlCho = strBPlCho
        _strHotSpot = strHotSpot
    End Sub
    Overridable Function ComputeCosts() As Decimal
       
        objBuyerCostsFile = New BuyerCost(_strBLName, _strBAddress, _strBZipCode, _strBEmail)

        objBuyerCostsFile.WriteRecord()
        Return decCost
    End Function

End Class

'Buyer cost class
Public Class BuyerCost

    Private _strBLName As String
    Private _strBAddress As String
    Private _strBZipCode As String
    Private _strBType As String
    Private _strDPChoice As String
    Private _strDPHotspot As String
    Private _decBPlanCost As Decimal
    Private _strBEmail As String

    Sub New(strBLName As String, strBAddress As String, strBZipCode As String, strBEmail As String, decBPlanCost As String)
        ' TODO: Complete member initialization 
        _strBLName = strBLName
        _strBAddress = strBAddress
        _strBZipCode = strBZipCode
        _strBEmail = strBEmail
        _decBPlanCost = decBPlanCost
    End Sub


    Sub WriteRecord()

        Dim strNameandLocationOfFile As String = "e:\StudentCosts.txt"
        Try
            Dim objWriter As IO.StreamWriter = _
                IO.File.AppendText(strNameandLocationOfFile)
            objWriter.Write(_strBLName & ",")
            objWriter.Write(_strBZipCode & ",")
            objWriter.Write(_strDPChoice & ",")
            objWriter.Write(_decBPlanCost)
            objWriter.Close()
        Catch ex As Exception
            MsgBox("No device available - program aborted", , "Error")
            Application.Exit()
        End Try
    End Sub
End Class

'Data Plan class
Option Strict On
Public Class DataPlan
    Inherits Buyer
    Private _InStore As Boolean
    Private _Internet As Boolean
    Private _DataP1GB As Boolean
    Private _DataP2GB As Boolean
    Private _DataP4GB As Boolean
    Private _DataPUnl As Boolean
    Private _AddYHotSpot As Boolean
    Private _AddNHotSpot As Boolean

    Dim objBuyerCostsFile As BuyerCost


    Sub New(ByVal BLName As String, ByVal BAddress As String, _
            ByVal BZipCode As String, ByVal BEmail As String, _
            ByVal DPChoice As String, ByVal DPHotspot As String, _
            ByVal DataP1GB As Boolean, ByVal DataP2GB As Boolean, _
            ByVal DataP4GB As Boolean, ByVal DataPUnl As Boolean, _
            ByVal AddYHotSpot As Boolean, ByVal AddNHotSpot As Boolean)
        MyBase.New(BLName, BAddress, BZipCode, BEmail, DPChoice, DPHotspot)


        _DataP1GB = DataP1GB
        _DataP2GB = DataP2GB
        _DataP4GB = DataP4GB
        _DataPUnl = DataPUnl
        _AddYHotSpot = AddYHotSpot
        _AddNHotSpot = AddNHotSpot
    End Sub
    ' Overrides Function ComputeCosts() As Decimal
    Function ComputeCosts() As Decimal
        Dim BuyerTypeSCost As Decimal
        Dim BuyerDataPCost As Decimal
        Dim BuyerAddHSCost As Decimal
        Dim BuyerTotalCost As Decimal

        Const cdecInStoreSCost As Decimal = 0D
        Const cdecInternetSCost As Decimal = 28D
        Const cdecDataP1GBCost As Decimal = 30D
        Const cdecDataP2GBCost As Decimal = 50D
        Const cdecDataP4GBCost As Decimal = 70D
        Const cdecDataPUnlCost As Decimal = 120D
        Const cdecAddYHotSpCost As Decimal = 20D
        Const cdecAddNHotSpCost As Decimal = 0D
        Const cdecInStoreTaxCost As Decimal = 0.0775D
        If _DataP1GB Then
            BuyerDataPCost = cdecDataP1GBCost
        ElseIf _DataP2GB Then
            BuyerDataPCost = cdecDataP2GBCost
        ElseIf _DataP4GB Then
            BuyerDataPCost = cdecDataP4GBCost
        ElseIf _DataPUnl Then
            BuyerDataPCost = cdecDataPUnlCost
        End If

        If _AddYHotSpot Then
            BuyerAddHSCost = cdecAddYHotSpCost
        ElseIf _AddYHotSpot Then
            BuyerAddHSCost = cdecAddNHotSpCost
        End If

        If _Internet Then
            BuyerTypeSCost = cdecInternetSCost
            BuyerTotalCost = BuyerDataPCost + BuyerAddHSCost + BuyerTypeSCost
        ElseIf _InStore Then
            BuyerTypeSCost = cdecInStoreSCost
            BuyerTotalCost = (BuyerDataPCost + BuyerAddHSCost) * cdecInStoreTaxCost
        End If

        Return BuyerTotalCost
    End Function

End Class

在Visual Studio中,双击错误编号1.



IDE将带您到出错的代码部分,在本例中
In Visual Studio, double click on error number 1.

The IDE will take you to the part of the code that is in error, in this case
objBuyerCostsFile = New BuyerCost(_strBLName, _strBAddress, _strBZipCode, _strBEmail)

您只有一个类BuyerCost的构造函数:

You only have one constructor for class BuyerCost:

Sub New(strBLName As String, strBAddress As String, strBZipCode As String, strBEmail As String, decBPlanCost As String)

哟你需要通过输入decBPlanCost参数的值来纠正第一行,或者创建另一个不需要该值的构造函数或者为该参数提供一个可选值。



你有一个构造函数的另一个问题,你已经将参数声明为 String 但我怀疑你实际上是指 Decimal



如果双击第二个错误,那么您将进入DataPlan类和ComputeCosts方法。无论出于何种原因,您已使用覆盖关键字注释了正确的定义。



如果再遇到编译错误或警告然后遵循相同的技术 - 双击错误以找到问题并修复它。始终以错误编号1开头,因为许多后续错误将在您修复之前的错误时消失

So you either need to correct the first line by putting in a value for the decBPlanCost parameter OR create another constructor where that value is not required OR provide an optional value for that parameter.

You have another problem with that constructor in that you have declared the parameter as String but I suspect you actually meant Decimal

If you double-click on the 2nd error then you will be taken to your DataPlan class and the method ComputeCosts. For whatever reason you have commented out the correct definition with Overrides keyword.

If you hit any more compile errors or warnings then follow the same technique - double-click the error to locate the problem and fix it. Always start with Error number 1 as many subsequent errors will disappear as you fix earlier ones