Lab4 - CS 241 Lab 4 Lab 4: Inheritance & Polymorphism CS...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 241 Lab 4 1 | P a g e CS 241 PURPOSE This lab demonstrates two tightly related central concepts of object-oriented programming: inheritance and polymorphism. Inheritance allows you to build complex classes from simpler parent classes, while polymorphism allows a superclass (i.e a parent class) variable to reference objects of a subclass. This lab allows you to practice polymorphism and inheritance in Java by building related classes of increasing complexity from an initially simple class and using those classes in a polymorphic manner. ASSIGNMENT 4A : Subtyping the “Geek” class The local bully in your school has been terrorizing geeks for years, but lately, it seems like there are so many geeks running around that he can hardly keep track of them. The bully is also apparently the second smartest computer geek in school and develops a geek-tracking program. The program keeps track of different kinds of geeks and how geeky on a scale of 1 to 10 each geek is (his or her geek factor, 10 being the geekiest geek possible). In addition to a constructor, your geek classes contains public getter and setter methods, a toString method that shows the geek’s name and geek factor, and a harass method that tells the bully how to terrorize the geek based upon the geek factor. To keep the harass method simple, a helper method, getHarassment() identifies an appropriate generic harassment given a specific geek level. A second class of objects keeps track of Star Trek geeks. In addition to all of the fields and
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/03/2010 for the course CS 240 taught by Professor Staff during the Spring '08 term at Wright State.

Page1 / 3

Lab4 - CS 241 Lab 4 Lab 4: Inheritance & Polymorphism CS...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online