Lesson 3 – Objects and Methods

When you come in
- Connect to the Internet
- Log in to Piazza
- Start Bluej
- Navigate to laughton.com/obrien/sjsu/cs46a/CRT_lessons/ and open this lesson
Activity - Public Interface of Day class
Record your participation in Piazza clicker question Lesson3 Q1
Which methods of the Day class take a argument? Select all that apply. (Here is documenation for the Day class - opens in a new window)
- addDays
- daysFrom
- getDayOfMonth
- getMonth
- getYear
- toString
Activity - Public Interface of Day class
Record your participation in Piazza clicker question Lesson3 Q2
Which methods of the Day class return a value? Select all that apply.
- addDays
- daysFrom
- getDayOfMonth
- getMonth
- getYear
- toString
Activity - Public interface of the Picture class
Record your participation in Piazza clicker question Lesson3 Q3
The getHeight method of the Picture class returns a value. (Here is the picture class documentation - opens in a new window)
- true
- false
Activity - Public interface of the Picture class
Record your participation in Piazza clicker question Lesson3 Q4
The grow method of the Picture class returns a value
- true
- false
Activity - Public interface of the String class
Record your participation in Piazza clicker question Lesson3 Q5
Look at the Java API at the public interface of the String class. (In your search engine, type java api string. Then select String ...)
- Does the charAt method take a parameter?
- Does the charAt method return a value?
- Does the toLowerCase method take a parameter?
- Does the toLowerCase method return a value?
Activity - Constructing Objects - Rectangles
Record your participation in Piazza clicker question Lesson3 Q6
Let's work on a project together to draw a staircase like the one below. The upper left hand corner is at (20, 10). Each step is 20 pixels tall. The first step is 20 pixels wide. Each of the following steps is 20 pixels wider than the one above.

- Create a new Bluej project
- Download the Horstmann graphics if you haven't already
- and put it somewhere you can find it
- Import the Horstmann graphics package you downloaded
- Create a class called StairViewer
- Delete all the code between the braces
- Add a main mehod
- Follow these specifications to draw the staircase
- The upper left hand corner of the first step is at (20, 10).
- Each step has a height of 20 pixels
- Construct and draw the top step first. It has a width of 20 pixels. (What is a good variable name for the top step?)
- Construct and draw the second step next. What are its coordinates? What is its width (20 more than the one above it)?
- Construct and draw the bottom step last. What are its coordinates? It has a width of 60 pixels. What is its width (20 more than the one above it)?
Activity - Using String methods
Record your participation in Piazza clicker question Lesson3 Q7
Let's experiment with String methods
- Create a new Bluej project
- Create a class called StringActivity
- Add a main method
- Declare and initialize a String variable word with a value of "University"
- Get a lowercase version of the string and print it.
- Print the original word
- Make all of the following replacements
- s with $
- i with 1 (number one)
- e with 3
- Print the new word with the replacements (Un1v3r$1ty)
- Print the original word (University)