0% found this document useful (0 votes)
9 views

Computer Project

Uploaded by

ssadhan994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Computer Project

Uploaded by

ssadhan994
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

HARDWARE SPECIFICATIONS

➢ PC or Laptop with Multi-core CPU

➢ At least 4GB RAM (recommended)

➢ Operating System (Windows)

SOFRWARE SPECIFICATIONS

Python – 3.x or python IDLE (jupyternotebook)


CONTENTS

S.No. Topics Covered Page No.

1. Case Study

2. Coding

3. Outputs

4. Scope of
Improvement

5. Conclusion

6. Bibliography
CASE STUDY

This project is based on Bus management


System using python . This project deals with
managing the buses.

This project uses simple codings of


functions.
CODING
class Bus:
def __init__(self, bus_id, driver_name, capacity):
self.bus_id = bus_id
self.driver_name = driver_name
self.capacity = capacity

def __str__(self):
return f"Bus ID: {self.bus_id}, Driver:
{self.driver_name}, Capacity: {self.capacity}"

class Route:
def __init__(self, route_id, start_point, end_point):
self.route_id = route_id
self.start_point = start_point
self.end_point = end_point

def __str__(self):
return f"Route ID: {self.route_id}, From:
{self.start_point}, To: {self.end_point}"
class BusManagementSystem:
def __init__(self):
self.buses = {}
self.routes = {}

def add_bus(self, bus_id, driver_name, capacity):


if bus_id in self.buses:
print(f"Bus with ID {bus_id} already exists.")
else:
self.buses[bus_id] = Bus(bus_id, driver_name,
capacity)
print(f"Bus {bus_id} added successfully.")

def add_route(self, route_id, start_point, end_point):


