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:

Similar documents
C Sc 227 Project 1: Three Main Methods

Programming Project: ArrayFun

(First is used here)

Programming Project: Game of Life

Assignment: TwoMethods Submitted to WebCat


Example Program. public class ComputeArea {

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

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

New York University Introduction to Computer Science Exam Sample Problems 2013 Andrew I. Case. Instructions:

CPSC 233: Assignment 4 (Due March 26 at 4 PM)

CMPSCI 187 / Spring 2015 Hangman

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

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CS61BL. Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling

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

CMPSCI 187 / Spring 2015 Postfix Expression Evaluator

1. [3 pts] What is your section number, the period your discussion meets, and the name of your discussion leader?

Question: Total Points: Score:

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

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

RANDOM NUMBER GAME PROJECT

Controls Structure for Repetition

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Spring 2016 Howard Rosenthal

CIS 1068 Design and Abstraction Spring 2017 Midterm 1a

Claremont McKenna College Computer Science

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

AP Computer Science Java Mr. Clausen Program 6A, 6B

Chapter 6. Repetition Statements. Animated Version The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

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

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Lab Exercise 6: Abstract Classes and Interfaces CS 2334

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

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

Soda Machine Laboratory

CMPSCI 187 / Spring 2015 Implementing Sets Using Linked Lists

Section 002 Spring CS 170 Exam 1. Name (print): Instructions:

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

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

Program 12 - Spring 2018

CMPSCI 187 / Spring 2015 Sorting Kata

CSE142 Sample Midterm Spring Name UW NetId (e.g. whitab) Section (e.g., AA) TA

Chapter 7 User-Defined Methods. Chapter Objectives

Selec%on and Decision Structures in Java: If Statements and Switch Statements CSC 121 Fall 2016 Howard Rosenthal

Programming Assignment 2 (PA2) - DraggingEmoji & ShortLongWords

Fundamentals of Programming Data Types & Methods

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

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

Assignment 2, perquack2 class hierarchy in Java, due 11:59 PM, Sunday March 16, 2014 Login into your account on acad/bill and do the following steps:

Object Oriented Programming with JAVA

: Principles of Imperative Computation. Fall Assignment 5: Interfaces, Backtracking Search, Hash Tables

CSE 114 Computer Science I

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

Question 1 [20 points]

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

St. Edmund Preparatory High School Brooklyn, NY

Java Programming. String Processing. 1 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

CMPSCI 187 / Spring 2015 Hanoi

Introduction to OOP with Java. Instructor: AbuKhleif, Mohammad Noor Sep 2017

CSIS-120 Final Exam Fall 2015 Name:

Introduction to Computer Programming

CAT.woa/wa/assignments/eclipse

Question: Total Points: Score:

Question: Total Points: Score:

public class Q1 { public int x; public static void main(string[] args) { Q1 a = new Q1(17); Q1 b = new Q1(39); public Q1(int x) { this.

This is a combination of a programming assignment and ungraded exercises

Final Exam Practice. Partial credit will be awarded.

- 1 - Handout #33 March 14, 2014 JAR Files. CS106A Winter

COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

Programming: Java. Chapter Objectives. Chapter Objectives (continued) Program Design Including Data Structures. Chapter 7: User-Defined Methods

Guessing Game with Objects

Repetition. Chapter 6

Chapter 3. Selections

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

Repetition. Chapter 6

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

Decisions: Logic Java Programming 2 Lesson 7

-Alfred North Whitehead. Copyright Pearson Education, 2010 Based on slides by Marty Stepp and Stuart Reges from

GB Programming Challenges

Linked Lists. private int num; // payload for the node private Node next; // pointer to the next node in the list }

Hello World! Computer Programming for Kids and Other Beginners. Chapter 1. by Warren Sande and Carter Sande. Copyright 2009 Manning Publications

CS 170 Java Programming 1. Week 13: Classes, Testing, Debugging

Motivating Example: Two Types of Errors (2) Test-Driven Development (TDD) with JUnit. Motivating Example: Two Types of Errors (1)

Programming Assignment 2 ( 100 Points )

Test-Driven Development (TDD) with JUnit

Implement factorial to return n! that is defined as n * n-1 * n-2 * n-3 * 2 * 1. 1! And 0! Are both defined as 1. Use recursion, no loop.

Oct Decision Structures cont d

FOR INTERNAL SCRUTINY (date of this version: 17/2/2016) UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS

Name: Checked: Preparation: Response time experiment accessing the system clock

ASSIGNMENT 5 Objects, Files, and a Music Player

Decision Logic: if, if else, switch, Boolean conditions and variables

15-122: Principles of Imperative Computation, Spring 2013

CSCI 1103: File I/O, Scanner, PrintWriter

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

New York University Intro to Computer Science (CSCI-UA.101) Fall 2014 Midterm #1 Test G. Instructions:

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

CS 315 Software Design Homework 3 Preconditions, Postconditions, Invariants Due: Sept. 29, 11:30 PM

Transcription:

Project MindNumber Collaboration: Solo. Complete this project by yourself with optional help from section leaders. Do not work with anyone else, do not copy any code directly, do not copy code indirectly through reading a computer screen, and do not give your code to anyone. Begin early. Turnin: Submit three well-tested required functions described below to WebCat for the bulk of the score. You will see your score, be given some hints, and will be allowed to submit as often as you desire until you have 100% for 60 /100 points. Include the actual game that we will grade by hand by running it as a Java Application. Goals In this assignment, you are going to implement a number guessing game that is often known as the game of Mastermind. This assignment will give you more experience with 1. Strings 2. User input 3. If statements 4. While statements 5. Testing with JUnit 6. Problem solving 7. Submitting projects to WebCat and learning how to read feedback to get a perfect score First Get the start of the Eclipse Project Download this archive file http://www.cs.arizona.edu/~mercer/assignments/mindnumberstart.zip and import it into Eclipse like this: Select File > Import > General > Existing Projects into Workspace > Next Click the radio button Select Archive File and then click the Browse button to the right Browse to where you downloaded MindNumberStart.zip, click Open, click Finish You will see many errors in MindNumberTest.java. Hover your cursor over any @Test and select the quick fix Add JUnit 4 library to the build path 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: 1. Write assertions to test your code 2. Change three methods from stubs to correct methods 3. Implement the game of MindNumber in a main method so anyone with your program can play the game 4. Optionally, play the game with the GUI Using a Main Method to Play the Game (only after you get three methods working) To first give you an overall feeling for the finished game, we first present a dialog to show how the game will be played. The user will first be prompted to enter a -1 to let the secret number for the program itself pick a secret number. You will also allow users to enter their own secret number, which is done for easier testing of your game (it really helps testing when you know the

'secret' number that you seek). A program generated secret number is a five digit number stored as a String as in "01234" or "92745" but not "1234", "12344", or "123z7". This number can be generated using the existing well-tested method public String generatesecretnumber(). The game should then prompt the game player to guess the number. The input is error checked only to ensure the user enters a string of length 5. Entering "what?" will not help at all, but it should be allowed and should count as a try at the secret number. If the user enters "123456" or "1234", notify the user they must enter 5 digits but do not count this as an attempt at the secret number. The game rules insist that you give the player some feedback on guesses. Based on that feedback, the player makes more guess. Guessing continues until the secret number is guessed or until the maximum number of tries (32) is reached. Here is one sample dialog that plays one game where we, the users, actually input the 'secret' number as 12345. Later on, enter -1 to let the real MindNumber experiences begin. Enter the secret number as a 5 digit number where all digits are unique, or enter -1 to have this program select the secret number. Select your own valid secret number or enter -1: what? 'what?' is not a valid secret number. Select your own valid secret number or enter -1: 123456 '123456?' is not a valid secret number. Select your own valid secret number or enter -1: 12233 '12233' is not a valid secret number. Select your own valid secret number or enter -1: 12345 Enter your 5 digit guess: 11111 Try number: 1 Digits found: 1 Enter your 5 digit guess: 22222 Try number: 2 Digits found: 1 Enter your 5 digit guess: 99999 Try number: 3 Digits found: 0 Correct position: 0 Enter your 5 digit guess: 12333 Try number: 4 Digits found: 3 Correct position: 3 Enter your 5 digit guess: 12344 Try number: 5 Digits found: 4 Correct position: 4 Enter your 5 digit guess: what? Try number: 6 Digits found: 0 Correct position: 0 Enter your 5 digit guess: 123456 '123456' must have a length of 5

Enter your 5 digit guess: 54321 Try number: 7 Digits found: 5 Enter your 5 digit guess: 12345 Try number: 8 Digits found: 5 Correct position: 5 You won in 8 tries! TopDown Design Before implementing the game method, you are asked (okay you are required if you want full credit for this assignment) to write three well-tested methods first that will make writing the actual game itself much easier with far fewer bugs. These three methods listed next should be tested well and have the same exact method signatures. They are all given in class MindNumber as method stubs (they compile but don't work). Sample assertions are included below each method heading to help explain the methods use and behavior (these same assertions are included in starter project MindNumberStart.zip). 1) isvalid / A secret number is valid if it 5 digits long and contains no duplicates and only contains the digits '0', '1', '2',... '9' @param str The secret number being tested for validity @return true if the number is valid public boolean isvalid(string str) asserttrue(m.isvalid("01987")); // These three examples are not valid secret numbers: assertfalse(m.isvalid("1234")); // length is not 5 assertfalse(m.isvalid("12x34")); // chars must be digits, 'x' is not assertfalse(m.isvalid("12933")); // duplicates not allow 2) uniquedigitsfound / Return the number of digits that are contained in both the secret number and the guess. For example when secretnumber: 12345 and guess: 67821, the two numbers share two digits: 1 and 2. @param secretnumber the secret number the user is trying to guess. @param guess the number the user is comparing to the secret number @return the amount of digits the both the secret number and the guess contain. public int uniquedigitsfound(string secretnumber, String guess) assertequals(5, m.uniquedigitsfound("12345", "21435")); assertequals(0, m.uniquedigitsfound("12345", "67890"));

2) foundinposition / Returns the number of matching digits between the guess and the secret number. For example when secretnumber is "12345" guess is "12675" returns 3 as the 1, 2 and 5 all have the same value at the same location. @param secretnumber the secret number the user is trying to guess @param guess the users guess at the secretnumber @return the number of digits in the guess that match the secretnumber public int foundinposition(string secretnumber, String guess) assertequals(1, m.foundinposition("12345", "99399")); assertequals(3, m.foundinposition("12345", "19395")); generatesecretnumber (provided in the starter project) This method and its full tests are given to you in the starter project. You won t need it until you implement the console version of the game. / Generates a 5 digit, valid secret number. A secret number is valid if it contains no duplicates and all five characters are digits '0'..'9' @return a valid secret number public String generatesecretnumber() // Implemented and tested for you! Tips/Hints: 1) The console game cannot allow more than 32 attempts to guess. At the point, the player loses. 2) Manipulation of the guess (the users input) is best done as a string (don t convert it to an int) 3) The user may enter anything as a guess such as what? as long as it does not affect the game or terminate the program. Count this is a try 4) report an error if the guess is not a length of 5. Do not count this as a try. 5) When the user enters the secret number (rather than -1), the program must check to make sure that is a valid 'secret' number: Five unique digits. 6) Some useful String methods: a. int length() how many characters in this String, returned as an integer b. char charat(int index) the character at the specified index into this String c. int indexof(string sub) returns the index of sub in this String or -1 if not found d. boolean contains(string other) return true if other is part of this String. e. boolean equals(string other) return true if other is exactly the same as this String. 7) Begin your game like this in a file Named MindNumberMain.java import java.util.scanner;

/ This program allows users to play a game like MasterMind. @author YOUR NAME public class MindNumberMain { public static void main(string[] args) { System.out.println("Enter the secret number as a 5 digit number"); System.out.println("where all digits are unique, or enter -1"); System.out.println("to have this program select the secret number."); MindNumber minnumfun = new MindNumber(); Scanner keyboard = new Scanner(System.in); Grading Criteria 100 pts max +70 Web-Cat correctness and method coverage. Your code must compile using the specified names, Rick's tests pass, and you have tested all of your methods with assertions in a test method. These 40 points are derived from Web-Cat. You may submit an unlimited number of times. The final submission will be the one that is graded. Notice that a multiplication feature is employed that means 90% problem coverage and 90% code coverage results in 0.9 0.9 = 0.81. 0.81 40 pts = 32.4 pts out of the maximum of 40. / +20 MindNumberMain.java is turned in with your project and has the code to run the game using standard IO. The dialog is very close (if not exactly the same) to what you see at the beginning of this document. It must use the three methods you implemented along with the given methods in MindNumber. +10 pts Style and Design: 1pt You named the program that runs the game MindNumberMain.java 2pts You added three methods to MindNumber.java 2pts You have your name as a comment at the top of the all files 3pts You used meaningful identifiers 2pts All code is formatted consistently (use Eclipse s Source > Format) Reasons you can get 0 on WebCat: You did not submit any tests. You need at least one file with the name Test at the end as in MindNumberTest.java and there must be @Test methods in that file One of your assertions does not pass when run on WebCat Our tests exposed a case where you have an infinite loop on WebCat. Look for Timeout errors on WebCat. Debug your code. Looks at all loops You have an incorrect method signature. Your tests run correctly on your machine, but Rick's reference tests on WebCat cannot find the expected method.