158.326 Software Construction
Tutorial 1
Create C# projects of Windows Forms App and Console App using Microsoft Visual Studio 2022 for the following scenario:
A payment kiosk is used by staff and customers to pay for parking tickets.
Parking rules are as follows:
Staff:
1. The parking charges for the first ten hours are $2.00.
2. Further parking beyond 10 hours will incur a charge of $2.00 per hour.
3. Parking time cannot exceed 24 hours. If a car is parked for more than 24 hours, it will be towed away.
Customer
1. The parking charges are based per hour. Parking per hour = $ 2.00
2. Parking time cannot exceed 24 hours. If a car is parked for more than 24 hours, it will be towed away.
The program should display the parking charges for each staff or customer. Charges are calculated based on the number of hours a car has been parked.
You have to make a two-tier design:
Class Design
Identify what classes you are going to use. What will be the fields, properties and methods?
Hints:
1. Useful Math functions: Math.Ceiling, Math.Abs(x), Math.Floor(x), Math.Max(x,y), Math.Min(x,y)
If a person has parked for 3.5 hours, the kiosk will charge him for 4 hours. So, use Math.Ceiling function
Math.Ceiling(3.5) = 4
2. To display output in currency format – use ToString(“C”) (refer to
http://msdn.microsoft.com/en-us/library/dwhawy9k(v=vs.110).aspx
Reference:
Pro C# 5.0 and .NET4.5 Framework
Author: Andrew Troelsen
ISBN: 978-1-4302-4234-5
Edition: 6th , Publisher: Apress, E-book
Chapter 5 – Understanding Encapsulation
Chapter 6 – Understanding Inheritance and Polymorphism
Chapter 7 – Understanding Structured Exception Handling
HINT:
• User interface design and sample output for your Windows Forms App
On selecting Customer or Staff, and clicking the “Next” button:
The parking amount varies for customer and staff
If parking exceeds 24 hours, an exception is thrown from a class member and caught by the form.
• Sample output for your Console App: