Skip to content

3.13 Tutorial 2

exercise_guide_2.pdf

Tasks

  1. Consider the project figures. Indicate which are the fields of the classes Square​, Circle​, and Person​, and their corresponding types.

  2. Open BlueJ, and load the figures project. Using the Code Pad, create a circle and a rectangle, and display both on the screen. Call methods slowMoveHorizontal​ and slowMoveVertical​ on these objects from the Code Pad, to get familiar with the syntax of methods and parameter passing.

  3. Load the house project. Modify the method draw​ in class Picture​, so that the sun sets slowly. The sun is represented by a circle, and this class has methods that allow a figure to move slowly; you may use these methods to achieve the required behavior.

  4. Modify the method draw​ in class Picture​ again to achieve a behavior in which the sun moves slowly to the left until it disappears, and appears again on the right, stopping at the same position where it started.u

  5. Do exercises 1.19 and 1.20 from Objects First with Java: A Practical Introduction using BlueJ (Barnes & Kölling).

  6. Load the lab-classes project. Create various objects of class Student​, passing adequate values as parameters to the constructor to represent real students of this course. Take into account that all parameters are of type String​, and string literals are indicated between double quotes.

  7. Describe the fields of class Student​ and their corresponding types.

  8. Enumerate at least two methods of class Student​ whose return type is not void​, and describe in your own words what these methods do.

  9. Create instances of class LabClass​ to represent different labs of this course. Use the method enrollStudent​ to add students to the labs. Analyze the fields and methods in the LabClass​ class to assign a teacher to each lab, a room, and a time, with some realistic values.

  10. Invoke the method printList​ on the LabClass​ instances to obtain the details of each lab.