CMPSCI 187 / Spring 2015 Hangman

Similar documents
CMPSCI 187 / Spring 2015 Sorting Kata

CMPSCI 187 / Spring 2015 Hanoi

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

COMPSCI 220 Programming Methodology Project Assignment 06: Expression Evaluator

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Lab 1: Silver Dollar Game 1 CSCI 2101B Fall 2018

Tips from the experts: How to waste a lot of time on this assignment

Simple design exercise similar to what you will do for your CS102 project (and what happens in industry!) Stages:

CS201 - Assignment 3, Part 2 Due: Wednesday March 5, at the beginning of class

CS 201 Advanced Object-Oriented Programming Lab 6 - Sudoku, Part 2 Due: March 10/11, 11:30 PM

Tips from the experts: How to waste a lot of time on this assignment

Lab Exercise 6: Abstract Classes and Interfaces CS 2334

Com S 227 Assignment Submission HOWTO

CMSC 201 Spring 2018 Project 3 Minesweeper

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

CS 2110 Fall Instructions. 1 Installing the code. Homework 4 Paint Program. 0.1 Grading, Partners, Academic Integrity, Help

Assignment Submission HOWTO

EE 422C HW 6 Multithreaded Programming

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do:

Our second exam is Thursday, November 10. Note that it will not be possible to get all the homework submissions graded before the exam.

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Project 3: Implementing a List Map

15-110: Principles of Computing, Spring 2018

IBM WebSphere Java Batch Lab

Hangman - Compsci 201

Assignment 5: Part 1 (COMPLETE) Sprites on a Plane

Laboratory 1: Eclipse and Karel the Robot

Carrera: Analista de Sistemas/Licenciatura en Sistemas. Asignatura: Programación Orientada a Objetos

CS201 - Assignment 3, Part 1 Due: Friday February 28, at the beginning of class

Our second exam is Monday, April 3. Note that it will not be possible to get all the homework submissions graded before the exam.

CE151 ASSIGNMENT

Be sure check the official clarification thread for corrections or updates to this document or to the distributed code.

Programming Project 5: NYPD Motor Vehicle Collisions Analysis

Moodle 2.2 Student User Guide My Private Files

Project #2: Linear Feedback Shift Register

CSCI 135 Programming Exam #1 Fundamentals of Computer Science I Fall 2014

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

CS 134 Programming Exercise 9:

Programming Project 1

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

Web-CAT Guidelines. 1. Logging into Web-CAT

Tips from the experts: How to waste a lot of time on this assignment

Com S 227 Spring 2018 Assignment points Due Date: Thursday, September 27, 11:59 pm (midnight) "Late" deadline: Friday, September 28, 11:59 pm

CS161: Introduction to Computer Science Homework Assignment 10 Due: Monday 11/28 by 11:59pm

CS 051 Homework Laboratory #2

Lab Exercise 4: Inheritance and Polymorphism CS 2334

Remaining Enhanced Labs

CPSC 217 Assignment 3

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

CS 2110 Summer 2011: Assignment 2 Boggle

CS2 Practical 1 CS2A 22/09/2004

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

CSCI 161: Introduction to Programming I Lab 1b: Hello, World (Eclipse, Java)

CS3114 (Fall 2013) PROGRAMMING ASSIGNMENT #2 Due Tuesday, October 11:00 PM for 100 points Due Monday, October 11:00 PM for 10 point bonus

Worksheet 3: Predictive Text Entry

CS 2223 B15 Term. Homework 1 (100 pts.)

Eric Roberts Handout #27 CSCI 121 October 3, Project #2 Snowman. This assignment is designed to build your skills in the following areas:

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

UNic Eclipse Mini Tutorial (Updated 06/09/2012) Prepared by Harald Gjermundrod

ASSIGNMENT 4 Classes and Objects

PA101 Learning the Ropes

CS261: HOMEWORK 2 Due 04/13/2012, at 2pm

CMSC 201 Spring 2017 Homework 4 Lists (and Loops and Strings)

Programming Principles 1 (CSC131) & 2 (CSC132) Software usage guide

COSC-211: DATA STRUCTURES HW5: HUFFMAN CODING. 1 Introduction. 2 Huffman Coding. Due Thursday, March 8, 11:59pm

Using System.out.println()

CS211 Computers and Programming Matthew Harris and Alexa Sharp July 9, Boggle

Installing a Custom AutoCAD Toolbar (CUI interface)

CIS 162 Project 4 Farkle (a dice game)

Assignment #4 Minesweeper

ASSIGNMENT 2. COMP-202A, Fall 2011, All Sections. Due: Monday, October 17th, 2011 (23:30)

Database Use & Design

18-Dec-09. Exercise #7, Joongle. Background. Sequential search. Consider the following text: Search for the word near

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018

Fundamentals: Expressions and Assignment

Assignment 5: MyString COP3330 Fall 2017

Initial Coding Guidelines

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

CSIS 10B Lab 2 Bags and Stacks

CSC116: Introduction to Computing - Java

CSCI 1301: Introduction to Computing and Programming Spring 2018 Project 3: Hangman 2.0 (A Word Guessing Game)

CS100M November 30, 2000

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

First Visual Basic Lab Paycheck-V1.0

ASSIGNMENT 5 Objects, Files, and a Music Player

Faculty Guide. Creating your Blank Shell for Blackboard Learn:

Prelim 1. CS 2110, September 29, 2016, 7:30 PM Total Question Name Loop invariants

CS451 - Assignment 3 Perceptron Learning Algorithm

Cmpt 101 Lab 1 - Outline

Chapter 4 Defining Classes I

15-110: Principles of Computing, Spring 2018

Up Diagonal. Right. Question No. 1 (60 points)

Lesson 10: Quiz #1 and Getting User Input (W03D2)

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

Assignment #4 Hangman Due: 3:15pm on Monday, November 3rd Your Early Assignment Help (YEAH) hours: 4:15pm-5:15pm, Friday, October 24th in Hewlett 200

During the first 2 weeks of class, all students in the course will take an in-lab programming exam. This is the Exam in Programming Proficiency.

Code::Blocks Student Manual

CS Programming Exercise:

Transcription:

CMPSCI 187 / Spring 2015 Hangman Due on February 12, 2015, 8:30 a.m. Marc Liberatore and John Ridgway Morrill I N375 Section 01 @ 10:00 Section 02 @ 08:30 1

CMPSCI 187 / Spring 2015 Hangman Contents Overview 3 Learning Goals................................................. 3 General Information 3 Policies..................................................... 3 Test Files.................................................... 4 Problem 1 4 Import Project into Eclipse........................................... 4 Starter Code and Tests............................................. 5 Hangman Game................................................. 5 Our Version of Hangman............................................ 6 Array Implementation.............................................. 6 Linked List Implementation........................................... 7 Testing...................................................... 8 Export and Submit............................................... 9 Sample Output................................................. 9 Page 2 of 10

CMPSCI 187 / Spring 2015 Hangman Overview This problem will have you implement a game called Hangman, using an interface defining the logical view of a game board. You will write two implementations, the first using arrays, and the second using linked lists. In this assignment you will be starting from initial code provided by us, adding to and modifying it, and creating new classes similar to existing classes. Learning Goals Continue to exercise your understanding of arrays, interfaces, and classes. Develop your understanding of the linked list abstraction and its implementation. Show ability to break a larger problem down into manageable pieces. Read a specification in text and as a Java interface, and demonstrate understanding by implementing it. Use existing JUnit test cases. Write new JUnit test cases to test specified behaviors. General Information Read this entire document. If, after a careful reading, something seems ambiguous or unclear to you, then email cs187help@cs.umass.edu immediately. Start this assignment as soon as possible. Do not wait until 5pm the night before the assignment is due to tell us you don t understand something, as our ability to help you will be minimal. Reminder: Copying partial or whole solutions, obtained from other students or elsewhere, is academic dishonesty. Do not share your code with your classmates, and do not use your classmates code. You are responsible for submitting project assignments that compile and are configured correctly. If your project submission does not follow these policies exactly you may receive a grade of zero for this assignment. Policies For some assignments, it will useful for you to write additional class files. Any class file you write that is used by your solution MUST be in the provided src directory you export. The TAs and instructors are here to help you figure out errors, but we won t do so for you after you submit your solution. When you submit your solution, be sure to remove all compilation errors from your project. Any compilation errors in your project will cause the autograder to fail, and you will receive a zero for your submission. Page 3 of 10

CMPSCI 187 / Spring 2015 Hangman Test Files In the test directory, we provide several JUnit test cases that will help you keep on track while completing the assignment. We recommend you run the tests often and use them to help create a checklist of things to do next. But you should be aware that we deliberately don t provide you the full test suite we use when grading. We recommend that you think about possible cases and add new @Test cases to these files as part of your programming discipline. Simple tests to add will consider questions such as: Do your methods taking integers as arguments handle positives, negatives, and zeroes (when those values are valid as input)? Does your code handle unusual cases, such as empty or maximally-sized data structures? More complex tests will be assignment-specific. To build good test cases, think about ways to exercise methods. Work out the correct result for a call of a method with a given set of parameters by hand, then add it as a test case. Note that we will not be looking at your test cases, they are just for your use. Before submitting, make sure that your program compiles with and passes all of the original tests. If you have errors in these files, it means the structure of the files found in the src directory have been altered in a way that will cause your submission to lose some (or all) points. Problem 1 Note: You may not use any of the classes from the Java Platform API that implement the Collection interface (or its sub-interfaces, etc.). The list of these classes is included in the API documentation, available at: http: //docs.oracle.com/javase/7/docs/api/java/util/collection.html. Doing so will be viewed as an attempt to cheat. Import Project into Eclipse Begin by downloading the starter project and importing it into your workspace. It is very important that you do not rename this project as its name is used during the autograding process. If the project is renamed, your assignment will not be graded, and you will receive a zero. The imported project may have some errors, but these should not prevent you from getting started. Specifically, we may provide JUnit tests for classes that do not yet exist in your code. You can still run the other JUnit tests. The project should normally contain the following root items: src This is the source folder where all code you are submitting must go. You can change anything you want in this folder (unless otherwise specified in the problem description and in the code we provide), you can add new files, etc. Problem 1 continued on next page... Page 4 of 10

support This folder contains support code that we encourage you to use (and must be used to pass certain tests). You must not change or add anything in this folder. To help ensure that, we suggest that you set the support folder to be read-only. You can do this by right-clicking on it in the package explorer, choosing Properties from the menu, choosing Resource from the list on the left of the pop-up Properties window, unchecking the Permissions check-box for Owner-Write, and clicking the OK button. A dialog box will show with the title Confirm recursive changes, and you should click on the Yes button. test The test folder where all of the public unit tests are available. JUnit 4 A library that is used to run the test programs. JRE System Library This is what allows Java to run; it is the location of the Java System Libraries. If you are missing any of the above or if errors are present in the project (other than in JUnit tests), seek help immediately so you can get started on the project right away. Starter Code and Tests First, explore the code as it is. In the src/hangman directory you will find ArrayGame.java. This file is just a driver, and contains only a main() method. It picks a word and allocates instances of ConsoleGameIO, ArrayGameModel, and GameController. (This driver is for the array-based version, so it uses ArrayGameModel.) These classes (except ArrayGameModel) are defined in support/hangman, and you must not modify them. The GameController class actually runs the game, getting input from and sending output to the GameIO instance. The state of the game is maintained in the GameModel instance. The GameModel interface is also defined in support/hangman and must also not be modified. Read GameModel carefully to see what your implementations of it must do. ArrayGameModel is an empty implemenation of GameModel. The starter code you receive is not a working implementation. However, you can still run ArrayGame. It will allow you to enter guesses, but it will never terminate. You can terminate the running program by pressing on the red square button in the top left of the console buttons: Hangman Game The rules for Hangman are simple and you can read the details online, for example, at http://en.wikipedia. org/wiki/hangman_%28game%29. Typically two players play the game with pencil and paper. Player A thinks Problem 1 continued on next page... Page 5 of 10

