Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎notes‎ > ‎


posted Nov 13, 2017, 9:53 AM by Konstantinovich Samuel
Final update on word search:

Goal: Command Line Parsing!

Use a Random object to re-create your random number sequence and reproduce errors / issues.

import java.util.*;
public class rerandom{
    public static void main(String[]args){
	int seed = (int)(Math.random()*100000);
	//seed = 17127;
        //change this to any seed you want.
	System.out.println("This is your seed: "+seed);
	Random randgen = new Random(seed);

	for(int i=0;i<10;i++){

Final revision, your puzzle generator is due Monday 11/21/2016 8am.
Overview of new main behavior:
java Driver [rows cols filename [randomSeed [answers]]]  
//square brackets mean optional
This means that each of these are valid:
java Driver
java Driver rows cols filename
java Driver rows cols filename randomSeed  
java Driver rows cols filename randomSeed answers  

1. If no command line arguments are specified, print directions to tell the user how to run the program.
2. rows and cols are the dimensions of the puzzle, filename is the name of the plain text file that contains words. If they are the only parameters passed, you should print the random seed with the puzzle. 
3. The randomSeed can be changed to force the same puzzle to occur again, so you can print the puzzle and the answers later.
4. If the randomSeed is provided, you can have a 4th parameter to display answers. You trigger answer mode by passing the value "key" into the answers parameter. Omitting the answers parameter, or passing any other values will just display the normal puzzle, and not show the answer.
5. Any invalid formatting of the command line arguments should print directions.


java Driver 20 30
 names.txt 124850
//would print the 20x30 puzzle seeded by 124850
java Driver 20 30 names.txt  124850 fish
//would print the 20x30 puzzle seeded by 124850
java Driver 20 30 names.txt  124850 key 
//would print the 20x30 answer key for the puzzle seeded by 124850    (all 3 of these will match)

java Driver 10 20 fish.txt 8230 oops
java Driver 10 20 fish.txt 8230     
//would print the 10x20  puzzle seeded by 8230  (both of these will match, neither are answer keys)

Changing the seed, dimensions of the puzzle, or quantity of words, even by a single number/word, will cause a completely different puzzle to occur. 

Write your main in your WordSearch. I will test your program with the 4 different ways of using it above.
java WordSearch
java WordSearch r c mydatafile.txt 
java WordSearch r c mydatafile.txt s
java WordSearch r c mydatafile.txt s key

Then use your main to construct the object and output the appropriate puzzle!

Things to note:
- I am not checking your WordSearch methods! I don't care what you called them. This assignment is a main program that is tested by changing the command line arguments!
- You will need at least one text file to test this. You should have a few, including one with words that are easy to spot (special Characters or repeated letters.)
- You should have public methods in your WordSearch to look at:  
    *list of added words
    *random seed