Results 1 to 7 of 7
  1. #1
    pianodave1984's Avatar
    pianodave1984 is offline Aspiring Javaman
    Join Date
    Sep 2013
    Location
    West Chester PA
    Posts
    8
    Rep Power
    0

    Default Baseball Simulator Issue. Illegal Start to an Expression?

    Here is the code for my BaseBall simulator:

    Java Code:
    public class ballgame{
    
    static int Runsf;
    static int RunsA;
    static int Outs;
    static int Innings;
    
    static boolean FirstBase;
    static boolean SecondBase;
    static boolean ThirdBase;
    static int MFirst;
    static int MSecond;
    static int MThird;
    
    
    static String[] LineUp = {"Ben Revere", "Jimmy Rollins", "Chase Utley", "Ryan Howard",
    	"Darin Ruf", "Domonic Brown", "Cody Asche", "Carlos Ruiz", "Cole Hamels"};
    static double[] OBP = {.324, .327, .373, .361, .340, .317, .324, .360, .202};
    static double[] HitP = {.826, .750, .664, .650, .662, .725, .794, .672, .810};
    static double[] EBP = {.121, .351, .397, .468, .472, .393, .370, .330, .176};
    static double[] DTP = {.999, .737, .610, .434, .423, .415, .700, .749, .933};
    static double[] TP = {.311, .192, .125, .079, .090, .143, .143, .029, .143};
    
    static String[] Stats = {"ABs", "Runs", "Hits", "Doubles", "Triples", "Homeruns",
    	"RBI", "Walks", "Hit By Pitch"};
    static double[][] Stats9 = new double[10][9];
    
    
    
    
        public static void main(String args[]){ 
        	LoadStats9();
        	Innings = 1;
        	int Batter = 0;
        	int StatIndex = 1;
        	while(Innings < 10){
        		System.out.println("------------------------------");
        		System.out.println("So we've started inning number " + Innings);
        		Outs = 0;
    	    	while(Outs < 3){
    	    		AtBat(StatIndex, Batter, FirstBase, SecondBase, ThirdBase);
    	    		Batter++;
    	    		StatIndex++;
    	    		if(Batter == 9 && StatIndex == 10){ //Top of the lineup
    	    			Batter = 0;
    	    			StatIndex = 1;
    	    		}
    	    		if(Outs == 3){
    	    			System.out.println("------------------------------");
    	    			System.out.println("And that's three down");
    	    	}//End of While Loop
    	    	Innings++;
    	}
       }
       
       public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
       	
       	System.out.println("------------------------------");
       	System.out.println(LineUp[Place2] + " is up to bat");
       	if(projection(OBP[Place2]) == true){ //Batter is on base but how
       		if(projection(HitP[Place2]) == true){ //It's a hit, but what kind
       			System.out.println("Swings and makes contact........");
       			Stats9[Place1][0]++;
       			Stats9[Place1][2]++;
       			if(projection(EBP[Place2]) == true){ //Extra Bases, but what kind
       				if(projection(DTP[Place2]) == true){ //Double/Triple
       					System.out.println("This is falling into the gap...");
       					if(projection(TP[Place2]) == true){ //Triple
       						System.out.println("He's rounding second looking for three... slides... AND HE'S SAFE WITH A TRIPLE!");
       						Stats9[Place1][4]++;
       						ThirdBase = true;
       						if(Third == true){ //Guy on Third
       							System.out.println("Runner on Third Scores");
       							Runsf++;
       							Stats9[Place1][6]++;
       							ThirdBase = true;
       							if(Second == true){ //Guy on Second
       								System.out.println("Runner on Second Scores");
       								Runsf++;
       								Stats9[Place1][6]++;
       								SecondBase = false;
       								if(First == true){ //Man on first
       									System.out.println("Runner on First comes around to score!");
       									Runsf++;
       									Stats9[Place1][6]++;
       									FirstBase = false;
       								} //End of First if
       							}//End of Second If
       						} //End of Third If
       					}else{ //It's a double
       						System.out.println("He's rounding first looking for two bags... and he's in there standing for a clean Double");
       						Stats9[Place1][3]++;
       						if(Third == true){ //Man on Third
       							System.out.println("Runner on Third scores!");
       							Runsf++;
       							Stats9[Place1][6]++;
       							ThirdBase = false;
       							if(Second == true){ //Man on Second
       								System.out.println("Runner on Second Scores");
       								Runsf++;
       								Stats9[Place1][6]++;
       								SecondBase = true;
       								if(First == true){ //Man on First
       									System.out.println("Runner on first moves on up to Second");
       									Third = true;
       									SecondBase = true;
       								}//End of First if
       							}//End of Second if
       						}//End of Third If
       					}//End of Double or Triple Decider
       				}else{ //It's a Home Run!
       					System.out.println("It's going... fair/foul it's......... FAIR! HOME RUN! CLEARING THE FENCE! GOING " + ((int)(Math.random() * 150) + 300) + " FEET!");
       					Runsf++;
       					Stats9[Place1][6]++;
       					Stats9[Place1][5]++;
       					if(Third == true){ //Man on Third
       						System.out.println("Runner on third scores!");
       						Runsf++;
       						Stats9[Place1][6]++;
       						ThirdBase = false;
       						if(Second == true){ //Man on Second
       							System.out.println("Runner on Second Scores!");
       							Runsf++;
       							Stats9[Place1][6]++;
       							SecondBase = false;
       							if(First == true){ //Man on First
       								System.out.println("Runner on First Scores!");
       								Runsf++;
       								Stats9[Place1][6]++;
       								FirstBase = false;
       							} //End of First if
       						} //End of Second if
       					} //End of Third If
       				} //End of Homer Run Decider
       			}else{ //It's a single
       				System.out.println("And through to the outfield for a single");
       				First = true;
       				if(Third == true){ //Man on Third
       					System.out.println("Runner on Third Scores");
       					Runsf++;
       					Stats9[Place1][6]++;
       					ThirdBase = false;
       					if(Second == true){ //Man on Second
       						System.out.println("Man on Second moves to Third");
       						ThirdBase = true;
       						SecondBase = false;
       						if(First == true){ //Man on First
       							System.out.println("Man on First moves up to Second");
       							SecondBase = true; 
       							FirstBase = true;
       						} //End of First if
       					} //End of Second If
       				} //End of Third If
       			}//End of Extra Base decider
       		}else{ //It's a Walk. Will be changed later
       			System.out.println("And that'll be ball four. A good show of patience by "  + LineUp[Place2]);
       			Stats9[Place1][7]++;
       			First = true;
       			if(Third == true){ //Man on Third
       				if(Second == true){ //Man on Second
       					if(First == true){ //Man on first
       						Runsf++;
       						Stats9[Place1][6]++;
       						SecondBase = true;
       						ThirdBase = true;
       						FirstBase = true;
       					}else{ //First is empty
       						FirstBase = true;
       					} //end of First if
       				}else{ //Second is empty
       					if(First == true){ //Man on first
       						SecondBase = true;
       						FirstBase = true;
       					} //End of First if
       				} //End of Second If
       			}else{ //Third base is empty
       				if(Second == true){//Man on Second
       					if(First == true){ //Man on First
       						SecondBase = true;
       						ThirdBase = true;
       						FirstBase = true;
       					}else{ //First base is empty
       						FirstBase = true;
       					} //End of First if
       				}else{ //Second base is empty
       					if(First == true){ //Man on First
       						SecondBase = true;
       						FirstBase = true;
       					}else{ //First base is empty
       						FirstBase = true;
       					} // End of First if
       				} //End of Second if
       			} //End of Third if
       		} //End of Hit or Walk decider
       	}else{ // Batter is out
       		System.out.println("And he's out! How did he get out? Not sure I wasn't paying attention");
       		Outs++;
       	} //End of Swing Decider
       } //End of At Bat Simulation
       
       public static boolean projection(double Percentage){
    	boolean Strike;
       	double PNumber = Math.random();
       	if(PNumber <= Percentage){
       		Strike = true;
       	}else{
       		Strike = false;
       	}
       	return Strike;
       }
       
       public static void LoadStats9(){
       	for(int i = 0; i < 10; i++){
    		for(int j = 0; j < 9; j++){
    			Stats9[i][j] = 0;
    		}
    	}
       }
       
    }
    I keep getting this error Message when I try to run it:

    compilesrc:
    [mkdir] Created dir: /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/build/classes
    [javac] Compiling 6 source files to /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/build/classes
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: illegal start of expression
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: illegal start of expression
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: ';' expected
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: '.class' expected
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: ';' expected
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: <identifier> expected
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: not a statement
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: ';' expected
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: <identifier> expected
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: not a statement
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:56: ';' expected
    [javac] public static void AtBat(int Place1, int Place2, boolean First, boolean Second, boolean Third){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:201: illegal start of expression
    [javac] public static boolean projection(double Percentage){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:201: illegal start of expression
    [javac] public static boolean projection(double Percentage){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:201: ';' expected
    [javac] public static boolean projection(double Percentage){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:201: '.class' expected
    [javac] public static boolean projection(double Percentage){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:201: ';' expected
    [javac] public static boolean projection(double Percentage){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:212: illegal start of expression
    [javac] public static void LoadStats9(){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:212: illegal start of expression
    [javac] public static void LoadStats9(){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:212: ';' expected
    [javac] public static void LoadStats9(){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:212: ';' expected
    [javac] public static void LoadStats9(){
    [javac] ^
    [javac] /home/onlinej/appservers/apache-tomcat-7.0.29/myusers/david.mcmonigleootp@yahoo.com/createdJavaFiles/ballgame.java:220: reached end of file while parsing
    [javac] }
    [javac] ^
    [javac] 21 errors



    Any thoughts? It ran fine the last time I ran it. Then I wanted to initialize the Boolean values for the bases before each inning and it started yelling at me. What did I do wrong?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: Baseball Simulator Issue. Illegal Start to an Expression?

    Count the curly brackets { ... } they should all match.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: Baseball Simulator Issue. Illegal Start to an Expression?

    Also, here are a couple of suggestions for future reference:

    When using booleans, the following are identical:

    Java Code:
    if (val == true) {
      // do something
    }
    
    if (val) { // preferred syntax
      // do something
    }
    To check for false do this
    Java Code:
    if (!val) {
       // do something
    }
    This is because the logical expression inside the if statement is evaluated to either true or false and then used to make the decision.

    Also, the following routine,

    Java Code:
    public static boolean projection(double Percentage) {
        boolean Strike;
        double PNumber = Math.random();
        if(PNumber <= Percentage){
            Strike = true;
        }else{
            Strike = false;
        }
        return Strike;
    }
    Can be shortened to

    Java Code:
    public static boolean projection(double Percentage){
        double PNumber = Math.random();
        return PNumber <= Percentage; // remember, logical expressions evaluate to true or false
    }
    or even

    Java Code:
    public static boolean projection(double Percentage){
        return Math.random() <= Percentage; // remember, logical expressions evaluate to true or false
    }

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  4. #4
    pianodave1984's Avatar
    pianodave1984 is offline Aspiring Javaman
    Join Date
    Sep 2013
    Location
    West Chester PA
    Posts
    8
    Rep Power
    0

    Default Re: Baseball Simulator Issue. Illegal Start to an Expression?

    Quote Originally Posted by JosAH View Post
    Count the curly brackets { ... } they should all match.

    kind regards,

    Jos
    AND THE TRUTH SHALL SET YOU FREE.

    Me and my blind eyes missed a bracket.... working fine.... now just to fix the logic

  5. #5
    pianodave1984's Avatar
    pianodave1984 is offline Aspiring Javaman
    Join Date
    Sep 2013
    Location
    West Chester PA
    Posts
    8
    Rep Power
    0

    Default Re: Baseball Simulator Issue. Illegal Start to an Expression?

    Quote Originally Posted by jim829 View Post
    Also, here are a couple of suggestions for future reference:

    When using booleans, the following are identical:

    Java Code:
    if (val == true) {
      // do something
    }
    
    if (val) { // preferred syntax
      // do something
    }
    To check for false do this
    Java Code:
    if (!val) {
       // do something
    }
    This is because the logical expression inside the if statement is evaluated to either true or false and then used to make the decision.

    Also, the following routine,

    Java Code:
    public static boolean projection(double Percentage) {
        boolean Strike;
        double PNumber = Math.random();
        if(PNumber <= Percentage){
            Strike = true;
        }else{
            Strike = false;
        }
        return Strike;
    }
    Can be shortened to

    Java Code:
    public static boolean projection(double Percentage){
        double PNumber = Math.random();
        return PNumber <= Percentage; // remember, logical expressions evaluate to true or false
    }
    or even

    Java Code:
    public static boolean projection(double Percentage){
        return Math.random() <= Percentage; // remember, logical expressions evaluate to true or false
    }

    Regards,
    Jim
    So
    Java Code:
    if(myBoolean == true){
            //something to do
    }
    can be shortened to this?
    Java Code:
    if(myBoolean){
         //something to do
    }

  6. #6
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,617
    Rep Power
    5

    Default Re: Baseball Simulator Issue. Illegal Start to an Expression?

    Exactly!

    And in general, any expression which evaluates to true or false may be assigned to a boolean. So

    Java Code:
    boolean result =  a <= b;
    if (result) {
      // do something
    }
    
    // is the same as 
    
    if (a <= b) {
       // do something.
    }
    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,529
    Blog Entries
    7
    Rep Power
    20

    Default Re: Baseball Simulator Issue. Illegal Start to an Expression?

    Quote Originally Posted by pianodave1984 View Post
    AND THE TRUTH SHALL SET YOU FREE.

    Me and my blind eyes missed a bracket.... working fine.... now just to fix the logic
    You should use an editor that does the counting and matching for you. Vi (or vim) does a fine job as well as the editor in Eclipse; I bet Netbeans has a similar feature.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Illegal start of expression
    By eddyk6 in forum New To Java
    Replies: 4
    Last Post: 01-27-2012, 07:51 AM
  2. Illegal Start of expression
    By Macca07 in forum New To Java
    Replies: 3
    Last Post: 11-23-2009, 08:43 AM
  3. Illegal start of expression
    By Basit56 in forum New To Java
    Replies: 2
    Last Post: 08-18-2009, 09:12 AM
  4. illegal start of expression
    By razmyasdfg in forum CLDC and MIDP
    Replies: 2
    Last Post: 07-27-2008, 10:44 PM
  5. Illegal start of expression
    By gabriel in forum New To Java
    Replies: 2
    Last Post: 08-01-2007, 05:09 PM

Tags for this Thread

Posting Permissions

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