of a word and writes down a sequence of underscores representing the word (the game board) that player B needs to guess. For example, if player A picks the case-sensitive word hello then she would write: An underscore is used for each letter that has not been guessed yet. Player B will then proceed to guess letters one at a time that might be contained in the unknown word. If a letter that player B guesses is contained in the word, player A will replace the underscore in the appropriate location with the letter that player B guessed. For example, if player B guesses L then player A would write: L L Note that if the guessed letter appears in multiple places in the word, each letter is revealed on the game board. If player B guesses a letter that is not in the word then player A will draw a part of the hangman picture. For example, if player B guesses an a then the result would be: -------- [L, a] L L, where the -------- represents the start of the hangman platform. The [L, a] represents the list of letters that the player has guessed previously. If player B continues to guess incorrectly she will lose the game with the following being written down by player A: ----- O /\ / \ --------- [L, a, b, C, x, g, P, k, z, m, N, q, w, i] The word was HeLLo! You lose! Our Version of Hangman In our version of the hangman game there are 11 states. The first state (state 0) is empty and the last state (state 10) is the complete hangman platform, as shown above. You can see each state diagrammatically in ConsoleGameIO.java. Note that, as demonstrated above, our version of hangman also considers the difference between uppercase and lowercase letters. That is, the letter A is not the same as a. Make sure your implementation takes this distinction into consideration. Finally, our version of hangman assumes that the set of possible letters are drawn from the standard English alphabet not other characters that could possibly be entered (such as numbers, symbols, or characters from other languages such as é). Your implementation must accept and correctly handle all fifty-two of these characters, and reject all other characters. Array Implementation First, you will complete the hangman game by providing an array-based implementation of GameModel in the ArrayGameModel.java file. We have provided a minimal start to your implementation, but the rest is up to you! The ArrayGameModel class implements the GameModel interface. A game model represents the current state of the game (0-10), the word currently being guessed ( L L ), and the previous guesses ([L, a, b]). It must also know what the word is that is being guessed (e.g., HeLLo ). Again, you should review the documentation in the GameModel interface to gain a better understanding of each method you need to implement. Here is a brief overview of the methods that are required in your implementation (more details are provided in the comments in GameModel.java): Problem 1 continued on next page... Page 6 of 10

