2016-11-16 WordSearch final update

posted Nov 16, 2016, 7:08 AM by Samuel Konstantinovich   [ updated Nov 16, 2016, 8:50 PM ]
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++){
	    System.out.println(randgen.nextInt());
	}
    }
}


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.


so:

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


It would make sense to have two constructors for your WordSearch:
public WordSearch(int r, int c, String filename){...}
public WordSearch(int r, int c, String filename, int seed, boolean showKey){...}

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

Sample how to read the args:

public static void main(String[]args){
if(args.length >=2){
    System.out.println(Integer.parseInt(args[0])+Integer.parseInt(args[1]));
}
}




Comments