RU beehive logo ITEC dept promo banner
ITEC 120
2019fall
asbrennem
ibarland

Strings
and setup: Object120.java

Note: To access your U: drive from home / off-campus: see the post on the course's D2L discussion-board.
Remember that in lab intro, we made a folder “itec120” in our U: drive, for all the notes & files for this course.
  1. We will take a few minutes to finish and discuss lab intro. You'll presumably want to Save As… your project onto your U: drive. If you can't locate your file from last time, you can copy/paste this file into BlueJ.
  2. Using Object120

  3. 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 .././../Lib/ITEC120/Object120.java somewhere on your U: 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. Press the Compile button, to make sure it works.
      In the Code Pad, also test it by typing Object120.substring("hello",2,4) and make sure you get the answer "ll".
  4. 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.
  5. Strings

  6. 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.
  7. 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.)
  8. Try the following conversion-functions:
  9. 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.
  10. Make at least two more test cases, trying to predict the answers:
  11. 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.
  12. 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 vice versa..      

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.