Whats the difference between these two classes

Hi I have a question about these two class's , • The bus (i.e., what values does it need to store and what actions can it take) • The command (i.e., what type of command has been issued to what bus and what values) I'm confused as to what the difference would be, the bus class will have the function where it moves it self. But then what is the command class for? I need to use to different classes for this one has been called bus and other command.

Guidlines--- You are running a bus company with four buses. These buses will move around based on commands provided from keyboard input. To move a bus, you will issue a command from the keyboard with the bus identification, direction, and number of spaces to move. For example: B W 3 Would move Bus “B” three spaces to the West. All buses will start at the bus station at coordinates (0,0). A “N”orth command would increment the y-coordinate; “S”outh decrement the y-coordinate. A “E”ast command increments the x-coordinate and a “W”est command decrements the x-coordinate. You will also accept commands to pick up and drop off people: D P 5 A D 2

2 answers

  • answered 2017-11-14 23:50 SynchroDynamic

    In trying to understand your question, I see a bus class also known as a bus object.

    It is just like a physical bus with attributes like:

    License plate number Capacity

    And whatever other attributes make up that bus.

    The command class if I am reading correctly is a class that can be inherited by bus, but it could also be inherited by other objects. If you had a bus object and a car object, they both have a license plate.

    If a bus and a car had some different attributes, they would be different.

    They could both inherit the command class however, and if the command class were to have a go function, they would both be able to go.

    Abstraction and polymorphism can be tricky, but it is key to object oriented programming.

    I hope this helps.

  • answered 2017-11-15 00:26 samuelnj

    Still confusing, but I'll give it a shot. If these are the only two classes in your program I think the division is pretty clear.

    The Bus will be a class that holds information about the bus. It will have member variables that represent its position on the "map" (x,y) with a move function that will update these member variables. So when you call busname.move(variables) it will move like you want it to and update its position. Additionally it seems like it would have a variable representing how many people are on board.

    The command class is something else entirely, it would be the main control for your program. It would have instances of the bus class as its members (A,B,C,D) and it would interpret commands from the keyboard to determine what command to issue to what bus. For example, if you type A W 3 on the keyboard how is bus A ever supposed to know to move to the west three spaces? Because the command class will take the keyboard input and call A.move(-3, 0) or something like that to update its position.

    Hope this helps.