A simple demonstration of OOP styles.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using ParkingLot.Vehicles;
  7. namespace ParkingLot
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. ParkingLot parkingLot = ParkingLot.CreateParkingLot(5, 5, 20);
  14. parkingLot.VehicleLeftEvent += ParkingLot_VehicleLeftEvent;
  15. Console.WriteLine("Type 'add' to add a vehicle. 'exit' to close the program.");
  16. bool run = true;
  17. while (run)
  18. {
  19. string command = Console.ReadLine();
  20. switch (command)
  21. {
  22. case "add":
  23. Vehicle newVehicle = Vehicle.CreateVehicle(600);
  24. bool success = parkingLot.AddVehicle(newVehicle);
  25. if (success)
  26. {
  27. Console.WriteLine("{0} Parked Successfully at Level {1}, Row {2}, Space {3}", newVehicle.VehicleType, newVehicle.Level, newVehicle.Row, string.Join(",", newVehicle.Spaces));
  28. }
  29. else
  30. {
  31. Console.WriteLine("The parking lot was full for the {0}", newVehicle.VehicleType);
  32. }
  33. break;
  34. case "exit":
  35. run = false;
  36. break;
  37. default:
  38. break;
  39. }
  40. }
  41. }
  42. private static void ParkingLot_VehicleLeftEvent(double price)
  43. {
  44. Console.WriteLine("Vehicle Left - Price: ${0}", price);
  45. }
  46. }
  47. }