SJSU/Udacity CS046

Lesson 2 - Objects

  1. Introduction
  2. Introducing Ellora
  3. Why OOP is Important
  4. Objects
  5. Objects Demo
  6. Quiz: Mariner 4
  7. Classes
  8. Quiz: Match the Methods
  9. Drawing Pictures
  10. Quiz: What Does This Method Do?
  11. Variables
  12. Variable Names
  13. Quiz: An Exercise on Variable Names
  14. Variable Types
  15. Quiz: Variable Types
  16. Initial Values
  17. Quiz: Initial Values
  18. Comments
  19. Quiz: How Many Days
  20. Quiz: Adding Comments
  21. Quiz: Variable Declarations: The Fine Print
  22. Variable Values Can Change
  23. Public Interfaces
  24. Public Interfaces 2
  25. Arguments and Return Values
  26. Quiz: Arguments and Return Values Exercise
  27. Method Declarations
  28. Quiz: Method Description
  29. Quiz: More Method Descriptions
  30. Constructing Objects
  31. Making Rectangles
  32. Quiz: Constructing Rectangles
  33. String Methods
  34. Quiz: The replace Method
  35. Quiz: The trim Method
  36. Quiz: toUpperCase and toLowerCase
  37. Accessors and Mutators
  38. Quiz: Accessor or Mutator?
  39. Quiz: Accessor or Mutator? 2
  40. Quiz: Pitfall
  41. Shared Objects
  42. Quiz: Copying Rectangles
  43. Quiz: Copying Strings
  44. Quiz: Copying Numbers
  45. Implementing a Test Program
  46. Quiz: Test Program
  47. Why It's Important to Test Your Code
  48. More About Graphics
  49. Quiz: Draw a Crate
  50. Quiz: Write Top Secret
  51. Quiz: Intro to Color
  52. Colors
  53. Matching Color
  54. An Interesting Project Ellora Worked On
  55. Ellora's Advice to You
  56. Conclusion

Quiz: Accessor or Mutator? 2

Run this code in the BlueJ code pad:

Rectangle box = new Rectangle(5, 10, 60, 90);
System.out.println(box.getX());
System.out.println(box.getWidth());
box.translate(25, 40);
System.out.println(box.getX());
System.out.println(box.getWidth());
What are the first two lines of the printout? (Just put the numbers next to each other, separated by a space, even though they will appear in separate lines.) 5 60 Remember the Rectangle constructor has four parameters: x, y, width, and height.
What are the third and fourth line of the printout? 30 60 The translate method shifts the rectangle by 25 pixels to the right, so now x is 5 + 25 = 30. The width does not change.
What kind of method is translate, accessor or mutator? mutator The translate method has changed the box object, as evidenced by the different result of the getX method.

Problem on this page?

Your name:

Your email address:

Problem description:

To protect against spam robots, please answer this simple math problem:
× =