Skip to Content
Head First Java, 3rd Edition
book

Head First Java, 3rd Edition

by Kathy Sierra, Bert Bates, Trisha Gee
May 2022
Beginner
754 pages
21h 51m
English
O'Reilly Media, Inc.
Book available
Content preview from Head First Java, 3rd Edition

Chapter 5. Extra-Strength Methods: Writing A Program

image

Let’s put some muscle in our methods. We dabbled with variables, played with a few objects, and wrote a little code. But we were weak. We need more tools. Like operators. We need more operators so we can do something a little more interesting than, say, bark. And loops. We need loops, but what’s with the wimpy while loops? We need for loops if we’re really serious. Might be useful to generate random numbers. Better learn that too. And why don’t we learn it all by building something real, to see what it’s like to write (and test) a program from scratch. Maybe a game, like Battleships. That’s a heavy-lifting task, so it’ll take two chapters to finish. We’ll build a simple version in this chapter and then build a more powerful deluxe version in Chapter 6, Using the Java Library.

Let’s build a Battleship-style game: “Sink a Startup”

It’s you against the computer, but unlike the real Battleship game, in this one you don’t place any ships of your own. Instead, your job is to sink the computer’s ships in the fewest number of guesses.

Oh, and we aren’t sinking ships. We’re killing ill-advised, Silicon Valley Startups (thus establishing business relevancy so you can expense the cost of this book).

Goal: Sink all of the computer’s Startups in the fewest number of guesses. You’re given a rating or level, based on how well you perform. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Head First Java, 2nd Edition

Head First Java, 2nd Edition

Kathy Sierra, Bert Bates
Learning Java, 6th Edition

Learning Java, 6th Edition

Marc Loy, Patrick Niemeyer, Daniel Leuck
Java in a Nutshell, 7th Edition

Java in a Nutshell, 7th Edition

Benjamin J. Evans, David Flanagan

Publisher Resources

ISBN: 9781492091646Errata Page