There is a problem which is requiring me to write a program which is a reversed
ID: 3638370 • Letter: T
Question
There is a problem which is requiring me to write a program which is a reversed Hangman. I give the word to the computer and it will guess the word. I am new to programming so it can not be really complicating.should look like this.
CS&141 – Lab #5
Programming Projects – Page 372 – 2.
Write a reverse Hangman game in which the user thinks of a word and the computer tries to guess the letters in that word. The user tells the computer how many letters the word contains.
Limit your program to a maximum of 6 guesses. Use a random number generator to generate the guesses. Use the following code to generate your letter guesses randomly:
// picks a letter at random that we haven't yet guessed
public static char getGuess(String guesses) {
Random r = new Random();
char guess;
do {
guess = (char)('A' + r.nextInt(26));
} while (guesses.indexOf(guess) != -1);
return guess;
}
Your program should be stored in a file called ReverseHangman.java.
Log of execution (user input underlined)
This program plays a game of reverse hangman.
You think up a word and I'll try to guess
the letters.
How many letters are in your word? 2
+--+
| |
|
|
|
|
+-----
I've got 0 of the 2 letters so far
I guess Q
Is that letter in the word? n
+--+
| |
| O
|
|
|
+-----
I've got 0 of the 2 letters so far
I guess O
Is that letter in the word? n
+--+
| |
| O
| |
|
|
+-----
I've got 0 of the 2 letters so far
I guess B
Is that letter in the word? n
+--+
| |
| O
| |
|
|
+-----
I've got 0 of the 2 letters so far
I guess T
Is that letter in the word? n
+--+
| |
| O
| |
| /
|
+-----
I've got 0 of the 2 letters so far
I guess X
Is that letter in the word? n
+--+
| |
| O
| |
| /
|
+-----
I've got 0 of the 2 letters so far
I guess H
Is that letter in the word? n
+--+
| |
| O
| /|
| /
|
+-----
I've got 0 of the 2 letters so far
I guess G
Is that letter in the word? n
+--+
| |
| O
| /|
| /
|
+-----
You beat me this time.
any ideas?
Explanation / Answer
import java.net.*; import java.io.*; import java.lang.reflect.*; public class MyLoader2 { public static void main (String argv[]) throws Exception { URLClassLoader loader = new URLClassLoader(new URL[] { new URL("http://www.javacourses.com/classes/") }); // Load class from class loader. argv[0] is the name of the class to be loaded Class c = loader.loadClass (argv[0]); Method m = c.getMethod("main", new Class[] {argv.getClass() }); m.setAccessible(true); int mods = m.getModifiers(); if(m.getReturnType() != void.class || !Modifier.isStatic(mods) || !Modifier.isPublic(mods)) { throw new NoSuchMethodException("main"); } try { m.invoke(null, new Object[] { argv }); } catch(IllegalAccessException e) { } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.