The “Simple Dot Com Game”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.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.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.LIS4930 © PIC
A High-Level Design	See you textbooks on page 97.LIS4930 © PIC
The Three Things!LIS4930 © PICPREP CODETEST CODEREAL CODEPrep code: A form of pseudocode, to help you focus on the logic without stressing about syntax.Test code: A class or methods that will test the real code and validate that it’s doing that right thing.Real code: The actual implementation of the class. This is where you put the real Java code.
Prep CodeMost prepcode includes three parts: Instance variable declarationsMethod declarationsMethod logicLIS4930 © PICPREP CODESimpleDotComint[] locationCellsintnumOfHitsString checkYourself(String guess)void setLocationCells(int[] loc)Let’s give it a try!
Test CodeLIS4930 © PICTEST CODEThe 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.Based on our prep code what should we test?
Test Code for the SimpleDotCom ClassLIS4930 © PICTEST CODE
The checkYourself() MethodLIS4930 © PICREAL CODE
Final code for SimpleDotCom and SimpleDotComTestDriveLIS4930 © PIC
Let’s Finish Our SimpleDotComGame ClassLIS4930 © PICCheck out the prep code on page 108.Check out the main() method on page 110.Let’s Play!
More about for loops!LIS4930 © PICfor (inti = 0; i < 100; i++) {  }Part One: initializationPart Two: boolean testPart Three: iteration expressionTake a trip through a for() loop on page 115.
Difference Between While and ForLIS4930 © PICThe 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.But, if you knowhow many times to loop a forloop is cleaner.Let’s compare the two types of loops.
The Enhanced For Loop!LIS4930 © PICfor (String name : nameArray) {  }Part One: initialization variable declarationPart Two: the actual collectionLet’s look at an example!
Casting PrimitivesLIS4930 © PICI have already gone over this concept in class, but read page 117 in your textbook for a more in-depth explanation. longbytecan be cast to

06b extra methods

  • 1.
    The “Simple DotCom Game”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.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.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.LIS4930 © PIC
  • 2.
    A High-Level Design Seeyou textbooks on page 97.LIS4930 © PIC
  • 3.
    The Three Things!LIS4930© PICPREP CODETEST CODEREAL CODEPrep code: A form of pseudocode, to help you focus on the logic without stressing about syntax.Test code: A class or methods that will test the real code and validate that it’s doing that right thing.Real code: The actual implementation of the class. This is where you put the real Java code.
  • 4.
    Prep CodeMost prepcodeincludes three parts: Instance variable declarationsMethod declarationsMethod logicLIS4930 © PICPREP CODESimpleDotComint[] locationCellsintnumOfHitsString checkYourself(String guess)void setLocationCells(int[] loc)Let’s give it a try!
  • 5.
    Test CodeLIS4930 ©PICTEST CODEThe 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.Based on our prep code what should we test?
  • 6.
    Test Code forthe SimpleDotCom ClassLIS4930 © PICTEST CODE
  • 7.
  • 8.
    Final code forSimpleDotCom and SimpleDotComTestDriveLIS4930 © PIC
  • 9.
    Let’s Finish OurSimpleDotComGame ClassLIS4930 © PICCheck out the prep code on page 108.Check out the main() method on page 110.Let’s Play!
  • 10.
    More about forloops!LIS4930 © PICfor (inti = 0; i < 100; i++) { }Part One: initializationPart Two: boolean testPart Three: iteration expressionTake a trip through a for() loop on page 115.
  • 11.
    Difference Between Whileand ForLIS4930 © PICThe 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.But, if you knowhow many times to loop a forloop is cleaner.Let’s compare the two types of loops.
  • 12.
    The Enhanced ForLoop!LIS4930 © PICfor (String name : nameArray) { }Part One: initialization variable declarationPart Two: the actual collectionLet’s look at an example!
  • 13.
    Casting PrimitivesLIS4930 ©PICI have already gone over this concept in class, but read page 117 in your textbook for a more in-depth explanation. longbytecan be cast to