Computer Bible Games with Java

Table of Contents

 

Course Description………………………………………………………………………….. vii

Course Prerequisites………………………………………………………………… vii

System Requirements………………………………………………………………. viii

Installing and Using the Downloadable Solution Files………………………. viii

Installing Beginning Java…………………………………………………………… viii

How To Take the Course…………………………………………………………… viii

Forward by Alan Payne, A Computer Science Teacher……………………… ix

 

1… Introducing Java

 

……. Preview………………………………………………………………………………… 1-1

……. What is Java?………………………………………………………………………… 1-2

……. Why Learn Java?……………………………………………………………………. 1-5

……. A Brief History of Programming Languages………………………………….. 1-6

……. Let’s Get Started…………………………………………………………………….. 1-8

……. Downloading and Installing Java………………………………………………. 1-10

……. NetBeans – A Java Development Environment……………………………. 1-11

……. Starting NetBeans…………………………………………………………………. 1-12

……. Opening a Java Project………………………………………………………….. 1-15

……. Compiling and Running a Java Project………………………………………. 1-18

……. Stopping NetBeans……………………………………………………………….. 1-19

……. Summary…………………………………………………………………………….. 1-20

 

 

2… Java Program Basics

 

……. Review and Preview………………………………………………………………… 2-1

……. Structure of a Java Program……………………………………………………… 2-2

……. The Welcome Project (Revisited)……………………………………………….. 2-5

……. Some Rules of Java Programming……………………………………………… 2-9

……. Creating Java Projects with NetBeans……………………………………….. 2-11

……. Saving Java Projects with NetBeans…………………………………………. 2-22

……. Compiling and Running a Java Program…………………………………….. 2-23

……. NetBeans and Java Files………………………………………………………… 2-25

        Summary…………………………………………………………………………….. 2-27

 

3… Your First Java Program

 

……. Review and Preview………………………………………………………………… 3-1

……. Creating a Java Program………………………………………………………….. 3-3

……. Java – The First Lesson……………………………………………………………. 3-7

               Variables……………………………………………………………………….. 3-7

               Variable Names………………………………………………………………. 3-8

               Variable Types………………………………………………………………… 3-9

               Declaring Variables………………………………………………………… 3-11

               Assignment Statement…………………………………………………….. 3-13

               Arithmetic Operators……………………………………………………….. 3-15

               String Concatenation………………………………………………………. 3-19

               Comments……………………………………………………………………. 3-20

               Program Output……………………………………………………………… 3-21

        Project – Sub Sandwich Party………………………………………………….. 3-24

               Project Design……………………………………………………………….. 3-24

               Project Development………………………………………………………. 3-25

               Run the Project……………………………………………………………… 3-30

               Other Things to Try…………………………………………………………. 3-31

        Summary…………………………………………………………………………….. 3-32

 

 

4… Java Project Design, Input Methods

 

……. Review and Preview………………………………………………………………… 4-1

……. Project Design……………………………………………………………………….. 4-2

……. Java – The Second Lesson………………………………………………………. 4-4

               Variable Initialization…………………………………………………………. 4-4

               Mathematical Functions…………………………………………………….. 4-6

        Program Input Methods………………………………………………………….. 4-10

               Input Methods Example…………………………………………………… 4-13

        Project – Savings Calculator……………………………………………………. 4-21

               Project Design……………………………………………………………….. 4-21

               Project Development………………………………………………………. 4-22

               Run the Project……………………………………………………………… 4-25

               Other Things to Try…………………………………………………………. 4-27

        Summary…………………………………………………………………………….. 4-28

 

 

5… Debugging, Decisions, Random Numbers

 

……. Review and Preview………………………………………………………………… 5-1

……. Debugging a Java Project………………………………………………………… 5-2

               Syntax Errors………………………………………………………………….. 5-3

               Run-Time Errors………………………………………………………………. 5-7

               Logic Errors……………………………………………………………………. 5-9

……. Java – The Third Lesson………………………………………………………… 5-10

               Logical Expressions………………………………………………………… 5-10

               Comparison Operators…………………………………………………….. 5-11

               Comparing Strings………………………………………………………….. 5-14

               Logical Operators…………………………………………………………… 5-15

               Decisions – The if Statement…………………………………………….. 5-20

               Random Number Generator……………………………………………… 5-26

        Project – Guess the Number Game…………………………………………… 5-30

               Project Design……………………………………………………………….. 5-31

               Project Development………………………………………………………. 5-32

               Run the Project……………………………………………………………… 5-36

               Other Things to Try…………………………………………………………. 5-38

        Summary…………………………………………………………………………….. 5-40

 

 

6… Java Looping, Methods

 

……. Review and Preview………………………………………………………………… 6-1

……. Java – The Fourth Lesson………………………………………………………… 6-2

               Java Loops…………………………………………………………………….. 6-2

        A Brief Interlude – Guess the Number Game (Revisited)…………………. 6-8

