Appendix . Chapter Quiz Answers

Here are the answers to the quizzes at the end of each chapter.

Chapter 1

1.

What does the acronym “JDK” stand for?

Answer:

Java Development Kit

2.

What version of the JDK are we focusing on in this book?

Answer:

6 or Java 6 or Java SE 6

3.

What is the name of the company that created Java?

Answer:

Sun Microsystems

4.

Where on the web will you find the text editor called TextPad?

Answer:

www.textpad.com

5.

In what year was Java first released?

Answer:

1995

6.

Where on the web is the primary download site for Java?

Answer:

http://java.sun.com

7.

What type of Java program do you run with the java.exe tool?

Answer:

application

8.

What type of Java program runs in a web browser?

Answer:

applet

9.

What is the name of the command-line tool used to run a web-based Java program?

Answer:

appletviewer.exe

10.

What is the name of the parameter passed to the paint() event method in an applet?

Answer:

Graphics g

Chapter 2

1.

What is the name of the JDK tool used to compile Java programs?

Answer:

javac.exe

2.

Which JDK command-line tool is used to run a Java application?

Answer:

java.exe

3.

Which JDK command-line tool is used to run a Java applet?

Answer:

appletviewer.exe

4.

What are two good, free Java IDEs recommended in this chapter?

Answer:

Eclipse, NetBeans, or TextPad

5.

Encapsulation, polymorphism, and inheritance are the keys to what programming methodology?

Answer:

OOP: Object-Oriented Programming

6.

What’s the main difference between a Java application and an applet?

Answer:

applets run in a Web browser

7.

Which method of the Graphics class can you use to print a text message on the screen?

Answer:

drawString()

8.

How many bits make up a Java integer (the int data type)?

Answer:

32

9.

How many bits are there in a Java long integer (the long data type)?

Answer:

64

10.

What programming language was Java based on?

Answer:

C++

Chapter 3

1.

What is the name of the method that calculates the velocity for X?

Answer:

calcAngleMoveX()

2.

What is the base class from which Ship, Asteroid, and Bullet are inherited?

Answer:

BaseVectorShape

3.

Which classic Atari game inspired the game developed in this chapter?

Answer:

Asteroids

4.

Which type of collision testing does this game use?

Answer:

Bounding Rectangle

5.

Which method of the Shape class does this game use for collision testing?

Answer:

contains()

6.

Which geometric shape class do the Ship and Asteroid classes use?

Answer:

Polygon

7.

Which geometric shape class does the Bullet class use?

Answer:

Rectangle (pixel also acceptable)

8.

Which applet event actually draws the screen?

Answer:

paint()

9.

What is the name of the interface class used to add threading support to the game?

Answer: Runnable

10.

What math function does calcAngleMoveX use to calculate the X velocity?

Answer:

Math.cos()

Chapter 4

1.

What is the primary class we’ve been using to manipulate vector graphics in this chapter?

Answer:

Graphics2D

2.

What is the name of the Applet event that refreshes the screen?

Answer:

paint() or update()

3.

What is the name of the Graphics2D method that draws a filled rectangle?

Answer:

fillRect()

4.

Define the words comprising the acronym “AWT.”

Answer:

Abstract Window Toolkit

5.

What class makes it possible to perform translation, rotation, and scaling of shapes?

Answer:

AffineTransform

6.

Which Graphics2D method draws a polygon?

Answer:

draw()

7.

Which transform method moves a shape to a new location?

Answer:

translate()

8.

What method initializes the keyboard listener interface?

Answer:

addKeyListener()

9.

What method in the Random class returns a double-precision floatingpoint value?

Answer:

nextDouble()

10.

Which KeyListener event detects key presses?

Answer:

keyPressed()

Chapter 5

1.

What is the primary class we’ve been using to manipulate bitmapped graphics in this chapter?

Answer:

Graphics2D

2.

What method initializes the keyboard listener interface?

Answer:

addKeyListener()

3.

What Graphics2D method is used to draw an image?

Answer:

drawImage()

4.

Which Java class contains the getImage() method?

Answer:

Applet

5.

What class makes it possible to perform translation, rotation, and scaling of images?

Answer:

AffineTransform

6.

Which Graphics2D method draws an image?

Answer:

drawImage()

7.

Which transform method moves an image to a new location?

Answer:

translate()

8.

What is the name of the “transparency” channel in a 32-bit PNG image?

Answer:

alpha channel

9.

What is the Applet class method used to load a resource from a JAR?

Answer:

getResource()

10.

Which KeyListener event detects key presses?

Answer:

keyPressed()

Chapter 6

1.

What is the name of the support class created in this chapter to help the Sprite class manage position and velocity?

Answer:

Point2D

2.

During which keyboard event should you disable a keypress variable, when detecting multiple key presses with global variables?

Answer:

keyReleased()

3.

What are the three types of parameters can you pass to the collidesWith() method?

Answer:

Rectangle, Sprite, and Point2D

4.

What Java class provides an alternate method for loading images that is not tied to the applet?

Answer:

Toolkit

5.

Which Java package do you need to import to use the Graphics2D class?

Answer:

java.awt.Graphics2D

6.

What numeric data type does the Point2D class (created in this chapter) use for internal storage of the X and Y values?

Answer:

double

7.

What data types can the Point2D class work with at the constructor level?

Answer:

int, float, and double

8.

Which sprite property determines the angle at which the sprite will move?

Answer:

moveAngle

9.

Which sprite property determines at which angle an image is pointed, regardless of movement direction?

Answer:

faceAngle

10.

Which AffineTransform methods allow you to translate, rotate, and scale a sprite?

Answer:

translate(), rotate(), and scale()

Chapter 7

1.

What is the name of the animation class created in this chapter?

Answer:

AnimatedSprite

2.

From which class does the new animation class inherit?

Answer:

Sprite

3.

How many frames of animation were there in the animated ball sprite?

Answer:

64

4.

What do you call an animation that is stored inside many files?

Answer:

sequence

5.

What do you call an animation that is all stored in a single file?

Answer:

tiled

6.

What type of parameter does the AnimatedSprite.setVelocity method accept?

Answer:

Point2D

7.

What arithmetic operation is used to calculate an animation frame’s Y position?

Answer:

division

8.

What arithmetic operation is used to calculate an animation frame’s X position?

Answer:

modulus

9.

What is a good class to use when you need to create a bitmap in memory?

Answer:

BufferedImage

10.

Which AnimatedSprite method draws the current frame of animation?

Answer:

draw()

Chapter 8

1.

What is the name of the method used to enable keyboard events in your program?

Answer:

addKeyListener()

2.

What is the name of the keyboard event interface?

Answer:

KeyListener

3.

What is the virtual key code for the Enter key?

Answer:

VK_ENTER

4.

Which keyboard event will tell you the code of a pressed key?

Answer:

Technically, any of the three ( keyPressed(), keyReleased(), and keyTyped() )

5.

Which keyboard event will tell you when a key has been released?

Answer:

keyPressed() or keyTyped()

6.

Which keyboard event will tell you the character of a pressed key?

Answer:

Technically, any of the three ( keyPressed(), keyReleased(), and keyTyped() )

7.

Which KeyEvent method returns a key code value?

Answer:

getKeyCode()

8.

What is the name of the method used to enable mouse motion events?

Answer:

addMouseMotionListener()

9.

What is the name of the class used as a parameter for all mouse event methods?

Answer:

MouseEvent

10.

Which mouse event reports the actual movement of the mouse?

Answer:

mouseDragged() or mouseMoved()

Chapter 9

1.

What is the name of Java’s digital sound system class?

Answer:

AudioSystem

2.

What is the name of Java’s MIDI music system class?

Answer:

MidiSystem (Sequencer also acceptable)

3.

Which Java class handles the loading of a sample file?

Answer:

AudioInputStream (AudioSystem also acceptable)

4.

Which Java class handles the loading of a MIDI file?

Answer:

Sequence (MidiSystem also acceptable)

5.

What type of exception error will Java generate when it cannot load a sound file?

Answer:

