• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 4 out of 126 pages
Exam (elaborations)

Solutions Manual For Objects First with Java, A Practical Introduction Using BlueJ, 6th Edition, Barnes, Kölling

Document preview thumbnail
Preview 4 out of 126 pages

Solutions For Objects First with Java 6th Edition / Objects First with Java 6e Solutions Manual. Objects First with Java, Sixth Edition Solutions Manual Barnes / Solutions For 9780134477367, David J. Barnes, Michael Kölling.

Content preview

SOLUTIONS MANUAL

Objects First with Java
A Practical Introduction Using BlueJ, 6TH EDITION

Exercise 1.3
Use a negative parameter value to move left, e.g. -70

Exercise 1.9
The House Picture

The main building:

 Create a new Square object
 Invoke its method makeVisible()
 Make the square bigger by invoking the method changeSize(newSize)
(100 is a good size)
 Move the square down by invoking the method moveVertical(distance)
(again 80 is a good value)

The window:

 Create a new Square object.
 Invoke its method makeVisible()
 Change its color by invoking changeColor()
 write "black" in the popupwindow
 Move the square down by invoking the method moveVertical(distance)
(100 is a good value)
 Move it to the right by invoking moveRight()

The roof:

 Create a new triangle object.
 Invoke its method makeVisible()
 Change its size with changeSize(newHeight, newWidth) (50,140)
 moveVertical(70)
 moveHoizontal(60)

The sun:

 Create new Circle object.
 Invoke its method makeVisible()
 Change its color by invoking changeColor() (write "yellow" in the popup
window) Optionally change its size with changeSize(60)
 Move it to the right by invoking moveHorizontal(180)

The Hilltop Picture

The hill:

,  Create a new Circle object.
 Invoke its makeVisible() method.
 Change its color by invoking changeColor (write “green” in the popup
window) Change its size with changeSize to something like 1000.
 Move it left with moveHorizontal(-500).
 Move it down with moveVertical(125).

The sun:

 Create a Circle.
 Make it visible.
 Set its size to 30.
 Move it right by 150 pixels.
 Move it down by 50 pixels.

The larger figure:

 Create a new Person object.
 Invoke its makeVisible method.
 Change its size to something like 50 high and 25 wide.
 Move it left by 30 pixels and up by around 8.

The smaller figure:

 The size should be around 40 by 20.
 Move it left by 3 pixels and down by 2.


Exercise 1.14
 It uses the objects of the classes Circle, Square and Triangle.
 It then moves these objects to the right places and changes the sizes and
colors of the objects. Essentially calling the same methods as used in
exercise 1.9


Exercise 1.16
Change:

sun.changeColor("yellow");

to be:

sun.changeColor("blue");

Note that this change should be made in both the draw() and setColor()
methods. Students often forget to do it in the latter. Illustrate the problem by

,drawing the picture, then calling setBlackAndWhite() then setColor() – the sun
will have been changed to yellow, rather than blue, if the second change is not
made.

Exercise 1.17
The second sun will need to be positioned somewhere different from the first
sun to be visible. As with the previous exercise, it is common for students to
miss the need to change the setColor and setBlackAndWhite methods for
compatibility with the addition. This is an earlier introduction to the need for
regression testing!

Exercise 1.18
After the line sun.makeVisible() insert the following:

 sun.slowMoveVertical(250);
 Compile the Picture class (Press compile in the editor window)
 Create instance of class Picture and invoke its draw() method.


Exercise 1.19
Remove the line (if added in the previous exercise): slowMoveVertical(250);
Right below the last } after the draw() method, add the sunset() method :

/**
* Animates the sunset.
*/
public void sunset()
{
sun.slowMoveVertical(250);
}

Compile! And run it.

Exercise 1.20
Define a new field:

private Person person;

Initialize and position them in the draw():

person = new Person();
person.changeSize(80, 40);
// Place them at ground level.
person.moveVertical(15);
// Make sure they are to the right of the house to start.
person.moveHorizontal(200);

, Make them visible and move up to the house in sunset():

person.makeVisible();
// Walk up to the house.
person.slowMoveHorizontal(-150);

Exercise 1.22
When calling the method getName(), the name of the student is displayed in a
popup window. The name displayed is the one typed in when the object was
created.

Exercise 1.24
It shows the number of students in the LabClass which is zero.

Exercise 1.31
Students looking these values up in the tutorial might not be able to readily
identify that the integer types used here are int, as opposed to byte, short or
long. Similarly, they may well suggest float rather than double for the final one.
Be sure to point out that String always has an initial upper-case letter, because
these subtleties are often missed.

0 int
"hello" String
101 int
-1 int
true boolean
"33" String
3.1415 double

Exercise 1.32
First you would have to decide which type the field should have. String would
be a good type to hold a name, so we add the following line to the source file of
Circle:
private String name;

The above line could be placed after this line in the source code of the Circle
class:

private boolean isVisible;

Exercise 1.33

Document information

Uploaded on
October 22, 2024
Number of pages
126
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$28.49

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
docusity
4.4
(292)
Sold
1783
Followers
136
Items
1442
Last sold
22 hours ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions