File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes does 200 mean something? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "does 200 mean something?" Watch "does 200 mean something?" New topic
Author

does 200 mean something?

Lee EunA
Greenhorn

Joined: Apr 29, 2008
Posts: 1
hello
I am a Korean.
I can not speak English...
sorry..
but i have a question ..
chapter 6. GameHelper Source.
=Head First Java=

------------

// Tiger version

import java.io.*;
import java.util.*;

class GameHelper {

private static final String alphabet = "abcdefg";
private int gridLength = 7;
private int gridSize = 49;
private int [] grid = new int[gridSize];
private int comCount = 0;


public String getUserInput(String prompt) {
String inputLine = null;
System.out.print(prompt + " ");
try {
BufferedReader is = new BufferedReader(
new InputStreamReader(System.in));
inputLine = is.readLine();
if (inputLine.length() == 0 ) return null;
} catch (IOException e) {
System.out.println("IOException: " + e);
}
return inputLine.toLowerCase();
}



public ArrayList<String> placeDotCom(int comSize) { // line 19
ArrayList<String> alphaCells = new ArrayList<String>();
String [] alphacoords = new String [comSize]; // holds 'f6' type coords
String temp = null; // temporary String for concat
int [] coords = new int[comSize]; // current candidate coords
int attempts = 0; // current attempts counter
boolean success = false; // flag = found a good location ?
int location = 0; // current starting location

comCount++; // nth dot com to place
int incr = 1; // set horizontal increment
if ((comCount % 2) == 1) { // if odd dot com (place vertically)
incr = gridLength; // set vertical increment
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~here!!!
// Number 200!!!
//Why 200???
while ( !success & attempts++ < 200 ) { // main searchloop (32)
//////////////////////////////////


location = (int) (Math.random() * gridSize); // get random starting point
System.out.print(" try " + location);
int x = 0; // nth position in dotcom to place
success = true; // assume success
while (success && x < comSize) { // look for adjacent unused spots
if (grid[location] == 0) { // if not already used
coords[x++] = location; // save location
location += incr; // try 'next' adjacent
if (location >= gridSize){ // out of bounds - 'bottom'
success = false; // failure
}
if (x>0 & (location % gridLength == 0)) { // out of bounds - right edge
success = false; // failure
}
} else { // found already used location
System.out.print(" used " + location);
success = false; // failure
}
}
System.out.println("\n");
System.out.println(attempts);
} // end while


int x = 0; // turn good location into alpha coords
int row = 0;
int column = 0;
System.out.println("\n");
while (x < comSize) {
grid[coords[x]] = 1; // mark master grid pts. as 'used'
row = (int) (coords[x] / gridLength); // get row value
column = coords[x] % gridLength; // get numeric column value
temp = String.valueOf(alphabet.charAt(column)); // convert to alpha

alphaCells.add(temp.concat(Integer.toString(row)));
x++;

System.out.print(" coord "+x+" = " + alphaCells.get(x-1));

}

System.out.println("\n");

return alphaCells;
}
}
-------------
I wondered

The meaning of 200............

It's just a big number of our actions?





[ April 29, 2008: Message edited by: Lee EunA ]

[edited to make subject meaningful - was "important question !!!please~~~"]
[ April 29, 2008: Message edited by: Jeanne Boyarsky ]
Alaa Nassef
Ranch Hand

Joined: Jan 28, 2008
Posts: 460
Hello Lee,

Which book is this from? How is this struts related? Administrators are going to refuse the title of the post since it's not descriptive.


Visit my blog: http://jnassef.blogspot.com/
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Hi,

Welcome to JavaRanch!

Yes, it's just a large number. After 200 attempts, the loop will exit.


[Jess in Action][AskingGoodQuestions]
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

It's often better to give "magic numbers" like this a descriptive name. For example...

static final int MAX_ALLOWED_ATTEMPTS = 200;

Then the code would be more clear...

while(!success && (attempts++ < MAX_ALLOWED_ATTEMPTS)) {...


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: does 200 mean something?