Lesson 4 – Objects

Big Java 6

When you come in

  1. Connect to the Internet
  2. Log in to Piazza
  3. Start Bluej
  4. Navigate to laughton.com/obrien/sjsu/cs46a/CRT_lessons/ and open this lesson

Questions

Activity - Accessors and Mutators

Record your participation in Piazza clicker question Lesson4 Q1

Which methods of the Day class are mutators? Select all that apply. (Here is documenation for the Day class - opens in a new window)

  1. addDays
  2. daysFrom
  3. getDayOfMonth
  4. getMonth
  5. getYear
  6. toString

Activity - Accessors and Mutators

Record your participation in Piazza clicker question Lesson4 Q2

Which methods of the Day class are accessors? Select all that apply.

  1. addDays
  2. daysFrom
  3. getDayOfMonth
  4. getMonth
  5. getYear
  6. toString

Activity - Accessors and Mutators

Record your participation in Piazza clicker question Lesson4 Q3

The getHeight method of the Picture class is an accessor. (Here is the picture class documentation - opens in a new window)

  1. true
  2. false

 

Activity - Accessors and Mutators

Record your participation in Piazza clicker question Lesson4 Q4

The grow method of the Picture class is an accessor

  1. true
  2. false

 

Activity - Accessors and Mutators

Record your participation in Piazza clicker question Lesson4 Q5

Look at the Java API at the public interface of the String class.

Activity - More Graphics

Record your participation in Piazza clicker question Lesson4 Q6

Enhance the StairsViewer from last class. You can download StairViewer project if you need it.

Do this

 

Activity - Copying Rectangle References

Record your participation in Piazza clicker question Lesson4 Q7

What does this code print? (Remember the grow method adds to both sides.)

Rectangle  tile1 = new Rectangle( 10, 30, 50, 20);
Rectangle tile2  = tile1;
tile2.grow(5, 0);
System.out.println(tile1.getWidth() + " " + tile2.getWidth());
  
  1. 60 50
  2. 50 50
  3. 50 60
  4. 60 60

Activity - Creating two rectangles with same values

Record your participation in Piazza clicker question Lesson4 Q8

What does this code print? (Remember the grow method adds to both sides.)

Rectangle  tile1 = new Rectangle( 10, 30, 50, 20);
Rectangle tile2  = new Rectangle( 10, 30, 50, 20);
tile2.grow(5, 0);
System.out.println(tile1.getWidth() + " " +  tile2.getWidth());
  
  1. 60 50
  2. 50 50
  3. 50 60
  4. 60 60

Activity - Copying Numbers

Record your participation in Piazza clicker question Lesson4 Q9

What does this code print?

double salary1 = 12.50;
double salary2 = salary1;
salary2 = salary2 + 1.00;
System.out.println( salary1 + " " + salary2);
  1. 12.50 12.50
  2. 13.50 13.50
  3. 12.50 13.50
  4. 13.50 12.50

 

Activity - String References

Record your participation in Piazza clicker question Lesson4 Q10

What is printed here? Try it in code pad, and write your answers on a piece of paper or in text file.

String farewell = "Goodbye, Moon";
farewell.toLowerCase();
System.out.println(farewell); // 1
farewell.replace("o", "");
System.out.println(farewell);  // 2
String changed = farewell.toLowerCase();
System.out.println(farewell);  // #3
System.out.println(changed);  // #4
changed = changed.replace("o", "");
changed = changed.replace("e", "3");
System.out.println(changed); // #5
System.out.println(farewell); // #6