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

2018-11-13 WordSearch final update.

posted Nov 13, 2018, 6:09 AM by Konstantinovich Samuel   [ updated Nov 15, 2018, 11:36 AM ]
Quiz This Thurs/Fri  on random, random seed, arrayList, arrays.

Do Now:
1. PAIR UP (triples ok if the row is oddly filled)
2. Discuss with your neighbors and then BOTH of you: WRITE an outline of this program on paper.
3. Write your name and your partner's name on each copy.

Note: each numerical value is nextInt()%100

$java Rerandom
This is your seed: 33211
-94 86 -97 -96 48 99 -6 56 25 -97
$java Rerandom
This is your seed: 23479
-6 66 27 -39 51 -80 27 95 -19 55
$java Rerandom
This is your seed: 82264
57 -53 -64 -75 10 88 69 0 -16 -56 
$java Rerandom 33211
This is your seed: 33211
-94 86 -97 -96 48 99 -6 56 25 -97
$java Rerandom 82264
This is your seed: 82264
57 -53 -64 -75 10 88 69 0 -16 -56






Final revision, to your WordSearch Repo.
This is due Monday 11/19/2018 8am.
This is ample time to complete the assignment. HOWEVER other small assignments may also be given before then.
You will get 2 lab days this week.  (and maybe a partial day)


Overview of new main behavior:

java WordSearch [rows cols filename [randomSeed [answers]]]  
//square brackets mean optional


Edit: removed "java WordSearch" and redefined valid.
This means that each of these will produce a puzzle or key:
java WordSearch rows cols filename
java WordSearch rows cols filename randomSeed  
java WordSearch rows cols filename randomSeed answers  

0. You must handle all exceptions.

1. You must print directions to the user that explain how to use the program when:
  • 0, 1, or 2 command line arguments are specified (this is not enough to run the program)
  • the file is not found
  • any numerical arguments are improperly formatted or out of range*
*Valid ranges:
seed is from 0 to 10000 inclusive
row/col must be > 0


Printing the directions is the end of the program, it should not do anything else!

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 choose a random seed from 0 to 10000 inclusive.
   The puzzle is constructed with words from the textfile specified, and after thee words are added, you fill the 
   remaining spaces with random letters.
   The puzzle is then printed (including the seed).

3. When you give 3 arguments, you may optionally also give randomSeed to choose which seed your program uses. 
   The purpose of this is to force the same puzzle to occur again, so you can reprint the puzzle and/or the answers later.
   The puzzle is then printed (including the seed).

4. When you give 4 arguments, you may optionally give a parameter to display answers. 
The answer is just the puzzle but without the random letters filled in! 
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.
   The puzzle answer is then printed (including the seed).


Sample output of word search
java WordSearch 4 4 words.txt  
OR
java WordSearch 4 4 words.txt 103
|X Y F B|
|I A I F|
|D E S A|
|M E H R|
Words: FAD, FISH, MEH (seed: 103)

Sample output of a solution: (solutions use spaces instead of underscores because it looks better)
java WordSearch 4 4 words.txt 103 key
|    F  |
|  A I  |
|D   S  |
|M E H  |
Words: FAD, FISH, MEH (seed: 103)


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

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


All of the following would print the directions (for various reasons)
java WordSearch 20 30
usage: java WordSearch [rows cols filename [randomSeed [answers]]]

java WordSearch 20 30 names.txt 51248
usage: java WordSearch [rows cols filename [randomSeed [answers]]]

java WordSearch 20 -30 names.txt 5248
usage: java WordSearch [rows cols filename [randomSeed [answers]]]

java WordSearch FISH 30 names.txt 5148
usage: java WordSearch [rows cols filename [randomSeed [answers]]]


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 3 correct ways of using it above AS WELL AS various invalid ways.
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.
- I am checking the main of your WordSearch by changing the command line arguments!


import java.util.*;
public class Rerandom{
    public static void main(String[]args){
        //change this to any seed you want.
        int seed = (int)(Math.random()*100000);


	//Manually assign a seed if you wish
        //seed = 17127;
        //or use the args
        if(args.length > 0){
          seed = Integer.parseInt(args[0]);
        }


        System.out.println("This is your seed: "+seed);
	Random randgen = new Random(seed);
        
        //Use the random to generate 10 numbers
for(int i=0;i<10;i++){ System.out.print(randgen.nextInt()%100+" "); } System.out.println(); } }
Comments