A parking garage charges a $2.00 minimum fee to park for up to three hours. The garage charges an additional $0.50 per hour for each hour or part thereof in excess of three hours. The maximum charge for any given 24-hour period is $10.00. Assume that no car parks for longer than 24 hours at a time. Write an application that calculates and displays the parking charges for each customer who parked in the garage yesterday. You should enter the hours parked for each customer. The program should display the charge for the current customer and should calculate and display the running total of yesterday’s receipts. It should use the method calculateCharges to determine the charge for each customer.
Imports System.IO
Module Module1
Sub Main()
Dim customerHours(2) As Double
For customer As Integer = 1 To 3
Console.Write("Enter customer " + customer.ToString() + " parking hours: ")
customerHours(customer - 1) = Double.Parse(Console.ReadLine())
Next
Console.WriteLine(String.Format("{0,-10}{1,-10}{2,-10}", "Cars", "Hours", "Charges"))
Dim totalCharges As Double = 0
Dim totalHours As Double = 0
For i As Integer = 0 To 2
Dim charges As Double = calculateCharge(customerHours(i))
Dim chargesStr As String = charges.ToString()
If charges = 0 Then
chargesStr = "No car parks for longer than 24 hours at a time."
End If
Console.WriteLine(String.Format("{0,-10}{1,-10}{2,-10}", (i + 1), customerHours(i), chargesStr))
totalCharges += charges
totalHours += customerHours(i)
Next
Console.WriteLine(String.Format("{0,-10}{1,-10}{2,-10}", "Total", totalHours, totalCharges))
Console.ReadLine()
End Sub
Function calculateCharge(ByVal hours As Double)
Dim currentHours As Double = hours
Dim charge As Double = 2.0
If (currentHours > 0) Then
If (currentHours <= 3) Then
Return charge
ElseIf (currentHours <= 24) Then
While (currentHours > 3)
charge += 0.5
currentHours -= 1
If (charge >= 10) Then
charge = 10
End If
End While
Return charge
End If
End If
Return 0
End Function
End Module
Comments
Leave a comment