• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 4 fuera de 126 páginas
Examen

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

Document preview thumbnail
Vista previa 4 fuera de 126 páginas

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.

Vista previa del contenido

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

Información del documento

Subido en
22 de octubre de 2024
Número de páginas
126
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$28.49

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
docusity
4.4
(307)
Vendido
1903
Seguidores
137
Artículos
1463
Última venta
1 hora hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes