Personal tools
You are here: Home Members mpate1's Home Lab7
Document Actions


by Mit Patel last modified 2006-03-02 05:53 PM

Classes. This is only to demonstrate how two classes work together. Some things like storing of #of passengers and their info requires arrays and what now. For the purpose of the lab though just think simple. (I MEAN VERY SIMPLE) :)

People class requirements are posted in course documents. Following is Car class requirements. These two classes are to work with each other to make manipulating objects more interesting.

  1. Car class should have passengers, a driver and speed (acceleration & deceleration). Use default and parameter constructor to create a car object. To assign person to the car you will use an attritube person which will have a type People Class.
  2. Car constructor should have #of driver(this will be 1 rite now), #of passengers and speed of car.
  3. You will then need to have 3 get methods and a display CarInfo method:
    1. Passengers that return #of passenger
    2. getPerson that returns a person (hint: has type People Class)
    3. Speed that uses acceleration and deceleration to change the speed
    4. CarInfo which is like a display method that displays #of passengers, name and gender which comes from People class again and the speed.
  4. You will thus need the set methods accordingly. Note: CarInfo is a display method so it doesn’t need the set method 

This is just bare minimum of what you can have to make People and Car classes to work together. There are no restrictions for the lab assignment now but if you see the optional part it will show you what kind of restrictions apply. Play around on object bench with these classes or have a nice and simple Test Class depending on time. Once this is done go on to optional part which is much more fun.

Optional part:


  1. Your method should allow to assign gender to passengers (this comes from People class) and there should be no more than 3 passengers. When you allocate driver position to one of them, the method should return driver already exist and if driver doesn’t exist than the person is allocated the driver position.
  2. You can assign age to the passengers which also come from the People class. If age < 18 & > 60 then can’t be a driver, can only be a passenger.
  3. Speed method should have accelerate 5x if speed is 15 and decelerate 5x if speed is higher than 100.

Be creative, think of cool things you can do with cars and assign attributes or methods accordingly.

Create a test class that includes the usage of both of these classes. Be creative though. User input would be a start.

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: