Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 12 of 12

Thread: question on list manipulation

  1. #1
    Junior Member
    Join Date
    Aug 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.......


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default 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.

  3. #3
    Junior Member
    Join Date
    Aug 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:

    /**
     * @(#)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:

    /**
     * @(#)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.....

  4. #4
    Junior Member
    Join Date
    Aug 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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:

    /**
     * @(#)MainGUI.java
     *
     *
     * @author
     * @version 1.00 2010/8/5
     */
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
     
    public class MainGUI extends JFrame {
     
    	private JTextField txtWordInput;
     
    	private JButton btnShuffle;
    	private JButton btnClear;
    	private JButton btnExit;
     
    	private JLabel Word;
     
    	private JPanel panel;
     
     
        public MainGUI() {
     
        GridBagConstraints c = new GridBagConstraints();
    	GridBagLayout gbl = new GridBagLayout();
     
        panel = new JPanel();
        panel.setLayout(gbl);
     
        txtWordInput = new JTextField(20);
     
        btnShuffle = new JButton("Shuffle");
        btnShuffle.addActionListener(new buttonHandler());
     
        btnClear = new JButton("Clear");
        btnShuffle.addActionListener(new buttonHandler());
     
        btnExit = new JButton("Exit");
        btnExit.addActionListener(new buttonHandler());
     
     
        }
     
        class ButtonHandler implements ActionListener {
        	public void actionPerformed(ActionEvent e) {
        	}
        }
     
     
    }

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: question on list manipulation

    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?

  6. #6
    Junior Member
    Join Date
    Aug 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: question on list manipulation

    Quote Originally Posted by Norm View Post
    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

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: question on list manipulation

    So do you have a problem or question?

  8. #8
    Junior Member
    Join Date
    Aug 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: question on list manipulation

    Quote Originally Posted by Norm View Post
    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?

  9. #9
    Junior Member
    Join Date
    Aug 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: question on list manipulation

    Quote Originally Posted by andrefaelnar View Post
    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?

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: question on list manipulation

    i have 3 errors
    Can you copy and paste the full text of the error messages here?

    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.

  11. #11
    Junior Member
    Join Date
    Aug 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: question on list manipulation

    Quote Originally Posted by Norm View Post
    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.

    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.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: question on list manipulation

    Where is the class buttonHandler defined?
    Java is case sensitive.

Similar Threads

  1. list in JSP
    By smackdown90 in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: November 13th, 2011, 01:08 PM
  2. String manipulation help
    By Duff in forum Loops & Control Statements
    Replies: 7
    Last Post: March 19th, 2010, 04:02 AM
  3. need help with a list class
    By araujo3rd in forum Object Oriented Programming
    Replies: 1
    Last Post: February 25th, 2010, 07:58 PM
  4. Which collection is best to do mathematical operation on it?
    By Sterzerkmode in forum Java Theory & Questions
    Replies: 1
    Last Post: May 7th, 2009, 04:48 AM
  5. Recursive function based on Linked list
    By rosh72851 in forum Collections and Generics
    Replies: 1
    Last Post: March 9th, 2009, 06:23 PM