8 Replies - 381 Views - Last Post: 06 December 2012 - 09:41 PM Rate Topic: -----

#1 ess1223  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-December 12

I keep getting the error message "reached end of file while parsin

Posted 06 December 2012 - 06:00 PM

I am working on a Hangman project, the directions for which I have attached. Attached File  assignment_4.doc (24.5K)
Number of downloads: 21

My partner and I have been working together through e-mail correspondence to complete the assignment, but I have encountered an error message that I cannot seem to bypass.
When I try to compile the code, it keeps saying "reached end of file while parsing". I have tried to do as it says to correct it, but the message still remains. Does that mean there is something wrong in the code that is doing that? If so, what should I do to correct it?


import java.util.Random;
import java.util.Scanner;
import java.util.*; 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Hangman4 {
public static void main( String[] args ) {
    HangmanSession hangmanSession = new HangmanSession();
    hangmanSession.play();
  }
}

class HangmanSession {
  private Player player;
  private HiddenKeyword hiddenKeyword;
  private LetterBox letterBox;
  private int triesNumber = 7;
  
  public HangmanSession() {
    hiddenKeyword = new HiddenKeyword();
    letterBox = new LetterBox();
  }

  private void printState() {
    letterBox.print();
    System.out.print( "Hidden word : " );
    hiddenKeyword.print();
    System.out.print( "Tries left: " + triesNumber + "\n<guess letter:>" );
  }

  public void play() {
    boolean bool = true;
    while( true ) {
      bool = true;
      printState();
      char ch = player.takeGuess();
      if( letterBox.contains( ch ) ) {
        System.out.println( "Try again, you've already used that letter " + ch );
        bool = false;
      }
      if( bool ) {
        if( hiddenKeyword.guess( ch ) ) {
          System.out.println( "YAY! you have found letter! " + ch );
        }
        else {
          triesNumber--;
        }
        if( triesNumber < 1 )
          gameOver();

        if( hiddenKeyword.found() )
          congratulations();
      }
    } //end of bool
  }

  public void congratulations() {
    System.out.println( "Congratulations " + player + ", you win!" );
    System.exit( 0 );
  }

  public void gameOver() {
    System.out.println( "Sorry " + player + ", you lost, but you can try again!" );
    System.exit( 0 );
  }
}

class HiddenKeyword {
  private String fValue;
  private StringBuffer pValue;
  private int lfoundNumber = 0;

  public String words() {
        Random r = new Random();
        int random = r.nextInt(20)+1;
    }
    
public boolean found() {
    System.out.println( "Letters found:" + lfoundNumber + "/" + fValue.length() );
    return ( lfoundNumber == fValue.length() );
  }
      
public boolean guess( char c ) {
    int index = fValue.indexOf( c );
    if( index == -1 )
      return false;
    else {
      lfoundNumber = lfoundNumber + findOccurances( c );
      return true;
    }
  }
  
  private int findOccurances( char c ) {
    int idx = fValue.indexOf( c );
    pValue.setCharAt( idx, fValue.charAt( idx ) );
    int counter = 1;
    while( idx != -1 ) {
      int idxx = fValue.indexOf( c, idx + 1 );
      idx = idxx;
      if( idx != -1 ) {
        counter++;
        pValue.setCharAt( idx, fValue.charAt( idx ) );
      }
    }
    return counter;
  }

  public void print() {
    System.out.println( pValue );
  }



class LetterBox {
  private char[] lbox = new char[24];
  private int counter = 0;

  public boolean contains( char c ) {
    for( int i = 0; i < counter; i++ ) {
      if( lbox[i] == c )
        return true;
    }
    lbox[counter] = c;
    counter++;
    return false;
  }

  public void print() {
    System.out.print( "\nLetterBox:" );
    for( int i = 0; i < counter; i++ ) {
      System.out.print( lbox[i] );
    }
    System.out.println( "" );
  }
}

 public class hiddenWords  {
    public static void main(String[] args) {
    int words = 20;String wordsString;
 switch(random) {
            case 1:
            return "star";

            case 2:
            return "hooray";

            case 3:
            return "dog";

            case 4:
            return "improvise";

            case 5: 
            return "teacher";
            
            case 6:
            return "college";
            
            case 7:
            return "seahawks";
            
            case 8:
            return "read";
            
            case 9:
            return "computer";
            
            case 10:
            return "program";
            
            case 11:
            return "holiday";
            
            case 12:
            return "film";
            
            case 13:
            return "music";
            
            case 14:
            return "learn";
            
            case 15: 
            return "library";
            
            case 16:
            return "waterfall";
            
            case 17:
            return "book";
            
            case 18:
            return "semester";
            
            case 19:
            return "first";
            
            case 20:
            return "vacation";

            default:
            return"";
        }

    }

