In this programming project you will practice:
You’re a bored Georgia Tech student without enough work to fill your days and you like word games, so you decide to make a word guessing game to pass the time.
Download WordGuess.java and complete the definition of the WordGuess
class so that it implements a simple word guessing game. WordGuess.java includes a skeleton main
method so that you can run the class as a console program. Fill in the rest of the main method – under the // Your code here:
line – with code that implements a console-based word guessing game.
Do not modify the code we give you.
'_'
, for letters which haven’t yet been guessed.'_'
characters for letters that weren’t guessed.Successful run with a couple of misses and a repeated letter:
$ java WordGuess
Missed letters (5 left):
Current guess: ___
Guess a letter: c
Missed letters (4 left): c
Current guess: ___
Guess a letter: a
Missed letters (4 left): c
Current guess: _a_
Guess a letter: t
Missed letters (3 left): ct
Current guess: _a_
Guess a letter: d
Missed letters: ct
Final guess: dad
Congratulations! You got it!
Unsuccessful run with a couple of hits:
$ java WordGuess
Missed letters (5 left):
Current guess: ___
Guess a letter: q
Missed letters (4 left): q
Current guess: ___
Guess a letter: w
Missed letters (3 left): qw
Current guess: ___
Guess a letter: e
Missed letters (2 left): qwe
Current guess: ___
Guess a letter: r
Missed letters (2 left): qwe
Current guess: r__
Guess a letter: t
Missed letters (2 left): qwe
Current guess: r_t
Guess a letter: y
Missed letters (1 left): qwey
Current guess: r_t
Guess a letter: u
Missed letters: qweyu
Final guess: r_t
Sorry, too many misses. The secret word was rat
System.in
to get the player’s input.java.util
make sense for this task, but we want you to practice using primitive features of Java.length
method, e.g., "cat".length()
returns 5
.StringBuilder
, e.g., StringBuilder sb = new StringBuilder()
, it’s empty.append
method to add a character to the String, e.g. sb.append('_')
.
'-'
characters?toString
method to get a printable String
with the current contents of the StringBuilder
.setCharAt
method to set the char
at a particular index of a StringBuilder
object, e.g., if you have a StringBuilder
sb
whose content is "___"
, then after sb.setCharAt(1, 'a')
its content is "_a_"
.StringBuilder
in JShell to get a feel for it.Scanner
method that returns a char
. You can use the next
method, which returns a String
and use String
s charAt
method to get a char
value. For example "a".charAt(0)
returns 'a'
.java WordGuess 0
the secret word will be "cat"
, if you run java WordGuess 1
the secret word will be "dad"
. You can use this feature to test your code. We will use this feature to auto-grade your code.Starting from this homework, you will need to write Javadoc comments and watch for checkstyle errors with your submission.
Every class should have a class level Javadoc that includes @author <GT Username>
.
Every public method should have a Javadoc explaining what the method does and includes any of the following tags if applicable:
@param <parameter name> <brief description of parameter>
@returns <brief description of what is returned>
@throws <Exception> <brief explanation of when the given exception is thrown>
See the CS 1331 Style Guide for details.
For each of your homwork assignments we will run checkstyle and deduct one point for every checkstyule error.
For this homework the checkstyle cap is 10, meaning you can lose up to 10 points on this assignment due to style errors. This limit will increase with each homework.
java -jar checkstyle-6.2.2.jar *.java
.java -jar checkstyle-6.2.2.jar -j *.java
.When completing homeworks for CS1331 you may talk with other students about:
_ What general strategies or algorithms you used to solve problems in the homeworks _ Parts of the homework specification you are unsure of and need more explanation _ Online resources that helped you find a solution _ Key course concepts and Java language features used in your solution _ You may not discuss, show, or share by other means the specifics of your code, including screenshots, file sharing, or showing someone else the code on your computer, or use code shared by others.
OKAY: “Hey, I’m really confused on how we are supposed to implement this part of the homework. What strategies/resources did you use to solve it?”
BY NO MEANS OKAY: “Hey… the homework is due in like 20 minutes… Can I see your code? I promise won’t copy it directly!”
In addition to the above rules, note that it is not allowed to upload your code to any sort of public repository. This could be considered an Honor Code violation, even if it is after the homework is due.
Submit your WordGuess.java
file as an attachment to the hw1
assignment on Canvas. You can submit as many times as you want, so feel free to submit as you make substantial progress on the homework. We only grade your last submission, meaning we will ignore any previous submissions.
As always, late submissions will not be accepted and non-compiling code will be given a score of 0. For this reason, we recommend submitting early and then confirming that you submitted ALL of the necessary files by re-downloading your file(s) and compiling/running them.
\(°□°)/