UnsupportedAudioFileException (LineUnavailableException and IOException are also technically acceptable)

6.

Which method of the MIDI system returns the sequencer object?

Answer:

MidiSystem.getSequencer()

7.

What is the main Java class hierarchy for the audio system class?

Answer:

javax.sound.sampled

8.

What is the main Java class hierarchy for the MIDI system class?

Answer:

javax.sound.midi

9.

What three digital sound file formats does Java support?

Answer:

AIFF, AU, and WAV

10.

What rare exception error will occur when no MIDI sequencer is available?

Answer:

MidiUnavailableException

Chapter 10

1.

What is the name of the interface class that provides thread support?

Answer:

Runnable

2.

What is the name of the thread execution method that you can use to run code inside the separate thread?

Answer:

run()

3.

What is the name of the class that handles vector-based graphics?

Answer:

Shape

4.

What Thread method causes the thread to pause execution for a specified time?

Answer:

sleep()

5.

What System method returns the current time in milliseconds?

Answer:

currentTimeMillis()

6.

What is the name of the method that returns the directory containing the applet (or HTML container) file?

Answer:

getCodeBase()

7.

What is the name of the method that returns the entire URL string including the applet (or HTML container) file?

Answer:

getDocumentBase()

8.

What class do you use to store a bitmap image?

Answer:

Image or BufferedImage

9.

Which Graphics2D method is used to draw a bitmap?

Answer:

drawImage()

10.

Which class helps to improve gameplay by providing random numbers?

Answer:

Random

Chapter 11

1.

What is the name of the class that handles bitmaps?

Answer:

Image or BufferedImage

2.

Which class in Galactic War detects when bullets hit the asteroids?

Answer:

Rectangle or Bullet

3.

What is the maximum number of sprites that can be supported by the game?

Answer:

virtually unlimited (based on available memory)

4.

Which method in the Graphics2D class actually draws the image of a sprite?

Answer:

drawImage()

5.

What is the name of the Applet method that redraws the window?

Answer:

paint()

6.

How many key presses can the game detect at a single time?

Answer:

virtually unlimited (limited only by the operating system)

7.

What method do you use to track the mouse’s movement?

Answer:

mouseMoved() or mouseDragged()

8.

What type of graphics entity does the game use for the asteroids?

Answer:

Shape

9.

Regarding ship rotation, by how many angles can the ship be rotated?

Answer:

360

10.

What method provides the game with support for collision detection?

Answer:

Rectangle.contains()

Chapter 12

1.

Which support class helps manage the position and velocity of sprites?

Answer:

Point2D

2.

During which keyboard event should you disable a keypress variable, when detecting multiple key presses with global variables?

Answer:

keyReleased

3.

What is the name of the sprite collision detection routine used in Galactic War?

Answer:

Rectangle.contains()

4.

Which method in the Applet class provides a way to load images from a

JAR file?

Answer:

getResource()

5.

Which Java package do you need to import to use the Graphics2D class?

Answer:

java.awt.Graphics2D

6.

What numeric data type does the Point2D class (created in this chapter) use for internal storage of the X and Y values?

Answer:

double

7.

How does the use of a class such as Point2D improve a game’s source code, versus using simple variables?

Answer:

A single parameter handles two variables (x and y)

8.

Which property in the Sprite class determines the angle at which the sprite will move?

Answer:

moveAngle

9.

Which property in the Sprite class determines the angle at which a sprite is pointed?

Answer:

faceAngle

10.

How many milliseconds must the game use as a delay in order to achieve a frame rate of 60 frames per second?

Answer:

1000/60 = 16.67 ms

Chapter 13

1.

What is the name of the method that makes collision detection possible?

Answer:

Rectangle.contains()

2.

How many collisions can the game detect within a single update of the game loop?

Answer:

the square of the number of sprites

3.

What would happen if the ship were to fire a projectile that “warps” around the screen and then hits the ship? Would a collision take place? Why or why not?

Answer:

No collision is handled between the ship and bullets

4.

What should happen to the player’s ship after it has been destroyed by a collision with an asteroid? Describe a better way to “respawn” the ship than what is currently being done.

