question on list manipulation
hello im new here
and im having problems with this objective.....
here is the instruction.....
General Specification:
Create a game that asks for a player’s name and then shows scrambled letters. The objective
for the game is for the player to guess the unscrambled word. A user is given 2 minutes to guess the
word and the user is given points in the following manner.
• 100 points: if the player guessed the word in the 1st minute.
• 50 points: if the player guessed the word within the succeeding minute.
The player has the option to keep scrambling the letters of the word to be unscrambled
either by clicking the button on the game’s interface or by pressing the spacebar of the keyboard.
This game ends when the player was not able to guess the word within the allowable time or if the
user was able to guess all the words in this game’s list of words to be guessed.
Name and score of the player is shown in the game’s interface if the player beats the current
highest score (the game’s highest score and scorer are shown with 0 and blank, respectively when
the game is first executed).
Detailed Specification:
o The program must read a text file containing 100 words with the following information for
each of the words:
The word (comprising 5 to 7 letters)
The classification of the word: noun, verb, or adjective
Definition of the word
Note: Just choose one classification/definition for the word if it has more than 1
definition.
o You are to use an ArrayList object to store the words read from the file.
o When running the program, the program must jumble all the 100 words before showing the
first word to be guessed. Note also that the jumbled letters of the word are shown to the
player.
o Your game’s interface should provide for the jumbling the letters of the word being guessed
through a button or by pressing the space bar.
o The time remaining for the player to guess must also be shown (starting with 2 minutes
[2:00]).
o When the first minute has elapsed and the player has not yet guessed the word, the word’s
classification (noun, verb, or adjective) is shown together with the definition of the word to
serve as a hint.
o Be creative in creating your game’s interface.
o Make sure that your project’s game interface (GUI) shall utilize a logic class that has the
direct access to the text file.
how do u use the Timer class for this activity?
if im in the wrong thread.....
jst tell me where should i place this thread to ok?.......
ur help is most appreciated......
thanks.......
Re: question on list manipulation
Show us what you've done so far (i.e. code), as well as give us some insight into your thought process for solving this problem.
Re: question on list manipulation
they say that you could pattern with this other problem..........
Consider the uml diagram below........
--------------------------------------
for Word:
------------------------------------------
-text:String
-charList:List<Character>
-shuffled;String
-------------------------------------------
+ Word(str:String)
- getChars():Arraylist<Character>
+shuffle():void
- listToString()String
+toString():String
+getShuffleedText():String
--------------------------------------------
*Definition of the diagram above has already been provided (Word.java)
-Study the code and give special attention how the shuffle method has been implemented.
-something to think about: What's the advantage of using the ArrayList as against a regular character array?
*Other than Word.java, another tester file is provided (Tester.java) with the sole purpose ofof trying the code for Word.java. You may run this program and make your own testing using this file.
Requirement:
1. Create a GUI class that Word class provided with the following functionalities:
*Entering a text:
-Display an input dialog box where the user can input the word the user wants to enter.
-When the input is successful, display the word on the main window(the componentmust be restricted from modification/s from the user).
-if the input is invalid(text enteredis less than 3 letters in length), another dialog box must be shown informing the user that the input is invalid. (Check the constructor for Word.java)
*shuffling the text displayed
-The component that allows the user to do this functionality should only be activated if a word is already displayed.
here is the code for Word.java:
Code java:
/**
* @(#)Word.java
*
*
* @author
* @version 1.00 2010/8/4
*/
import java.util.*;
public class Word {
private String text;
private List<Character> charList;
private String shuffled;
public Word(String str) {
if (str.length() < 3) {
throw new RuntimeException("Word must be more than 2 characters...");
}
text = str.toUpperCase();
charList = getChars();
shuffle();
}
private ArrayList<Character> getChars() {
ArrayList<Character> tempList = new ArrayList<Character>();
for (int i = 0; i < text.length(); i++) {
tempList.add(text.charAt(i));
}
return tempList;
}
public void shuffle() {
String orig = shuffled;
String tempShuffled;
do {
Collections.shuffle(charList);
tempShuffled = listToString();
} while (tempShuffled.equals(orig) || tempShuffled.equals(text));
shuffled = tempShuffled;
}
private String listToString() {
String strTemp = "";
for (Character ch: charList) {
strTemp += ch;
}
return strTemp;
}
public String toString() {
return text;
}
public String getShuffledText() {
return shuffled;
}
}
and here's the code for Tester.java:
Code java:
/**
* @(#)Tester.java
*
*
* @author
* @version 1.00 2010/8/4
*/
public class Tester {
public static void main(String[] args) {
divider();
Word w = new Word("caterpillar");
System.out.println("word is: " + w);
System.out.println("Succeeding lines are calls to shuffling the letters of the word:");
System.out.println(w.getShuffledText());
w.shuffle();
System.out.println(w.getShuffledText());
w.shuffle();
System.out.println(w.getShuffledText());
w.shuffle();
System.out.println(w.getShuffledText());
w.shuffle();
System.out.println(w.getShuffledText());
w.shuffle();
System.out.println(w.getShuffledText());
w.shuffle();
System.out.println(w.getShuffledText());
divider();
// further testing below (eg. what if the assigned word to w is less than 2 in length such as "to")
w = new Word("to");
}
private static void divider() {
System.out.println("============================");
}
}
i'll try to upload the GUI class that goes with the Word.java and Tester.java soon........
i think what they are trying to do is try to make up of some sort of a text twist type of game in my first post.
this post is just a simple GUI class that allows the user to input a word and place on a table and once a word was placed on the GUI class, that's the time when the user can shuffle the letters of the given word.
but the first that i placed, is similar but they added a timer class and insteas is more of like a similarity to text twist or something. or its like guessing the word.
but like i said i'll try to get the GUI class that goes with the Word.java and Tester.java so i'll know what to do next.....
Re: question on list manipulation
ok im back.......
sorry i was busy.....
anyways, here is the gui.class that relates to word.java and tester.java
its incomplete and i had 3 errors......
i wonder whats missing in order to make this program work?......
yuor help is most appreciated...
thanks...
here's the gui code:
Re: question on list manipulation
Quote:
i wonder whats missing in order to make this program work?
There isn't any code in the actionPerformed method.
What is the program supposed to do when a button is pressed?
Re: question on list manipulation
Quote:
Originally Posted by
Norm
There isn't any code in the actionPerformed method.
What is the program supposed to do when a button is pressed?
well there are three buttons that should appear in the gui
the first button does the shuffling of the current word
but you could only shuffle it after you enter a word
the second button clears the current word you entered
and the third button exits the program itself
Re: question on list manipulation
So do you have a problem or question?
Re: question on list manipulation
Quote:
Originally Posted by
Norm
So do you have a problem or question?
i have the idea but it just didnt come together.......
i couldnt make the gui work cos i have 3 errors.....
i'll try to place in in this forum
What's Wrong With My Code?
Re: question on list manipulation
Quote:
Originally Posted by
andrefaelnar
i have the idea but it just didnt come together.......
i couldnt make the gui work cos i have 3 errors.....
i'll try to place in in this forum
What's Wrong With My Code?
but the question i wanted to ask is how do you use the timer class?
Re: question on list manipulation
Can you copy and paste the full text of the error messages here?
Quote:
how do you use the timer class
If you read the API doc for javax.swing.Timer class, there are two links to Tutorials about how to use timers. The tutorial has examples on how to use timers.
Re: question on list manipulation
Quote:
Originally Posted by
Norm
Can you copy and paste the full text of the error messages here?
If you read the API doc for javax.swing.Timer class, there are two links to Tutorials about how to use timers. The tutorial has examples on how to use timers.
Code java:
H:\IT2072227\IT211\Lab_Activities\MainGUI.java:37: cannot find symbol
symbol : class buttonHandler
location: class MainGUI
btnShuffle.addActionListener(new buttonHandler());
^
H:\IT2072227\IT211\Lab_Activities\MainGUI.java:40: cannot find symbol
symbol : class buttonHandler
location: class MainGUI
btnShuffle.addActionListener(new buttonHandler());
^
H:\IT2072227\IT211\Lab_Activities\MainGUI.java:43: cannot find symbol
symbol : class buttonHandler
location: class MainGUI
btnExit.addActionListener(new buttonHandler());
^
3 errors
Process completed.
Re: question on list manipulation
Where is the class buttonHandler defined?
Java is case sensitive.