December 17th, 2012, 06:08 AM
-
Need Help Please
I have a HW problem that I am able to get it to work with using select case, but I know that there is a much easier method, like a If...Then statement, however it doesn't work
This is a HW? I am using Visual Basics 2010 Express
I need to create an application that calculates and displays a customer's bill. Business customers must have at least one connection. Be sure to use one or more independent sub or Function procedures in the application.
Residential customers: Processing fee = $4.50; Basic Service Fee = $30; and Premium channels = $5 per channel.
Business customers: Processing fee = $16.50; Basic Service fee = $80 for the first 10 connections and $4 for each additional connections; Premium channels = $50 per channel for any number of connections
Here is the code that I am able to have work, need help consolidating:
Option Explicit On
Option Strict On
Public Class MainForm
Private Function CalcBusiness(ByVal process1 As Double, ByVal service1 As Double, ByVal price1 As Double) As Double
' add basic charges for business customers to calculate the total of a cable bill
' declare variables
Dim total1 As Double
Dim processingFee As Double = 16.5
Dim serviceFee As Double
Dim premiumChannels As Double
Dim connections As Double
Dim price As Double
' determine the service fee for number of connections
' customers must have at least 1 connection
serviceFee = connectionsListBox.SelectedIndex
Select Case serviceFee
Case 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
connections = 80
Case 10
connections = 84
Case 11
connections = 88
Case 12
connections = 92
Case 13
connections = 96
Case Else
connections = 100
End Select
' determine the price for the premium channels
premiumChannels = premListBox.SelectedIndex
Select Case premiumChannels
Case 0
price = 0
Case 1
price = 50
Case 2
price = 100
Case 3
price = 150
Case 4
price = 200
Case 5
price = 250
Case 6
price = 300
Case 7
price = 350
Case 8
price = 400
Case 9
price = 450
Case Else
price = 500
End Select
' calculate and display the total charge
total1 = processingFee + connections + price
totalDueLabel.Text = total1.ToString("C2")
Return total1
End Function
Private Function CalcResidential(ByVal process2 As Double, ByVal service2 As Double, ByVal price2 As Double) As Double
' add basic charges for residential customers to calculate the total of a cable bill
' declare variables
Dim total2 As Double
Dim processingFee As Double = 4.5
Dim serviceFee As Double = 30
Dim premiumChannels As Double
Dim price As Double
' customers must have at least 1 connection, but the service fee is flat at $30
' determine the price for the premium channels
premiumChannels = premListBox.SelectedIndex
Select Case premiumChannels
Case 0
price = 0
Case 1
price = 5
Case 2
price = 10
Case 3
price = 15
Case 4
price = 20
Case 5
price = 25
Case 6
price = 30
Case 7
price = 35
Case 8
price = 40
Case 9
price = 45
Case Else
price = 50
End Select
' calculate and display the total charge
total2 = processingFee + serviceFee + price
totalDueLabel.Text = total2.ToString("C2")
Return total2
End Function
Private Sub calcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles calcButton.Click
If businessRadioButton.Checked = True Then
Dim processingFee As Double
Dim connections As Double
Dim price As Double
' call a function procedure to perform calculations
Call CalcBusiness(processingFee, connections, price)
Else
Dim processingFee As Double
Dim serviceFee As Double
Dim price As Double
' call a function procedure to perform calculations
Call CalcResidential(processingFee, serviceFee, price)
End If
End Sub
Private Sub exitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles exitButton.Click
Me.Close()
End Sub
Private Sub clearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearButton.Click
totalDueLabel.Text = String.Empty
End Sub
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
December 18th, 2012, 12:27 PM
-
This appears to be a duplicated question, thread closed.
======
Doug G
======
I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton