RU beehive logo ITEC dept promo banner
ITEC 120
2010fall
ibarland

homeinfolectslabsexamshws
tutor/PIsObject120 + its docsjava.lang docsjava.util docs

lect08c
loop intro
and, Random

See quiz-week08c-static-to-OO—practice: converting static calls to OO

Reminder: “static” means associated with                 , not with any particular                 .

For fields: If you have created 100 Song objects, then you have                  fields for title, and                  fields for MB_PER_SEC. Even if you have zero Song objects created, you still have                  static field.

For methods: If you haven't created any objects yet, you can't call any                  methods, but you can call a                  method.

Note the perspective-change: Rather than "hey function, give me the answer (and here are the arguments you need)", the object-oriented perspective thinks of it as "hey object, I want you do to something for me (and here is the *additional* info you need that you don't already have inside you)".

We have two ways of doing things, and have spent the week translating between static and object-oriented ways of doing the same thing. Why? What does O.O. give us? We'll see later: O.O. makes it easier to write future-compatiable code. E.g. I wrote code a while back that took in an object and called its toString method. Then you came along later, made class Robot, and made your own tailored toString for it -- and my old legacy code calls your recent toString automatically!


Our starting code
 - StudentTester: paste code several times repeat code
 - pull into helper function; note scope issues.
 - add an 'if' statement, to only continue while num hours is < 120.
   Note: the one-armed if.
   We have this when we have mutation (side-effects),
   (footnote: including modifying a local variable).
 - make a while statement

Our resulting loop

homeinfolectslabsexamshws
tutor/PIsObject120 + its docsjava.lang docsjava.util docs


©2010, Ian Barland, Radford University
Last modified 2010.Oct.25 (Mon)
Please mail any suggestions
(incl. typos, broken links)
to iba�rlandrad�ford.edu
Powered by PLT Scheme