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 5 of 5

Thread: i need help for this program.....

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

    Default i need help for this program.....

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

    but 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("============================");
        }
    }

    and here's what's wrong with my code

    its about the gui class that should go along with word.java and tester.java.....

    if u know and corrections or solutions to complete this program
    just let me know ok?

    anyways here is my unfinished 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) {
            }
        }
     
     
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,320
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: i need help for this program.....

    Do you have some questions about how to complete your code?

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

    Default Re: i need help for this program.....

    Quote Originally Posted by Norm View Post
    Do you have some questions about how to complete your code?
    the question is how to place the timer class cos i dont know where to insert the timer class somewhere in my gui code also how to count and keep on track on the points since im making a game that is related to text twist.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,320
    Thanks
    56
    Thanked 2,374 Times in 2,345 Posts

    Default Re: i need help for this program.....

    how to place the timer class
    One use appears to be to update the count down timer display. Every second the Timer's actionPerformed method should be called and have it update the time display by decrementing it by one second.

    To test how the Timer class works, write a small test program that prints out a line every second for 10 seconds. When you get it to work, move the logic into the large program.

  5. #5
    Member
    Join Date
    May 2010
    Posts
    36
    Thanks
    0
    Thanked 13 Times in 12 Posts

    Default Re: i need help for this program.....

    Quote Originally Posted by andrefaelnar View Post
    the question is how to place the timer class
    i wrote a countdown class the take a jlabel as argument in its constructor and displays the time in the jlabel. here is the code

    import java.util.Timer;
    import java.util.TimerTask;
     
    import javax.swing.JLabel;
     
    public class CountDown {
     
    	private int count = 120;
    	private JLabel timeLabel;
     
    	public CountDown(JLabel label) {
     
    		timeLabel = label;
    		Timer timer = new Timer();
     
    		TimerTask task = new TimerTask() {
    			public void run() {
    				timeLabel.setText("Remaining time: " + count / 60 + ":" + count	% 60);
    				if (count > 0)
    					count--;
     
    				if (count == 0)
    					System.exit(0);
    			}
    		};
     
    		timer.schedule(task, 0, 1000);
    	}
    }


    now, add the JLabel in your MainGUI and as soon the user presses the button "Start" instantiate the CountDown class and pass your JLabel to the constructor which will be updates each second. as soon the count reach 0 a System.exit(0) is executed. change this behaviour to inform the games that the time has elapsed.