Cooking

Submitted by: Submitted by

Views: 198

Words: 1330

Pages: 6

Category: Other Topics

Date Submitted: 10/31/2012 11:07 AM

Report This Essay

Extra-Strength Methods

Let’s put some muscle in our methods.

6 Using the Java Library

Java ships with hundreds of pre-built classes.

We’re gonna build the

Sink a Dot Com game

- Julia, 31, hand model

Building the Sink a Dot Com game 96

Starting with the Simple Dot Com game (a simpler version) 98

Writing prepcode (pseudocode for the game) 100

Test code for Simple Dot Com 102

Coding the Simple Dot Com game 103

Final code for Simple Dot Com 106

Generating random numbers with Math.random() 111

Ready-bake code for getting user input from the command-line 112

Looping with for loops 114

Casting primitives from a large size to a smaller size 117

Converting a String to an int with Integer.parseInt() 117

Exercises and puzzles 118

Analying the bug in the Simple Dot Com Game 126

ArrayList (taking advantage of the Java API) 132

Fixing the DotCom class code 138

Building the real game (Sink a Dot Com) 140

Prepcode for the real game 144

Code for the real game 146

boolean expressions 151

Using the library (Java API) 154

Using packages (import statements, fully-qualifi ed names) 155

Using the HTML API docs and reference books 158

Exercises and puzzles 161

xiii

Some classes just should not be instantiated 200

Abstract classes (can’t be instantiated) 201

Abstract methods (must be implemented) 203

Polymorphism in action 206

Class Object (the ultimate superclass of everything) 208

Taking objects out of an ArrayList (they come out as type Object) 211

Compiler checks the reference type (before letting you call a method) 213

Get in touch with your inner object 214

Polymorphic references 215

Casting an object reference (moving lower on the inheritance tree) 216

Deadly Diamond of Death (multiple inheritance problem) 223

Using interfaces (the best solution!) 224

Exercises and puzzles 230

7 Better Living in Objectville

Plan your programs with the future in mind.

8 Serious...