A parking garage charges a $2.00 minimum fee to park for up to three hours. The
ID: 3548732 • Letter: A
Question
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 app 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 app should display the charge for the current customer and should calculate and display
the running total of yesterday
Explanation / Answer
using System.IO;
using System;
public class ParkingFee
{
public static double CalculateCharges(int no_of_hours)
{
double charge = 2.0;
if(no_of_hours<=3)
charge = 2.0;
else if(no_of_hours>3)
{
charge = 2.0 + (no_of_hours-3)*0.5;
}
if(charge>10)
charge = 10;
return charge;
}
public static void Main()
{
int no_of_customers;
Console.WriteLine("Enter no of Customers Yesterday :");
no_of_customers = int.Parse(Console.ReadLine());
int[] customer_array = new int[no_of_customers];
for(int i=0; i<no_of_customers; i++)
{
Console.WriteLine("How Many Hours Customer" + (i+1) + " Parked Yesterday :");
customer_array[i] = int.Parse(Console.ReadLine());
}
for(int i=0; i<no_of_customers; i++)
{
Console.WriteLine("Customer " + (i+1) + " Parking Fee Given by : " + CalculateCharges(customer_array[i]));
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.