Answer:

It should be destroyed and respawned. A better way might be to give the player some “invulnerable” time after respawn to improve game-play.

5.

What type of transform could you apply to the explosion sprite to change its size?

Answer:

scaling

6.

How does the ship’s velocity affect the result of a collision when the ship is destroyed? Should the ship continue to exert momentum even while blowing up?

Answer:

The ship currently stops when it explodes. A more realistic explosion would continue to move a little ways along the ship’s trajectory.

7.

How can the collision routine be improved upon, so that collisions are more precise?

Answer:

Either smaller bounding boxes can be used or every pixel of two sprites can be compared (which is usually overkill)

8.

What is the name of the constant applied to the ship when a collision has taken place?

Answer:

STATE_EXPLODING

9.

What is the name of the method that updates a sprite’s animation sequence?

Answer:

updateAnimation()

10.

What is the name of the method that handles the game loop for Galactic War?

Answer:

gameUpdate()

Chapter 14

1.

What is the name of the new game engine class developed in this chapter?

Answer:

Game

2.

How many sprites can the new engine handle on the screen simultaneously?

Answer:

unlimited (with available memory)

3.

Which of the four key classes in the game engine handles image loading?

Answer:

ImageEntity

4.

How many different asteroid sizes does the game use?

Answer:

4

5.

True or False: Collisions are handled inside the game engine.

Answer:

False (collisions are only detected, not handled)

6.

What type of object is animImage, a private variable in AnimatedSprite?

Answer:

ImageEntity

7.

Which class is responsible for rendering a single frame of an animation in AnimatedSprite?

Answer:

Sprite (which, in turn, uses ImageEntity)

8.

What is the maximum velocity value for the player’s spaceship?

Answer:

10

9.

What class does the game/sprite engine pass in some of its events?

Answer:

AnimatedSprite

10.

What is the name of the support method in AnimatedSprite that returns a properly formed URL for a file to be loaded?

Answer:

getURL

Chapter 15

1.

What method in GalacticWar.java makes it possible to add powerups to the game when a tiny asteroid is destroyed?

Answer:

spawnPowerup()

2.

What construct does the sprite engine (in Game.java) use to manage the sprites?

Answer:

LinkedList

3.

How many weapon upgrades are available now in Galactic War?

Answer:

5

4.

How many different point-value power-ups are there in the game?

Answer:

3

5.

What method in GalacticWar.java returns a stock bullet sprite object, which is then tweaked to produce the upgraded bullet spreads?

Answer:

stockBullet()

6.

How many different asteroid images are there in Galactic War?

Answer:

14

7.

If you wanted to add another weapon upgrade to the game, which method would you need to modify?

Answer:

fireBullet()

8.

How many sprites is the sprite engine capable of handling at a time?

Answer:

unlimited (with available memory)

9.

How many bullets are fired at a time with the fifth-level weapon upgrade?

Answer:

6

10.

What is the name of the static int that represents the game state when the game is running normally?

Answer:

GAME_RUNNING

Chapter 16

1.

What does the acronym JAR stand for?

Answer:

Java Archive

2.

What is the name of the program used to work with JAR files?

Answer:

jar.exe

3.

What types of files can be stored inside a JAR file?

Answer:

Any type of file

4.

What compression method does the JAR format use?

Answer:

ZIP compression

5.

What method must you use in conjunction with the java.net.URL class for loading media files when an applet has been deployed in a JAR file?

Answer:

getResource()

6.

What command would you enter to create a new JAR file, called test.jar, that contains all files in the current folder?

Answer:

jar cf test.jar *.*

7.

What command would you enter to create the same archive but also include a manifest file called manifest.txt?

Answer:

jar cfm test.jar manifest.txt *.*

8.

What command would you enter to list the contents of a file called MyGame.jar with verbose listing enabled?

Answer:

jar tvf MyGame.jar

9.

What JAR parameter option causes files to be added from a different folder without adding the folder name to the files stored in the archive?

Answer:

C

10.

What type of web server do you need to host a Java applet–based game?

Answer:

Any server will do; applets are client-side programs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.54.239