Executable Class CincoGuesser Class CincoGuesser & Class Dictionary Oh, please b
ID: 3759033 • Letter: E
Question
Executable Class CincoGuesser
Class CincoGuesser & Class Dictionary
Oh, please be sure to use the starter code. and there is help from other tutors with their ideas, they didn't quite finish up with the project different errors or incomplete.. i commented the link with the Dictionary class... it was just pasted twice there is no cincoguesser and with the other code i'm getting a compiling errors on Scanner = new Scanner (system.in) symbol error on Scanner and new Scanner
Make sure to save time to test your program, some of these functions will be tricky to code! Program Description In this program, you will be creating a word guessing game called Cinco, except that in your program the computer will guess the words, not a human player! In this game, the human will pick a (legal) secret five letter word from the list of legal secret words. The computer guesses a word. A word is only a legal guess if it appears in the Dictionary.
A word is a legal secret word only if it appears in the Dictionary and does not have a repeated letter. A word list of about 2400 five letter words is provided1 (click this link to get the word list). Note, that the program can be run with different length word lists. I suggest making your own (very short) word lists to greatly simplfy your initial testing! The file will always consist of five-letter words, one per line, all in lowercase and in alphabetical order. Your program will always read its word list from a file named cinco-words.txt. Each round, the computer guesses a word from its list of words.
After the computer guesses, the human enters the number of letters in the guess that also exist in the secret word and how many of those letters are in the correct spot. If the score is five and five, then the computer has guessed your secret word and the game ends, printing out how many guesses it took the computer to win. If the socre is less than five and five, the computer will update its Dictionary (by removing one or more words from its word list) and then makes its next guess.
If the computer runs out of words to guess, it will inform the player that they must have made a mistake or cheated. Some sample runs are provided below. Any letter in your secret word should only be matched once. For example, Your secret word: fable Computer's guessed word: eagle results in Matching: 3 In-Place: 3 and not Matching: 4 In-Place: 3 This program should be constructed using two classes. One class, named Dictionary, will take care of inputting and storing the words from a file, selecting a random word from the list (for each guessed word by the computer,) and removing one or more words from the list after the computer's guess (this is the hardest part of the assignment.)
It should also include one or more helper functions since removing words from the list involves several steps. Secret words must have five different letters. For example, eagle is a valid guess, but not a valid secret word. The other class, named CincoGuesser, will keep track of the game state, handle the user input and output, and contain the main function. The main game loop (which will include all human i/o over STDIN and STDOUT) must be in a function named consoleUI().
A required main() function for the CincoGuesser class is provided. Review the starter code for more information about these classes and members. Your output must match the style and formatting of the example, as the testing may be automated. This is a program with many details. I strongly urge you to keep your program compiling and running at all stages of your project. Keep all your functions simple at first—the minimum to compile and run. Add code to one function at a time and test as you code.
Provided starter code ::
Sample Execution::
This should be everything, just two things to compile CincoGuesser.java & Dictionary.java
Should include main function, also this teacher is really strict so anything that is NOT coherent with the program basics ie: number input or less than or more than 5 letter guesses would need to be accounted for. So file exception errors etc... Thanks
Also, the text of the file is supposed to be called cinco-words.txt but it can be any list of five letter words, it isn't dependent on the words the text should be interchangeable with any five letter word list.Thanks!!
it's a first real programming java course so please nothing over the top just what you'd take out of a Java Programming textbook... thank you so much!!!! Cheers
Explanation / Answer
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Random;
public class Dictionary
{
int DictionarySize=100;
public Dictionary(String filename) throws IOException
{
numwords=0;
words= new String[DictionarySize];
File file = new File(filename);
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null)
{
words[numwords]=line;
numwords++;
}
}
public String getRandomWord()
{
Random rn = new Random();
int rNum = rn.nextInt(numwords)%numwords;
return words[rNum];
}
public void removeWords(String word, int matching, int inplace)
{
int i;
if(matching==5 && inplace==5)
{
}
else
{
for(i=0;i<numwords;i++)
{
if(words[i]==word)
break;
}
for(int j=i;j<numwords-1;j++)
{
words[j]=words[j+1];
}
numwords--;
}
}
public int countMatching(String firstWord, String secondWord)
{
int matchings=0;
for(int i=0;i<firstWord.length();i++)
{
for(int j=0;j<secondWord.length();j++)
{
if(firstWord.charAt(i)==secondWord.charAt(j))
{
matchings++;
}
}
}
return matchings;
}
public int countInPlace(String firstWord, String secondWord)
{
int inPlace=0;
for(int i=0;i<secondWord.length();i++)
{
if(firstWord.charAt(i)==secondWord.charAt(i))
{
inPlace++;
}
}
return inPlace;
}
private String [] words;
private int numwords;
{
return numwords;
}
}
CincoGuesser
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Random;
public class CincoGuesser
{
public static void main(String [] args)
{
CincoGuesser c = new CincoGuesser();
c.play();
}
int DictionarySize=100;
public CincoGuesser(String filename) throws IOException
{
numwords=0;
words= new String[DictionarySize];
File file = new File(filename);
FileReader fileReader = new FileReader(file);
BufferedReader bufferedReader = new BufferedReader(fileReader);
StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = bufferedReader.readLine()) != null)
{
words[numwords]=line;
numwords++;
}
}
public String getRandomWord()
{
Random rn = new Random();
int rNum = rn.nextInt(numwords)%numwords;
return words[rNum];
}
public void removeWords(String word, int matching, int inplace)
{
int i;
if(matching==5 && inplace==5)
{
}
else
{
for(i=0;i<numwords;i++)
{
if(words[i]==word)
break;
}
for(int j=i;j<numwords-1;j++)
{
words[j]=words[j+1];
}
numwords--;
}
}
public int countMatching(String firstWord, String secondWord)
{
int matchings=0;
for(int i=0;i<firstWord.length();i++)
{
for(int j=0;j<secondWord.length();j++)
{
if(firstWord.charAt(i)==secondWord.charAt(j))
{
matchings++;
}
}
}
return matchings;
}
public int countInPlace(String firstWord, String secondWord)
{
int inPlace=0;
for(int i=0;i<secondWord.length();i++)
{
if(firstWord.charAt(i)==secondWord.charAt(i))
{
inPlace++;
}
}
return inPlace;
}
private String [] words;
private int numwords;
public int noWords()
{
return numwords;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.