/**
 * CS149 - Introduction to Programming
 * Department of Computer Science
 * James Madison University
 * @version Fall 2018
 */

PA4 - 00000111 Little Words (Loops and Arrays)

Due Dates and Submission Details

See submission details below for all due dates and submission details. Note there are multiple submission parts.

Honor Code

This assignment should be completed individually to maximize learning. It is important that you adhere to the Course Policies, particularly the section on Programming Assignments. Also relevant is the JMU Honor Code.

Objectives

Background

In this program, you will implement a simplified text version of the 7 Little Words — game. (For those of you who may not know, 00000111 interpreted as a base 2 number is 7 in base 10.) The 7 Little Words website explains the game and will allow you to play it. Our text version is very similar, but breaks every solution word into only two pieces, then displays those words in text boxes vertically instead of as a graphical grid. Our version does not give the hint of how many letters a solution is but otherwise works very similar to the game on the website. The clues must be solved in order and the user can ask for multiple hints for each clue. Hints can be the first letter of the solution, the first "slice" or part of the solution word in the puzzle, or the whole word.

Requirements

You will be writing two classes for this assignment, Generator.java and TerminalUI.java and one test class, GeneratorTest.java. The methods for the first two classes will have methods as described below. Note that each method must be implemented exactly as described. See the example input and output below for the form of the interaction with the user.

TerminalUI.java

Generator.java

Testing

This assignment requires you to use both of the testing techniques you have learned so far. TerminalUI.java should be tested first using TerminalUIDriver.java and test.in and test.exp files as in PA2. The driver code is provided for you below along with one test. Generator.java should be tested using JUnit and your GeneratorTest.java file will be submitted as part of your submission. Note that the examples given in the method explanations above are provided in JUnit below. Don't forget to include tests for invalid inputs as described for each method.

You should test TerminalUI with several of your own tests, but included here is a pa4TUItest1.in and a pa4TUItest1.exp to give you one verified command-line test. You may also like to test your program using this driver to play the game. SevenLittleWords. DO NOT upload these drivers as a part of your submission!

Below is a set of tests you may find helpful for testing Generator.java.

  Assert.assertArrayEquals("Error in test1: wordSplicer",
                 new String[] {"tof", "utti", "magn", "etism"},
                 Generator.wordSplicer(new String[] {"tofutti", "magnetism"}));

  Assert.assertArrayEquals("Error in test1: randomizer",
                 new String[] {"dling", "aurus", "edi", "tof",
                "fice", "gri", "magn", "ll", "bu", "utti",
                "nder", "etism", "groun", "thes"},
                 Generator.randomizer(new String[] {"tof", "utti", "magn", "etism",
                  "edi", "fice", "gri", "nder", "groun", "dling",
                  "thes", "aurus","bu", "ll"}, 0));
  Assert.assertEquals("Error in test1: clueToString",
               "1) a small bird\n2) common flavor\n",
               Generator.clueToString(new String[] {"a small bird", "common flavor"}));

  String actualBoard = Generator.boardToString(board);
  Assert.assertEquals("Error in test1: boardToString",
      "------------\n| 01 | tof |\n------------\n-------------\n| 02 | utti |\n-------------\n",
      actualBoard);

  

Submission

This assignment has two parts that should be completed in order. By the first deadline you should submit TerminalUI.java , Generator.java (stubs that return the examples given above only), and GeneratorTest.java (one test per method only). By the second deadline you must submit your completed code for all three TerminalUI.java, Generator.java, and GeneratorTest.java through AutoLab.

Part A - Friday October 19, 11:00PM

Read this entire document and complete the code for TerminalUI.java, the stubs for Generator.java that return the examples above, and a version of GeneratorTest.java that has at least one good test for each method. This submission cannot be late!. You must submit by the deadline to get any credit.

Part B - Friday October 26, 11:00PM

Upload your completed Generator.java, GeneratorTest.java, and your TerminalUI.java files through AutoLab.

You must implement the above in java, creating a file called TerminalUI.java, Generator.java and GeneratorTest.java. Before uploading your files, be sure to carefully complete the steps below. If you are having trouble getting started, see the Hints section further below.

Your submission will be graded using the following criteria:

RequirementPoints
PART A: TerminalUI.java 10
PART A: Generator.java (stubs)5
PART A: GeneratorTest.java (100% coverage of stubs)10
PART A: Checkstyle5
PART B: Checkstyle5
PART B: Instructor grading based on style, code quality, comments.5
PART B: Loop with nested if-else statement (PromptNDisplayHints)5
PART B: While/do-while context loop (promptForString, promptForInt)10
PART B: Basic for context loop (clueToString)5
PART B: Pass arrays as method arguments and return values (wordSplicer)5
PART B: Manipulate, initialize, copy and compare elements of arrays of Strings (wordSplicer, randomizer)10
PART B: Generate random numbers based on an algorithm (randomizer)5
PART B: Use nested loops (boardToString)5
PART B: JUnit tests 100% coverage and passing15

Don't put off submission until the last possible minute! Any submission system may become bogged down when it receives a large number of submissions. You may have some unanticipated difficulties uploading your code. It is your responsibility to take these possibilities into account and submit early enough to ensure that the submission process is completed before the deadline. It is recommended that you submit once early, after you have a set of stubs completed, to make sure that you have all of the method and class definitions exactly right.

Hints

It would be wise to implement the code in the following order.

  1. Implement promptForInt in TerminalUI. Test it using your own main or the interactions pane in your IDE and make needed changes.
  2. Implement promptForString in TerminalUI. Test it using your own main or the interactions pane in your IDE and make needed changes.
  3. Test promptForInt and promptForString only using the TerminalUIDriver code by using a stub for promptNDisplayHints. Make needed changes.
  4. Implement and test promptNDisplayHints using the TerminalUIDriver. Make needed changes.
  5. Implement stubs only for GeneratorTest.java.
  6. Implement a single test at a time for each method in GeneratorTest.java, making sure each one compiles correctly with GeneratorTest.java
  7. Once you have 100% code coverage from your tests, submit to the submission system.

Going Further

Why did we use the colors above (input/output)?

Acknowledgments

This assignment was originally designed by Dee Weikle and Alvin Chao.