Reputation: 1625
I'm in a crash-course class that teaches us Python in 6-weeks and I've been having a hard time keeping up. Our teacher has now told us to work on a program that basically imitates a "Bus System" that revolves around three destinations and what we have to do is create different modules and classes and make them all interact with each other to work.
My problem is that I just don't understand how he wants me to do this and also I don't know what type of classes I need to have. This is how he describes the problem:
Build a model of a bus company. There should be at least 3 destinations (don't have too many!), several buses (each will be built by a Bus class, and should have a chosen number of seats, and be associated with a pair of destinations (one to leave from and one to arrive at -- these might get updated after each trip), and people (to choose the bus route they want and to sit in the buses). The buses should indicate if they're full, but until then should allow people to join the bus. Build such other structure to your model as makes sense to you without becoming overly sophisticated
So far I've come up with a people class ''' Created on Jul 7, 2013 @author: Rohan Vidyarthi, Papon Luengvarinkul '''
class Person :
'''This people class will allow me to make people'''
def __init__(self, name, ID, age, location, destination):
self.my_name = name
self.my_ID = ID
self.my_age = age
self.my_location = location
self.my_destination = destination
def introduce_myself(self):
return str(self.my_name + " " + str(self.my_ID) + " " + str(self.my_age) + " " + self.my_location + " to " + self.my_destination)
def __str__(self):
return self.my_name
But I don't really know how i'm going to do this. Also
I created a Bus class that has a constructor with the inputs of the bus number, where it goes, and its capacity.
I feel like I'm not going anywhere with this and i just need like a plan to start working on this like how to plan the program out
Upvotes: 0
Views: 5632
Reputation: 4399
You basically just need two classes. Passenger and Bus. A Bus class needs the following:
class Bus:
# Properties
route = "66"
source = "Where I came from"
detinsation = "Where I am going"
__capacity = Max Passengers
__passengers = {} # Key on the passenger name
# Methods
addPassenger(passenger)
removePassenger(passengerName)
class Passenger:
# Properties
name = "Foo"
route = "Not set"
I don't think it needs to be any more complicated than that. In your addPassenger method, you need to make sure you haven't reached your "capacity". If you have, raise an exception. Also ensure the parameter is type checked and only allows Passenger objects.
This doesn't really have anything to do with python, it's merely a simple problem that requires you to demonstrate some python knowledge. Realistically, this can be solved in any language.
Upvotes: 1