-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
118 lines (103 loc) · 4.05 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
using CarRentingSystem.Management;
using CarRentingSystem.Services;
using System;
namespace CarRentingSystem
{
class Program
{
static void Main(string[] args)
{
CarRentalSystem carRentalSystem = new CarRentalSystem();
AdminPanel adminPanel = new AdminPanel(carRentalSystem);
carRentalSystem.AddCar(new Car("Toyota", "Corolla", 2020, 300));
carRentalSystem.AddCar(new Car("Honda", "Civic", 2019, 280));
carRentalSystem.AddCar(new Car("Ford", "Focus", 2018, 250));
bool isRunning = true;
while (isRunning)
{
Console.Clear();
Console.WriteLine("=== Car Rental System ===");
Console.WriteLine("1. List Available Cars");
Console.WriteLine("2. Rent a Car");
Console.WriteLine("3. End Rental");
Console.WriteLine("4. List Rented Cars");
Console.WriteLine("5. Admin Menu");
Console.WriteLine("6. Exit");
Console.Write("Please select an option (1-6): ");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
carRentalSystem.ListAvailableCars();
break;
case "2":
RentCarMenu(carRentalSystem);
break;
case "3":
EndRentalMenu(carRentalSystem);
break;
case "4":
carRentalSystem.ListRentedCars();
break;
case "5":
adminPanel.ShowAdminMenu();
break;
case "6":
isRunning = false;
Console.WriteLine("Exiting the system. Goodbye!");
break;
default:
Console.WriteLine("Invalid choice, please try again.");
break;
}
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
static void RentCarMenu(CarRentalSystem carRentalSystem)
{
Console.Clear();
Console.WriteLine("Enter the brand and model of the car you want to rent:");
carRentalSystem.ListAvailableCars();
Console.Write("Brand: ");
string brand = Console.ReadLine();
Console.Write("Model: ");
string model = Console.ReadLine();
Console.Write("Rental Days: ");
int days = int.Parse(Console.ReadLine());
Car car = carRentalSystem.FindCar(brand, model);
if (car != null && !car.IsRented)
{
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Console.Write("Enter your ID: ");
string id = Console.ReadLine();
Customer customer = new Customer(name, id);
carRentalSystem.RentCar(car, customer, days);
}
else
{
Console.WriteLine("The car is either rented or not found.");
}
}
static void EndRentalMenu(CarRentalSystem carRentalSystem)
{
Console.Clear();
Console.WriteLine("Enter the brand and model of the car you want to return:");
Console.Write("Brand: ");
string brand = Console.ReadLine();
Console.Write("Model: ");
string model = Console.ReadLine();
Car car = carRentalSystem.FindCar(brand, model);
if (car != null && car.IsRented)
{
carRentalSystem.EndRental(car);
Console.WriteLine("The rental has been successfully ended.");
}
else
{
Console.WriteLine("The car is either not rented or not found.");
}
}
}
}