……. Java – The Fourth Lesson (Continued)………………………………………. 6-11

               Java Methods………………………………………………………………… 6-11

        Project – Lemonade Stand……………………………………………………… 6-17

               Project Design……………………………………………………………….. 6-18

               Project Development………………………………………………………. 6-19

               Run the Project……………………………………………………………… 6-27

               Other Things to Try…………………………………………………………. 6-30

        Summary…………………………………………………………………………….. 6-31

 

 

 

7… Arrays, More Java Looping

 

……. Review and Preview………………………………………………………………… 7-1

……. Java – The Fifth Lesson…………………………………………………………… 7-2

               Variable Arrays……………………………………………………………….. 7-2

               Java for Loops………………………………………………………………… 7-5

        “Shuffle” Method…………………………………………………………………… 7-11

        Project – Card Wars………………………………………………………………. 7-19

               Project Design……………………………………………………………….. 7-19

               Project Development………………………………………………………. 7-20

               Run the Project……………………………………………………………… 7-30

               Other Things to Try…………………………………………………………. 7-31

        Summary…………………………………………………………………………….. 7-32

 

 

8… Java Graphics, Mouse Methods

 

……. Review and Preview………………………………………………………………… 8-1

……. Graphic User Interfaces (GUI)…………………………………………………… 8-2

……. Java Graphics……………………………………………………………………….. 8-7

               Frames………………………………………………………………………….. 8-7

               Event Methods………………………………………………………………. 8-10

……. Java – The Sixth Lesson………………………………………………………… 8-12

               Mouse Events……………………………………………………………….. 8-12

               mousePressed Event………………………………………………………. 8-12

               mouseDragged Event……………………………………………………… 8-16

               Class Level Scope Variables…………………………………………….. 8-19

        More Java Graphics………………………………………………………………. 8-21

               Graphics Coordinates……………………………………………………… 8-21

               Colors………………………………………………………………………….. 8-23

               drawLine Method……………………………………………………………. 8-26

               drawRect Method…………………………………………………………… 8-32

               fillRect Method………………………………………………………………. 8-35

        Project – Blackboard Fun……………………………………………………….. 8-39

               Project Design……………………………………………………………….. 8-39

               Project Development………………………………………………………. 8-40

               Run the Project……………………………………………………………… 8-52

               Other Things to Try…………………………………………………………. 8-54

        Summary…………………………………………………………………………….. 8-57

 

  1. Timers, Animation, Keyboard Methods

 

……. Review and Preview………………………………………………………………… 9-1

……. Timer Class…………………………………………………………………………… 9-2

……. Java – The Final Lesson………………………………………………………… 9-14

               drawstring Method………………………………………………………….. 9-14

               Animation……………………………………………………………………… 9-17

               Object Disappearance…………………………………………………….. 9-23

               Border Crossing…………………………………………………………….. 9-26

               Object Erasure………………………………………………………………. 9-31

               Collision Detection………………………………………………………….. 9-32

               Keyboard Methods…………………………………………………………. 9-37

               keyPressed Event………………………………………………………….. 9-38

        Project – Balloons…………………………………………………………………. 9-42

               Project Design……………………………………………………………….. 9-42

               Project Development………………………………………………………. 9-43

               Run the Project……………………………………………………………… 9-63

               Other Things to Try…………………………………………………………. 9-64

        Summary…………………………………………………………………………….. 9-66

 

 

 

  1. More Topics, More Projects

 

……. Preview………………………………………………………………………………. 10-1

        New Topic – Timing………………………………………………………………. 10-2

        Project 1 – Computer Stopwatch………………………………………………. 10-3

        Project 2 – Dice Rolling………………………………………………………….. 10-7

        New Topic – Switch Structure………………………………………………….. 10-8

        Project 3 – State Capitals……………………………………………………… 10-17

        Project 4 – Units Conversion………………………………………………….. 10-27

        Project 5 – Times Tables………………………………………………………. 10-32

        Project 6 – Loan Calculator……………………………………………………. 10-36

        Project 7 – Checkbook Balancer…………………………………………….. 10-40

        New Topic – Dates………………………………………………………………. 10-46

        Project 8 – Portfolio Manager…………………………………………………. 10-49

        Project 9 – Frown………………………………………………………………… 10-54

        Project 10 – Tic-Tac-Toe………………………………………………………. 10-65

        Project 11 – Memory Game…………………………………………………… 10-71

        Project 12 – Decode…………………………………………………………….. 10-88

        Bonus – Pong!……………………………………………………………………. 10-96

 

 

Bonus:  Classic Computer Games Enhanced with Java

 

Preview  ………………………………………………………………………………. C-1

Even Wins  ………………………………………………………………………….. C-2

Mugwump  …………………………………………………………………………… C-4

Lunar Lander  ………………………………………………………………………. C-6

 

 

Appendix Installing Java & NetBeans for Windows or MAC