if route_id in self.routes:
print(f"Route with ID {route_id} already
exists.")
else:
self.routes[route_id] = Route(route_id,
start_point, end_point)
print(f"Route {route_id} added successfully.")

def view_bus(self, bus_id):


bus = self.buses.get(bus_id)
if bus:
print(bus)
else:
print(f"No bus found with ID {bus_id}.")

def view_route(self, route_id):


route = self.routes.get(route_id)
if route:
print(route)
else:
print(f"No route found with ID {route_id}.")

def list_buses(self):
if self.buses:
for bus in self.buses.values():
print(bus)
else:
print("No buses available.")

def list_routes(self):
if self.routes:
for route in self.routes.values():
print(route)
else:
print("No routes available.")
def main():
system = BusManagementSystem()

while True:
print("\nBus Management System")
print("1. Add Bus")
print("2. Add Route")
print("3. View Bus")
print("4. View Route")
print("5. List Buses")
print("6. List Routes")
print("7. Exit")

choice = input("Enter your choice: ")

if choice == '1':
bus_id = input("Enter Bus ID: ")
driver_name = input("Enter Driver Name: ")
capacity = int(input("Enter Capacity: "))
system.add_bus(bus_id, driver_name, capacity)
elif choice == '2':
route_id = input("Enter Route ID: ")
start_point = input("Enter Start Point: ")
end_point = input("Enter End Point: ")
system.add_route(route_id, start_point,
end_point)
elif choice == '3':
bus_id = input("Enter Bus ID: ")
system.view_bus(bus_id)
elif choice == '4':
route_id = input("Enter Route ID: ")
system.view_route(route_id)
elif choice == '5':
system.list_buses()
elif choice == '6':
system.list_routes()
elif choice == '7':
print("Exiting the system.")
break
else:
print("Invalid choice, please try again.")

if __name__ == "__main__":
main()
import json
import os

class Bus:
def __init__(self, bus_id, driver_name, capacity):
self.bus_id = bus_id
self.driver_name = driver_name
self.capacity = capacity

def to_dict(self):
return {
'bus_id': self.bus_id,
'driver_name': self.driver_name,
'capacity': self.capacity
}

@classmethod
def from_dict(cls, data):
return cls(data['bus_id'], data['driver_name'],
data['capacity'])

def __str__(self):
return f"Bus ID: {self.bus_id}, Driver:
{self.driver_name}, Capacity: {self.capacity}"

class Route:
def __init__(self, route_id, start_point, end_point):
self.route_id = route_id
self.start_point = start_point
self.end_point = end_point

def to_dict(self):
return {
'route_id': self.route_id,
'start_point': self.start_point,
'end_point': self.end_point
}

@classmethod
def from_dict(cls, data):
return cls(data['route_id'], data['start_point'],
data['end_point'])

def __str__(self):
return f"Route ID: {self.route_id}, From:
{self.start_point}, To: {self.end_point}"
class BusManagementSystem:
def __init__(self):
self.buses = {}
self.routes = {}
self.load_data()

def add_bus(self, bus_id, driver_name, capacity):


if bus_id in self.buses:
print(f"Bus with ID {bus_id} already exists.")
else:
self.buses[bus_id] = Bus(bus_id, driver_name,
capacity)
print(f"Bus {bus_id} added successfully.")
self.save_data()

def add_route(self, route_id, start_point, end_point):


if route_id in self.routes:
print(f"Route with ID {route_id} already
exists.")
else:
self.routes[route_id] = Route(route_id,
start_point, end_point)
print(f"Route {route_id} added successfully.")
self.save_data()

def update_bus(self, bus_id, driver_name=None,


capacity=None):
if bus_id in self.buses:
bus = self.buses[bus_id]
if driver_name is not None:
bus.driver_name = driver_name
if capacity is not None:
bus.capacity = capacity
print(f"Bus {bus_id} updated successfully.")
self.save_data()
else:
print(f"No bus found with ID {bus_id}.")

def update_route(self, route_id, start_point=None,


end_point=None):
if route_id in self.routes:
route = self.routes[route_id]
if start_point is not None:
route.start_point = start_point
if end_point is not None:
route.end_point = end_point
print(f"Route {route_id} updated successfully.")
self.save_data()
else:
print(f"No route found with ID {route_id}.")

def delete_bus(self, bus_id):


if bus_id in self.buses:
del self.buses[bus_id]
print(f"Bus {bus_id} deleted successfully.")
self.save_data()
else:
print(f"No bus found with ID {bus_id}.")

def delete_route(self, route_id):


if route_id in self.routes:
del self.routes[route_id]
print(f"Route {route_id} deleted successfully.")
self.save_data()
else:
print(f"No route found with ID {route_id}.")

def view_bus(self, bus_id):


bus = self.buses.get(bus_id)
if bus:
print(bus)
else:
print(f"No bus found with ID {bus_id}.")

def view_route(self, route_id):


route = self.routes.get(route_id)
if route:
print(route)
else:
print(f"No route found with ID {route_id}.")

def list_buses(self):
if self.buses:
for bus in self.buses.values():
print(bus)
else:
print("No buses available.")

def list_routes(self):
if self.routes:
for route in self.routes.values():
print(route)
else:
print("No routes available.")

def save_data(self):
with open('buses.json', 'w') as f:
json.dump({bus_id: bus.to_dict() for bus_id, bus
in self.buses.items()}, f, indent=4)
with open('routes.json', 'w') as f:
json.dump({route_id: route.to_dict() for
route_id, route in self.routes.items()}, f, indent=4)

def load_data(self):
if os.path.exists('buses.json'):
with open('buses.json', 'r') as f:
buses_data = json.load(f)
self.buses = {bus_id: Bus.from_dict(data) for
bus_id, data in buses_data.items()}
if os.path.exists('routes.json'):
with open('routes.json', 'r') as f:
routes_data = json.load(f)
self.routes = {route_id: Route.from_dict(data)
for route_id, data in routes_data.items()}
def main():
system = BusManagementSystem()

while True:
print("\nBus Management System")
print("1. Add Bus")
print("2. Add Route")
print("3. Update Bus")
print("4. Update Route")
print("5. Delete Bus")
print("6. Delete Route")
print("7. View Bus")
print("8. View Route")
print("9. List Buses")
print("10. List Routes")
print("11. Exit")

choice = input("Enter your choice: ")

if choice == '1':
bus_id = input("Enter Bus ID: ")
driver_name = input("Enter Driver Name: ")
capacity = int(input("Enter Capacity: "))
system.add_bus(bus_id, driver_name, capacity)
elif choice == '2':
route_id = input("Enter Route ID: ")
start_point = input("Enter Start Point: ")
end_point = input("Enter End Point: ")
system.add_route(route_id, start_point,
end_point)
elif choice == '3':
bus_id = input("Enter Bus ID to update: ")
driver_name = input("Enter new Driver Name
(leave blank if no change): ")
capacity = input("Enter new Capacity (leave
blank if no change): ")
capacity = int(capacity) if capacity else None
system.update_bus(bus_id, driver_name or
None, capacity)
elif choice == '4':
route_id = input("Enter Route ID to update: ")
start_point = input("Enter new Start Point (leave
blank if no change): ")
end_point = input("Enter new End Point (leave
blank if no change): ")
system.update_route(route_id, start_point or
None, end_point or None)
elif choice == '5':
bus_id = input("Enter Bus ID to delete: ")
system.delete_bus(bus_id)
elif choice == '6':
route_id = input("Enter Route ID to delete: ")
system.delete_route(route_id)
elif choice == '7':
bus_id = input("Enter Bus ID to view: ")
system.view_bus(bus_id)
elif choice == '8':
route_id = input("Enter Route ID to view: ")
system.view_route(route_id)
elif choice == '9':
system.list_buses()
elif choice == '10':
system.list_routes()
elif choice == '11':
print("Exiting the system.")
break
else:
print("Invalid choice, please try again.")
if __name__ == "__main__":
main()
OUTPUT

You might also like