View Single Post
  #1   Spotlight this post!  
Unread 10-30-2009, 10:45 PM
isaacdl isaacdl is offline
I have a white hat..it's just dirty
AKA: Isaac Dontje Lindell
FRC #3018 (Nordic Storm)
 
Join Date: Oct 2009
Rookie Year: 2010
Location: St. Peter
Posts: 32
isaacdl is an unknown quantity at this point
Question regarding interfaces

Hi,

I'm trying to teach myself Java for this years competition, having never done anything more complex than Liberty Basic. I understand classes, and how to use one to define an object. I'm using the Java tutorials on Sun.com to teach myself. I got to the section on interfaces, and for the life of me I cannot understand how to use them, or even what they are.
I have this sample program (attached), which uses bicycles as an example class. There is the superclass Bicycle, and the subclass MountainBike. 3 objects are defined, bike1, bike2, and bike3. Bike1 and bike2 are normal Bicycle objects, and bike3 is a MountainBike.

Bicycle has states "cadence", "speed", and "gear". It has methods "changeCadence", "changeGear", "speedUp", "applyBrakes".

MountainBike extends class Bicycle to include state "awesomeness" (first state that popped to mind )

At the end, the program prints the states of each bike.

How would I use interfaces in a useful manner in this program? What use are they in general?

Thanks,
Isaac
Reply With Quote