boolean ispriorguess(char guess); This method returns true if the character guess has been guessed previously. int numberofguesses(); This method returns the number of guesses already guessed (excluding repeated guesses). boolean iscorrectguess(char guess); This method returns true if the character guess is a guess that has not been guessed before and is a character that is in the word to be guessed. boolean domove(char guess); This method will play the character guess on the game board. boolean inwinningstate(); This method returns true if the game is in a winning state. boolean inlosingstate(); This method returns true if the game is in a losing state. int getstate(); This method returns the current hung state (in the interval 0 10). String tostring(); This method returns a string representation of the game. For example: L L String previousguessstring(); This method returns a string representation of the previous guesses. For example: [L, a, b, C, x, g, P, k, z, m, N, q, w, i] String getword(); This method returns the word that the player is trying to guess. You will notice that there are 10 TODO comments in the provided ArrayGameModel.java file. You must implement each of these TODOs in order to satisfy the public JUnit tests that we provide. Your implementation must use Java arrays internally to represent the game board and the previous guesses. We have also provided the start of a constructor in the starter code that you should use to initialize the state of the game. The constructor takes a single String argument representing the word to be guessed: 1 public ArrayGameModel(String guessword) { 2 // TODO (1) 3 state = STARTING_STATE; 4 } Remember, you must not use any Collection abstractions (such as ArrayList) provided by the Java Platform API. Linked List Implementation In this part, your job is to complete the hangman game by providing an implementation using a linked list for the hangman game. You need to create a new class that implements the GameModel interface. To do this in Eclipse you select the arrow to the right side of the GameModel.java file in the Package Explorer in Eclipse to reveal the interface icon: Problem 1 continued on next page... Page 7 of 10

Right-click on the interface icon and select New Class. This will bring up a New Java Class wizard. Modify the Source folder: to create the file in the src directory instead of the support directory. Give your new class the name LinkedListGameModel (do not use a different name, or your program will not pass the autograder). This will create a new Java file in the Package Explorer called LinkedListGameModel.java with all of the methods that you must implement to satisfy the interface in that file. You will need to add a constructor for this new class that takes the same argument as the ArrayGameModel class (a String representing the word to be guessed). In order to implement the LinkedListGameModel interface you will need to provide a class to implement a linked list of characters in the same spirit as the LLStringNode class covered in detail in the book. You must name this new class LLCharacterNode. It must have a constructor that takes a single char argument, a getter named getinfo that returns the stored char, and a pair of getters/setters named getlink and setlink that allow creation and traversal of the list. Use the LLCharacterNode in your implementation of the LinkedListGameModel class. The LinkedListGameModel class implements the GameModel interface. A game model represents the current state of the game (0-10), the word currently being guessed ( L L ), and the previous guesses ([L, a, b]). It must also know what the word is that is being guessed (e.g., HeLLo ). Again, you should review the documentation in the GameModel interface file to gain a better understanding of each method you need to implement. You will also need to create a LinkedListGame class similar to the ArrayGame class to test the execution of your implementation. Remember, you must not use any Collection abstractions (such as ArrayList) provided by the Java Platform API. Testing We provide three public JUnit test classes you should use to test your implementation: ArrayGameModelPublicTest.java LinkedListGameModelPublicTest.java LLCharacterNodePublicTest.java You should run these tests to test your implementation of each classes. You should note that the LinkedListGameModelPublicTest and LLCharacterNodePublicTest classes will contain errors until you have created the required classes for the linked list implementation. Your grade for this assignment will depend on the results of these tests as well as private tests (that are not visible to you) that we have constructed to ensure that your implementation has not been tailored to the public tests. Problem 1 continued on next page... Page 8 of 10

Export and Submit When you have completed the changes to your code, you should export an archive file containing the entire Java project. To do this, click on the hangman-student project in the package explorer. Then choose File Export from the menu. In the window that appears, under General choose Archive File. Then choose Next and enter a destination for the output file. Be sure that the project is named hangman-student. Save the exported file with the zip extension (any name is fine). Log into Moodle and submit the exported zip file. Sample Output Here is an example of the output generated from our solution to give you an idea of what the completed program should produce when implemented correctly. pick a letter: i Good guess! [i] _ i pick a letter: i You guessed i already! guess: _ i [i] _ i pick a letter: n Good guess! [i, n] _ i n n pick a letter: m -------- [i, n, m] _ i n n pick a letter: w Good guess! pick a letter: q -------- [i, n, m, w, q] pick a letter: x ----- -------- [i, n, m, w, q, x] pick a letter: k -------- [i, n, m, w] Problem 1 continued on next page... Page 9 of 10

----- -------- [i, n, m, w, q, x, k] pick a letter: g ----- O -------- [i, n, m, w, q, x, k, g] pick a letter: h ----- O -------- [i, n, m, w, q, x, k, g, h] pick a letter: o ----- O / -------- [i, n, m, w, q, x, k, g, h, o] pick a letter: e Good guess! ----- O / -------- [i, n, m, w, q, x, k, g, h, o, e] w i n n e _ pick a letter: r Good guess! ----- O / -------- [i, n, m, w, q, x, k, g, h, o, e, r] You won! The word was winner! Number of guesses: 12 Page 10 of 10