207Tutorial5.pdf

5 Pages
95 Views
Unlock Document

Department
Computer Science
Course
CSC207H1
Professor
Ted Petit
Semester
Fall

Description
CSC  207  Tutorial  5     Purpose:   The  purpose  of  this  lab  is  to  get  you  familiar  with  inheritance.  Take  this  as  an   excellent  learning  opportunity  to  write  some  code  an d  in  the  process  learn  (inheritance,   function  overriding,  super  and  much  more).  As  you  work  through  the  tutorial,  if  you  have   questions  about  inheritance,  please  do  ask   the  TA.         Submission  (only  one  lab  partner  must  do  this):           1)  Login    to  MarkUs  @    https://stanley.cdf.toronto.edu/markus/csc207 -­‐2012-­‐05/en   2)  Go  to  Tutorial5.       3)  Make  sure  that  you  add  your  lab  partner  to  your  group  in  MarkUs.       4)  Upload  three  files  (studentInfo.txt,  Bicycle.java  and  MountainBike.java)   (you  don’t  have  to  use  svn   for  this)   5)  studentInfo.txt  must  contain  your  and  your  lab  partner  name,  cdf  username  and  student  ID.       Part  1:       Open  up  Eclipse  or  any  other  IDE  that  you  wish  to  use  for  Java.  Create  a  new  Java  Project.  In   the  Java  Project  add  a  new  class  called  Bicycle.  The  Bicycle  class  must  have  three  public   instance   variables   of   type   int   i.e.   (cadence,   gear,   speed).   It   must   have   one   public   constructor  that  takes  in  three  input  int  variables   (startCadence,  startSpeed  and  startGear).   All  this  constructor  does  is  that  it  sets  the  three  local  variables   (startCadence,  startSpeed   and   startGear)   to   the   three   instance   variables   of   the   class   (cadence,   gear,   speed).     The   Bicycle  class  also  has   five  instance  methods  as  follows:                 Part  2:       Before   you   start   with   Part2,   you   must   feel   comfortable   with   what   are   instance   methods  and  class  methods.  If  you  have  concerns  on  this  topic,  please  ask  the  TA.     You  must  also  have  your  Bicycle  class  completely  written  as  per  the  specs  in  Part1.         a) Now  write  a  new  Java  class  called  ‘Mountain  Bike’.  It  must  be  in  the  same   folder/package  as  your  ‘Bicycle’  class.    Mountain  Bike  must  inherit  from  the   Bicycle  class.  Do  you  remember  how  to  do  this?         b)  At  this  point  MountainBike  has  inherited  all  the  instance  variables  and  instance   methods  of  the  Bicycle  class.  Remember:  Whatever  is  public  or  protected  in  Bicycle   class  has  been  inherited  by  the  MountainBike  class.  None  of  the  private  stuff  gets   inherited.  So  if  the  Bicycle  class  had  some  private  instance  variables  or  instance   methods,  they  will  not  get  inherited.       c)  Your  MountainBike  class  must  add  an  public  instance  variable  called  seatHeight   of  type  int  and  a  public  instance  method  called  setHeight  i.e.                         d)  Your  constructor  for  MountainBike    is:          
More Less

Related notes for CSC207H1

Log In


OR

Join OneClass

Access over 10 million pages of study
documents for 1.3 million courses.

Sign up

Join to view


OR

By registering, I agree to the Terms and Privacy Policies
Already have an account?
Just a few more details

So we can recommend you notes for your school.

Reset Password

Please enter below the email address you registered with and we will send you a link to reset your password.

Add your courses

Get notes from the top students in your class.


Submit