RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

lab01b
Strings
and setup: H: drive; Object120.java

  1. Mount your H: drive:
    1. Mapping your H: drive (windows)
    2. Mapping your H: drive (mac)
    3. Alternately: instead of having your H: drive appear on the desktop, another option is manually transferring files to/from H: drive via myRU.
    4. If you want to map your H: drive from off-campus (or, use any campus-computer resource from off-campus), you can connect your computer to a campus "virtual private network": Installing VPN (windows)
  2. We will take a few minutes to finish and discuss lab01a—lab intro: Compiling a program with BlueJ. You'll presumably want to Save As… your project onto your H: drive. If you can't locate your file from last time, you can copy/paste this file into BlueJ.
  3. Using Object120

  4. Add Object120: For much of this class, we will use an extra file to help us, “Object120.java”. To add it to your BlueJ project:
    1. Right-click, and save Object120.java somewhere on your H: drive. (Note that we'll be using this file for each lab and homework project, for about ten weeks.)
    2. In your already-created BlueJ project, select Edit > Add Class from File…, and then select the Object120.java you just saved. Compile, to make sure it works.
    3. Back in Pizzeria.java, we'll add two words: change “class Pizzeria {” to “class Pizzeria extends Object120 {”. This will allow us to use all the helper functions from Object120 inside Pizzeria (without needing to spell out its full name).
  5. Double-click on Object120, and in the upper-right change Source Code to Documentation. These are the signatures of all the methods defined inside Object120. We'll be calling several of those methods today.
  6. Strings

  7. In the code pad, type "hello". This is a piece of data shoe type is String (a bunch of individual characters, strung together). We've seen some Strings already, in our System.out.println statements.
  8. There are several functions that can work on Strings. Try typing the following, in Code Pad. (Remember: up-arrow in Code Pad will bring back previously-typed expressions, saving you a lot of time.)
  9. Calling these functions from a program

  10. Now let's call some of these same functions from inside a program. Go back to class Pizzeria, and let's make a new function void testStringFuncs().
    (See if you can declare an empty function and compile it. Look to see exactly what was needed for void testPizzeria().)
  11. Let's write some test cases to see if the String function are behaving as expected in some more involved situations:
          System.out.println( "Computing: " + charAt(toUpperCase("howdy"), 2) );
          System.out.println( "Expected: ???" );
        
    where you replace "???" with what you and your partner think the answer should honest-to-gosh be.
  12. Make at least two more test cases, trying to predict the answers:
  13. Note: When calling a function like charAt: In the code-pad, we need to type its full name, “Object120.charAt”. But inside your class, you may omit it (though certainly may still include it, if that consistency makes more sense to you). If you're curious about the Java's reasoning behind this: We're allowed to omit the full-name inside the class, because (a) code inside class Pizzeria is already on a first-name basis with all functions in the same class; you don't need to specify the full name, and (b) because “class Pizzeria extends Object120”, everything that is Object120 knows is also known by Pizzeria1.
  14. The following doesn't make sense. First try adding it as a test case and compiling -- this will give you a syntax error. With your partner, read the error, and see if you can figure out why it doesn't quite make sense: toUpperCase( charAt("howdy", 2) ).

1 In object-oriented lingo, “Pizzeria extends Object120” means “Every Pizzeria is an Object120, although not &vv;.”.      

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2012, Ian Barland, Radford University
Last modified 2012.Aug.30 (Thu)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme