Kristofer Younger 3c741d9c85 Update 'README.md' 4 years ago
.gitignore Initial commit 4 years ago
README.md Update 'README.md' 4 years ago

README.md

ZCW-Lab-BlueJPic1

Exercise 1.13

In the source code of class Picture, find the part that actually draws the picture. Change it so that the sun will be blue rather than yellow.

Exercise 1.14

Add a second sun to the picture. To do this, pay attention to the field definitions close to the top of the class. You will find this code: private Square wall; private Square window; private Triangle roof; private Circle sun; You need to add a line here for the second sun. For example: private Circle sun2; Then write the appropriate code for creating the second sun.

Exercise 1.15 Challenge exercise

(This means that this exercise might not be solved quickly. We do not expect everyone to be able to solve this at the moment. If you do – great. If you don’t, then don’t worry. Things will become clearer as you read on. Come back to this exercise later.)

Add a sunset to the single-sun version of Picture. That is: make the sun go down slowly. Remember: The circle has a method slowMoveVertical that you can use to do this.

Exercise 1.16 Challenge exercise

If you added your sunset to the end of the draw method (so that the sun goes down automatically when the picture is drawn), change this now. We now want the sunset in a separate method, so that we can call draw and see the picture with the sun up, and then call sunset (a separate method!) to make the sun go down.

Exercise 1.17

Create an object of class Student. You will notice that this time you are prompted not only for a name of the instance, but also for some other parameters. Fill them in before clicking Ok. (Remember that parameters of type String must be written in double quotes.)

Exercise 1.18

Create some student objects. Call the getName method on each object. Explain what is happening.

Exercise 1.19

Create an object of class LabClass. As the signature indicates, you need to specify the maximum number of students in that class (an integer).

Exercise 1.20

Call the numberOfStudents method of that class. What does it do?

Exercise1.21

Look at the signature of the enrollStudent method. You will notice that the type of the expected parameter is Student. Make sure you have two or three students and a LabClass object on the object bench, then call the enrollStudent method of the LabClass object. With the input cursor in the dialog entry field, click on one of the student objects – this enters the name of the student object into the par- ameter field of the enrollStudent method (Figure 1.8). Click Ok, and you have added the student to the LabClass. Add one or more other students as well.

Exercise 1.22

Call the printList method of the LabClass object. You will see a list of all the students in that class printed to the BlueJ terminal window (Figure 1.9).

Exercise 1.23

Create three students with the following details:

  • Snow White, student ID: 100234, credits: 24
  • Lisa Simpson, student ID: 122044, credits: 56
  • Charlie Brown, student ID: 12003P, credits: 6

Then enter all three into a lab and print a list to the screen.

Exercise 1.24

Use the inspector on a LabClass object to discover what fields it has.

Exercise 1.25

Set the instructor, room, and time for a lab, and print the list to the terminal window to check that these new details appear.

Exercise 1.26

In this chapter we have mentioned the data types int and String. Java has more predefined data types. Find out what they are and what they are used for. To do this, you can check Appendix B, or look it up in another Java book or in an online Java language manual. One such manual is at http://java.sun.com/docs/books/tutorial/java/nutsandbolts/datatypes.html

Exercise 1.27

What are the types of the following values?

  • 0
  • "hello"
  • 101
  • –1
  • true
  • "33"
  • 3.1415
Exercise 1.28

What would you have to do to add a new field, for example one called name, to a circle object?

Exercise1.29

Write the signature for a method named send that has one parameter of type String, and does not return a value.

Exercise 1.30

Write the signature for a method named average that has two parameters, both of type int, and returns an int value.

Exercise 1.31

Look at the book you are reading right now. Is it an object or a class? If it is a class, name some objects. If it is an object, name its class.

Exercise 1.32

Can an object have several different classes? Discuss.