    public static void main(String[] args) {
        Hangman4 h = new Hangman4();
        Scanner input = new Scanner (System.in);
        String play = h.words();

        int incorrectGuesses = 7; 
        String playAgain;
        System.out.println("Welcome to Hangman!");
        do{
            System.out.println("Please enter a letter:");
            for (int c = 7; incorrectGuesses > c; incorrectGuesses--) {
            }
            String userInput = input.next();
            char Guess = userInput.charAt(0);

            char[] playArray = play.toCharArray();
            char [] guessplay = new char[playArray.length];

            for(int k=0;k<guessplay.length;k++){
                guessplay[k] = '_';
            }
            int counter = 0;

        while( counter < play.length() ){
            counter++;

            System.out.print("_ ");

        }


            int charCount = play.length();
            boolean d = false;
            for(int i = 0; i < play.length(); i++) {

                char ch = play.charAt(i);
                if(ch == (Guess)){
                    System.out.println("Correct!");
                    d = true;
                }
            }
            if( d == false){
                System.out.println("Nope.You have" + " " +incorrectGuesses + " " + "incorrect guesses left.");
            }

            if(incorrectGuesses == 0){
                System.out.println("Hangman. Game Over.");

                Guess++;
            }

        }while(incorrectGuesses > 0);
    }
}

//System.out.println(h.words());
if( d == false){
System.out.println("Nope.You have" + " " +incorrectGuesses + " " + "incorrect guesses left.");
}
else {
if(incorrectGuesses == 1){
System.out.println("Hangman. Game Over.");

Guess++;
}
}

System.out.println("\nDo you want to keep playing (Y/N): " );
playAgain = input.next();

while (playAgain.equalsIgnoreCase("Y"));{
System.out.println("\nGame over. Thank you for playing.\n\n" );

else(new Hangman4()); 
}
Random random = new Random();
for (int count = 0; count < 19; count++)
Word= random.nextInt(words.length);

String input = Word;

Scanner user_input= new Scanner(System.in);

String User_Guess;
System.out.println("Guess a letter.");
User_Guess = user.input.next();

Console.WriteLine(Char.Parse(User_Guess));

if Character.isLetter(a, b, c, d, e, f, g, h, i , j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z,); 
{
System.out.println("Correct!");

else {
System.out.println("Sorry");
}



Is This A Good Question/Topic? 0
  • +

Replies To: I keep getting the error message "reached end of file while parsin

#2 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: I keep getting the error message "reached end of file while parsin

Posted 06 December 2012 - 06:19 PM

Line number of error?
Was This Post Helpful? 1
  • +
  • -

#3 ess1223  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-December 12

Re: I keep getting the error message "reached end of file while parsin

Posted 06 December 2012 - 06:45 PM

The last one.

The last line.
Was This Post Helpful? 0
  • +
  • -

#4 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 292
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: I keep getting the error message "reached end of file while parsin

Posted 06 December 2012 - 06:59 PM

Well, you gotta close your class =)

This post has been edited by Luckless: 06 December 2012 - 06:59 PM

Was This Post Helpful? 1
  • +
  • -

#5 ess1223  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-December 12

Re: I keep getting the error message "reached end of file while parsin

Posted 06 December 2012 - 07:03 PM

Don't I just do that with a bracket?
Was This Post Helpful? 0
  • +
  • -

#6 nunc  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 131
  • Joined: 20-November 11

Re: I keep getting the error message "reached end of file while parsin

Posted 06 December 2012 - 07:05 PM

Always put a bracket at the end of your class when you get that area because it usually fixes the problem. Make sure you format your code too as it makes identifying this problem easier.
Was This Post Helpful? 1
  • +
  • -

#7 ess1223  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-December 12

Re: I keep getting the error message "reached end of file while parsin

Posted 06 December 2012 - 07:10 PM

Okay, thank you. I have corrected that problem, but now it is saying that class,interface, or enum expected (referring to line 59)
Was This Post Helpful? 0
  • +
  • -

#8 nunc  Icon User is offline

  • D.I.C Head

Reputation: 36
  • View blog
  • Posts: 131
  • Joined: 20-November 11

Re: I keep getting the error message "reached end of file while parsin

Posted 06 December 2012 - 07:22 PM

You have two main methods, one on line 140 and one on line 209. I don't know quite what you're doing there. I also can't make sense of any of your code after line 263. You have all that code outside the scope of a class.
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8342
  • View blog
  • Posts: 31,880
  • Joined: 06-March 08

Re: I keep getting the error message "reached end of file while parsin

Posted 06 December 2012 - 09:41 PM

When you are a newbie... fiorget about inner classes
Put each of your class in its own .java file and forget about the rest
that will save you a lot of trouble
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1