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

Thread: Word Scramble Using Objects & Methods

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Word Scramble Using Objects & Methods

    Alright, I'm not looking for an EXACT solution (Unless you seriously want to give the time to help me out that much) I'm just looking for where I should start and maybe a really nice detailed algorithm.

    I've got an assignment to create a Word Jumble game played between two players. I've got some fairly specific guidelines I need to follow which I will post:

    PROBLEM

    For this assignment you are to create a simple word guessing game for two players. For each round in the game the following sequence is followed:

    first player enters a word to be guessed
    the program rearranges the letters in the word and displays to the second player
    the second player has 5 attempts to guess the word correctly

    second player enters a word to be guessed
    the program rearranges the letters in the word and displays to the first player
    the first player has 5 attempts to guess the word correctly

    The scoring for the game is as follows:
    100 points if guessed on first try
    80 points if guessed on second try
    60 points if guessed on third try
    40 points if guessed on fourth try
    20 points if guessed on fifth try

    The players have the option to play as many rounds as they would like. The game is over when players select “quit program” from the menu.

    The program will automatically play the first round. After that a menu will appear to allow the players the option of displaying their score, playing another round, ending the game or quitting the program immediately. The menu will appear as follows:

    Please select from one of the following options:
    p - play another round
    s - display current score
    e - end game and display final score
    q - quit program


    CLASSES

    For this problem you are required to create specific classes and methods. The following classes and methods are required.

    Player Class
    This class maintains information about a player. It has two private attributes, name and score. The following methods are required for this class:

    Player( name : String ) Constructor which creates a new instance with name specified.

    increaseScore( amount : int ) Method which adds the specified amount to the player’s score.

    resetScore( ) Method resets player’s score to zero

    getName() Accessor method which returns player’s name

    displayScoreDetails() Method which displays the player’s name and score to console output in the form “name: score”.

    findWinner( player1 : Player, player2 : Player ) This static method accepts two Player instances and determines which of the players has the higher score. The method returns the Player instance of the player with the highest score. If the players are tied this method returns null as there is no winner.

    Word Class
    This class maintains information about a word. It has one private attribute, word. The following methods are required:

    Word( word : String ) Constructor accepting word to use.

    Word() Constructor which uses the default word of “popcorn”. Use constructor chaining.

    getWord() This method returns the word.

    getJumbledWord() This method returns the word with the letters mixed up. This method must mix up the letters by taking the original word and performing ten letter swaps. This method should have a loop that loops ten times. Each time through the loop randomly pick two letters and swap their positions in the word.
    doesWordMatch( otherWord : String ) This method compares the provided word to its word. If the word is an exact match it will return true otherwise it returns false. Note: case is irrelevant so make sure the case is ignored.

    Jumble Class

    This is the class that plays the game. It makes use of the Player and Word classes. It has three private attributes, player1, player2 and input. The input attribute represents the Scanner instance and is used for getting input from the user. The following methods are required for this class:

    main( args : String[] ) Main entry point for the Java application. This method should instantiate the Jumble class and call the playGame method.

    Jumble() Constructor. Displays welcome message and creates two new player instances. Use the getPlayerName method to get the two player names.

    getPlayerName() This method gets the user to enter a player name. Make sure the player name is at least one character long.

    getPlayerGuess( word : Word, player : Player ) This method is responsible for getting a player’s guess for a word. This method should do the following:
    - clear the screen by displaying 25 blank lines
    - use a loop to allow the player up to five guesses
    - ask the player for their guess
    - if the guess is correct, add appropriate amount to player’s score. Amount to add is based on which guess it is. First guess is 100 points, second is 80, third is 60, fourth is 40 and fifth is 20. If the player does not guess within five guesses, the player scores nothing.
    playGame() This method handles the main loop for playing the game. The loop should loop while the user wants to keep running the program. The first time through the loop, the first round should automatically be played. Within this loop do the appropriate action based on the choice selected by the user. The choices are:
    - play a round. Each player gets to provide one word that the other player then guesses. Ask each player to enter a word and use the getPlayerGuess method for having the other player guess the word.
    - display the current score for each player. Use the displayScoreDetails method in the Player class.
    - end the game and display the final score for each player, including indicating who won the game. Call the displayWinner method in the Jumble class.
    - quit the program. Terminate the program. No scores are displayed, and no indication is given of who won the game.
    Use the getMenuChoice method to display the menu and get the user choice.

    displayWinner() Use the findWinner method in the Player class to determine who is the winner. Use the displayScoreDetails to display the final score for each player. Reset the scores for each player.

    getMenuChoice() This method should display the menu and get the user choice. Make sure the input is validated.


  2. #2
    Junior Member
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Word Scramble Using Objects & Methods

    Also, here is some sample output for the program:
    Welcome to Jumble - the mixed up word guessing game
    Enter player name
    Sharon
    Enter player name
    Shane
    Sharon enter a word. Shane no peeking!
    stale

    Shane the jumbled word is etasl
    Enter your guess:
    least

    Sorry, that is not the word.
    Please guess again. Jumbled word is etasl
    Enter your guess:
    slate

    Sorry, that is not the word.
    Please guess again. Jumbled word is etasl
    Enter your guess:
    stale

    Congratulations you got it! 60 was added to your score.

    Shane enter a word. Sharon no peeking!
    grate

    Sharon the jumbled word is arget
    Enter your guess:
    great

    Sorry, that is not the word.
    Please guess again. Jumbled word is arget
    Enter your guess:
    grate

    Congratulations you got it! 80 was added to your score.

    Please select from one of the following options:
    p - play another round
    s - display current score
    e - end game and display final score
    q - quit program
    s
    Current Score:
    Sharon: 80
    Shane: 60

    Please select from one of the following options:
    p - play another round
    s - display current score
    e - end game and display final score
    q - quit program
    p
    Sharon enter a word. Shane no peeking!
    skates

    Shane the jumbled word is atskes
    Enter your guess:
    steaks

    Sorry, that is not the word.
    Please guess again. Jumbled word is atskes
    Enter your guess:
    skates

    Congratulations you got it! 80 was added to your score.

    Shane enter a word. Sharon no peeking!
    lodge

    Sharon the jumbled word is egold
    Enter your guess:
    lodge

    Congratulations you got it! 100 was added to your score.

    Please select from one of the following options:
    p - play another round
    s - display current score
    e - end game and display final score
    q - quit program
    e
    Congratualtions Sharon you win!
    Final Score:
    Sharon: 180
    Shane: 140

    Please select from one of the following options:
    p - play another round
    s - display current score
    e - end game and display final score
    q - quit program
    s
    Current Score:
    Sharon: 0
    Shane: 0

    Please select from one of the following options:
    p - play another round
    s - display current score
    e - end game and display final score
    q - quit program
    p
    Sharon enter a word. Shane no peeking!
    popcorn

    Shane the jumbled word is noocprp
    Enter your guess:
    popcorn

    Congratulations you got it! 100 was added to your score.

    Shane enter a word. Sharon no peeking!
    synthesis

    Sharon the jumbled word is hitsssyne
    Enter your guess:
    hiss

    Sorry, that is not the word.
    Please guess again. Jumbled word is hitsssyne
    Enter your guess:
    stein

    Sorry, that is not the word.
    Please guess again. Jumbled word is hitsssyne
    Enter your guess:
    snitty

    Sorry, that is not the word.
    Please guess again. Jumbled word is hitsssyne
    Enter your guess:
    justfooling

    Sorry, that is not the word.
    Please guess again. Jumbled word is hitsssyne
    Enter your guess:
    noguessthistime

    Sorry, that is not the word.
    Round over. You scored 0

    Please select from one of the following options:
    p - play another round
    s - display current score
    e - end game and display final score
    q - quit program
    s
    Current Score:
    Sharon: 0
    Shane: 100

    Please select from one of the following options:
    p - play another round
    s - display current score
    e - end game and display final score
    q - quit program
    e
    Congratualtions Shane you win!
    Final Score:
    Sharon: 0
    Shane: 100

    Please select from one of the following options:
    p - play another round
    s - display current score
    e - end game and display final score
    q - quit program
    q
    Last edited by helloworld922; December 10th, 2009 at 02:14 AM.

  3. #3
    Junior Member
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Word Scramble Using Objects & Methods

    Problem Solved!

  4. #4
    Junior Member
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Word Scramble Using Objects & Methods

    I am actually doing this for my notes since I was absent from CS class, but I don't know how to do it, so could you share the code or help me out?

Similar Threads

  1. Working with Methods
    By duckman in forum Object Oriented Programming
    Replies: 3
    Last Post: November 9th, 2009, 08:27 PM
  2. User Defined Methods
    By mgutierrez19 in forum Object Oriented Programming
    Replies: 11
    Last Post: October 20th, 2009, 06:57 PM
  3. Novice with java methods, please help!
    By raidcomputer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 14th, 2009, 04:23 AM
  4. How to invert a word String
    By Truffy in forum Java Programming Tutorials
    Replies: 16
    Last Post: October 3rd, 2009, 02:44 AM
  5. numerical conversion methods..
    By chronoz13 in forum Java SE APIs
    Replies: 12
    Last Post: September 27th, 2009, 04:29 AM