Results 1 to 2 of 2
  1. #1
    mbw290 is offline Member
    Join Date
    Sep 2011
    Posts
    12
    Rep Power
    0

    Default string array hell (please help!!)

    I get the following compiler errors Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    st cannot be resolved
    Syntax error on token "}", delete this token
    The method getAverage(int, int) in the type Besibol is not applicable for the arguments (float, int)
    i cannot be resolved to a variable
    i cannot be resolved to a variable
    Syntax error, insert "}" to complete Block
    Syntax error, insert "while ( Expression ) ;" to complete DoStatement
    Syntax error on token "}", { expected after this token

    at Besibol.main(Beisbol.java:63)

    Java Code:
    import java.io.*;
    import java.lang.*;
    import java.util.*;
    import java.text.*;
    public class Besibol
    {
      public static void main (String[]args) throws IOException
      {
        ////////////////////////////////////////////////////////
        //Variable Declarations                       //
        ////////////////////////////////////////////////////////
    
        BufferedReader br;
          String[] name;
        String AB;
        String hits;
        String user = "";
        boolean option;
    
        int[] numAB;
        int[] numHits;
        int tokencount = 0;
          name = new String[10];
          numAB = new int[10];
          numHits = new int[10];
        //////////////////////////////////////////////////////////
        //Since the user needs to be prompted for the input     //
        //before they choose whether or not to enter another,   //
        //the do while statement is the best option.            //
        //////////////////////////////////////////////////////////
        do
          {
    	//////////////////////////////////////////////////////////
    	//This section simply prompts the user for information, //
    	//and initializes the bufferedReader variables to user  //
    	//input.                                                //
    	System.out.print ("Enter name: ");
    	br = new BufferedReader (new InputStreamReader (System.in));
    	//name = br.readLine ();
    	System.out.print ("Enter at bats: ");
    	br = new BufferedReader (new InputStreamReader (System.in));
    	AB = br.readLine ();
    	System.out.print ("Enter hits: ");
    	br = new BufferedReader (new InputStreamReader (System.in));
    	hits = br.readLine ();
    	////////////////////////////////////////////////////////////
    	//Performing math functions would require the user to     //
    	//enter an int and thus we need to check and then proceed //
    	////////////////////////////////////////////////////////////
    
    	try
    	{
    	  for (int i = 0; i < numHits.length; i++)
    	    {
    
    	      numAB[i] = Integer.parseInt (AB);
    	      numHits[i] = Integer.parseInt (hits);
    	      //////////////////////////////////////////////////////
    	      //This tokenizer will allow us to split the string  //
    	      //with the default " " and swap first and last name //
    	      //////////////////////////////////////////////////////
    	  //    StringTokenizer st = new StringTokenizer (name);
    	        tokencount = st.countTokens ();
    	      /////////////////////////////////////////////////////////////
    	      //Just to make sure that the user entered the name right,  //
    	      //We make sure there are only two tokens.                  //
    	      /////////////////////////////////////////////////////////////
    	    //  if (tokencount != 2)
    		//{
    		 // System.out.println
    		  //  ("Please enter a first and last name only, no more, no less.");
    		  //System.exit (1);
    		//}
    	      /////////////////////////////////////////////////////////////
    	      //Swapping first and last                                  //
    	      /////////////////////////////////////////////////////////////
    	      //while (st.hasMoreTokens ())
    		//{
    		  //String first = st.nextToken ();
    		  //String last = st.nextToken ();
    		    //System.out.println ("Thank you, your results are:");
    		    //System.out.println ("Player: " + last + "," + first);
    		    System.out.println ("At Bats: " + numAB[i]);
    		    System.out.println ("Hits: " + numHits[i]);
    		}
    	      /////////////////////////////////////////////////////////////
    	      //Simple check to make sure the user doesn't enter an      //
    	      //impossible scenario.                                     //
    	      /////////////////////////////////////////////////////////////
    	     // if (numHits[i] < numAB[i])
    		//{
    		//}
    	     // else
    		//{
    		 // System.out.println ("You are a dumbass");
    		  //System.exit (1);
    		//}
    	    }
    
    	}
    
    
    	//////////////////////////////////////////////////////////////
    	//If user makes a mistake, we will catch it and tell them.  //
    	//////////////////////////////////////////////////////////////
    	catch (NumberFormatException e)
    	{
    	  System.out.println ("Please enter a valid integer");
    	  System.exit (1);
    	}
    	//////////////////////////////////////////////////////////////
    	//This is our method getAverage at work.  After calculating,//
    	//we format the decimal to always be 3 digits after decimal.//
    	//////////////////////////////////////////////////////////////
    
    	float Average = getAverage ((float) numHits[i], numAB[i]);
    	DecimalFormat formatter = new DecimalFormat (".000");
    	System.out.println ("Average: " + formatter.format (Average));
    	////////////////////////////////////////////////////////
    	//Prompts the user for another round of calculation   //
    	//and initiliazes the br variable to user input       //
    	////////////////////////////////////////////////////////        
    	System.out.print ("enter another user (yes or no):  ");
    	br = new BufferedReader (new InputStreamReader (System.in));
    	user = br.readLine ();
    
    	/////////////////////////////////////////////////////////
    	//I set the boolean variable to false or true based on //
    	//user input.  Then the while continues the program    //
    	//only if the user enters yes as in they wish to       //
    	//continue.                                            //
    	/////////////////////////////////////////////////////////
    
    	if (user.equals ("no"))
    	  {
    	    option = false;
    	    System.exit (1);
    	  }
    	if (user.equals ("yes"))
    	  {
    	    option = true;
    	  }
    	else
    	  {
    	    System.out.println ("invalid option");
    	    System.exit (1);
    	  }
    	 while (option = true);
      }
    }
    
          }
       
    
    
    
      //////////////////////////////////////////////////
      //It may be simple, but this separate method    //
      //does most of the heavy lifiting in calculating//
      //the actual average and returning it.          //
      //////////////////////////////////////////////////
      public static float getAverage (int numHits, int numAB)
      {
        float Average = numHits / numAB;
        return (Average);
      }
    }

  2. #2
    musclecode is offline Member
    Join Date
    Aug 2012
    Posts
    9
    Rep Power
    0

    Default Re: string array hell (please help!!)

    You've got: st cannot be resolved
    because line 62 is commented, but even when I'm deleting slashes it gives error that constructor of class StringTokenizer (you can use String as argument but not String[]). A re you sure you need string array to keep name?

    Next: whats 'i' from line 116? It's outside everything

    Sorry if I'm wrong, I'm just newbie that want to help

Similar Threads

  1. Comparing 2D string array with 1D string array
    By jumpgirl in forum New To Java
    Replies: 1
    Last Post: 03-31-2012, 09:41 PM
  2. Thread hell - Please Help!!
    By lcmorley in forum Threads and Synchronization
    Replies: 3
    Last Post: 01-03-2012, 05:24 PM
  3. create a 2d char array from a 1D string array
    By jschmall12 in forum New To Java
    Replies: 1
    Last Post: 04-27-2010, 09:01 PM
  4. Convert Char Array to String Array
    By Mayur in forum New To Java
    Replies: 8
    Last Post: 10-12-2009, 11:41 AM
  5. Replies: 1
    Last Post: 08-03-2007, 10:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •