Your SlideShare is downloading. ×
0
The “Simple Dot Com Game”<br />Goal: Sink all of the computer’s Dot Coms in the fewest number of guesses. You’re given a t...
A High-Level Design	<br />See you textbooks on page 97.<br />LIS4930 © PIC<br />
The Three Things!<br />LIS4930 © PIC<br />PREP CODE<br />TEST CODE<br />REAL CODE<br />Prep code: A form of pseudocode, to...
Prep Code<br />Most prepcode includes three parts: <br />Instance variable declarations<br />Method declarations<br />Meth...
Test Code<br />LIS4930 © PIC<br />TEST CODE<br />The concept of writing the test code first is one of the practices of Ext...
Test Code for the SimpleDotCom Class<br />LIS4930 © PIC<br />TEST CODE<br />
The checkYourself() Method<br />LIS4930 © PIC<br />REAL CODE<br />
Final code for SimpleDotCom and SimpleDotComTestDrive<br />LIS4930 © PIC<br />
Let’s Finish Our SimpleDotComGame Class<br />LIS4930 © PIC<br />Check out the prep code on page 108.<br />Check out the ma...
More about for loops!<br />LIS4930 © PIC<br />for (inti = 0; i < 100; i++) {  }<br />Part One: initialization<br />Part Tw...
Difference Between While and For<br />LIS4930 © PIC<br />The whileloop has only the Boolean test; it doesn’t have a built-...
The Enhanced For Loop!<br />LIS4930 © PIC<br />for (String name : nameArray) {  }<br />Part One: initialization variable d...
Casting Primitives<br />LIS4930 © PIC<br />I have already gone over this concept in class, but read page 117 in your textb...
Upcoming SlideShare
Loading in...5
×

06b extra methods

483

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
483
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "06b extra methods"

  1. 1. The “Simple Dot Com Game”<br />Goal: Sink all of the computer’s Dot Coms in the fewest number of guesses. You’re given a taring of level, based on how well you perform.<br />Setup: When the game program is launched, the computer places three Dot Coms on a virtual 7x7 grid. When that’s complete, the game asks for your first guess.<br />How you play: The computer will prompt the user to enter a guess. In response to the guess you’ll see a response at the command line: “Hit”, “Miss”, or “You sunk Pets.com” (or whatever the name of the company was). When all companies are sunk the game ends by reporting your rating.<br />LIS4930 © PIC<br />
  2. 2. A High-Level Design <br />See you textbooks on page 97.<br />LIS4930 © PIC<br />
  3. 3. The Three Things!<br />LIS4930 © PIC<br />PREP CODE<br />TEST CODE<br />REAL CODE<br />Prep code: A form of pseudocode, to help you focus on the logic without stressing about syntax.<br />Test code: A class or methods that will test the real code and validate that it’s doing that right thing.<br />Real code: The actual implementation of the class. This is where you put the real Java code.<br />
  4. 4. Prep Code<br />Most prepcode includes three parts: <br />Instance variable declarations<br />Method declarations<br />Method logic<br />LIS4930 © PIC<br />PREP CODE<br />SimpleDotCom<br />int[] locationCells<br />intnumOfHits<br />String checkYourself(String guess)<br />void setLocationCells(int[] loc)<br />Let’s give it a try!<br />
  5. 5. Test Code<br />LIS4930 © PIC<br />TEST CODE<br />The concept of writing the test code first is one of the practices of Extreme Programming (XP), and it can make it easier (and faster) for you to write your code.<br />Based on our prep code what should we test?<br />
  6. 6. Test Code for the SimpleDotCom Class<br />LIS4930 © PIC<br />TEST CODE<br />
  7. 7. The checkYourself() Method<br />LIS4930 © PIC<br />REAL CODE<br />
  8. 8. Final code for SimpleDotCom and SimpleDotComTestDrive<br />LIS4930 © PIC<br />
  9. 9. Let’s Finish Our SimpleDotComGame Class<br />LIS4930 © PIC<br />Check out the prep code on page 108.<br />Check out the main() method on page 110.<br />Let’s Play!<br />
  10. 10. More about for loops!<br />LIS4930 © PIC<br />for (inti = 0; i < 100; i++) { }<br />Part One: initialization<br />Part Two: boolean test<br />Part Three: iteration expression<br />Take a trip through a for() loop on page 115.<br />
  11. 11. Difference Between While and For<br />LIS4930 © PIC<br />The whileloop has only the Boolean test; it doesn’t have a built-in initialization or iteration expression.A whileloop is good when you don’t know how many times to loop and just want to keep going while some condition is true.<br />But, if you knowhow many times to loop a forloop is cleaner.<br />Let’s compare the two types of loops.<br />
  12. 12. The Enhanced For Loop!<br />LIS4930 © PIC<br />for (String name : nameArray) { }<br />Part One: initialization variable declaration<br />Part Two: the actual collection<br />Let’s look at an example!<br />
  13. 13. Casting Primitives<br />LIS4930 © PIC<br />I have already gone over this concept in class, but read page 117 in your textbook for a more in-depth explanation. <br />long<br />byte<br />can be cast to<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×