www.webdeveloper.com
Results 1 to 2 of 2

Thread: ; expected error

  1. #1
    Join Date
    Apr 2008
    Posts
    136

    ; expected error

    I get the following error when trying to compile: "40 error: ; expected"

    There is a ; at that line

    Code:
    import java.util.Random;
    import java.io.*;
    
    public class DealorNoDeal {
    
    	public static void main (String[] args)	{
    
    		System.out.println( "Welcome to Deal or No Deal Game!" );
    
    		System.out.println( "In this game, there are 10 cases containing" + 
    
    		"various amounts of money. Three of those cases contain no money."+ 
    
    		"Of the seven cases that do contain money, they contain the" + 		
    
    		"following amounts: $1, $10, $100, $1,000, $10,000, $100,000" +		
    
    				"and $1,000,000");
    
    		System.out.println("You will be asked to select a case to open."+ 	
    
    		"You'll have the opportunity to open up to 3 cases. But, if you" + 	
    
    		"decide you like the amount before the third case is opened, you"+ 	
    
    		"can stop the game at that point. But, if you use all three" + 		
    
    		"tries,you'll have to take the amount received on your" +		
    
    		"third try.");
    
    		System.out.println("Let's start the game!");
    
    //Setup looping mechanism to ensure user can only guess a maximum of three times.
    
    	
    	for (numofGuesses=0;numofGuesses < 3;) {
    		GameHelper helper = new GameHelper();
    		helper.getUserInput("Enter a case number between 0 and 9: ");
    
    		//Display the amount contained in the case selected by user
    		System.out.println("The case you selected contains: " + 		
    
    		(Val(arr[position])));
    		
    
    		helper.getUserYN("Deal or No Deal? Y or N");
    			if (line.equalsIgnoreCase("N"))	{
    				numofGuesses++; //If user answers "n" continue loop
    			}
    
    			else 	{
    
    			break; //If user answers "y" terminate the loop
    
    			}
    	}
    
    	//Print the amount user has won. Game over at this point.
    	System println("The amount you've won is:" + (val(arr[position])));
    
     }
    
    }
    
    public class RandomArr {
    	
        private static Random rand = new Random ();
        
        // instance variable to hold dollar amounts inside an array
        private int [] arr = { 0,0,0,1,10,100,1000,10000,100000,1000000};
            
        // setter method that randomly assigns amounts to positions inside array
        public RandomArr(){
            int tempVal;
            int randPos;
           
            for ( int i=0; i<10; i++ ) {
                for ( int j=0; i<arr.length; i++ ) {
                    randPos = rand.nextInt ( arr.length );
                    tempVal = arr[j];
                    arr[j] = arr[randPos];
                    arr[randPos] = tempVal;
                }
            }
    	}
    	
    	// getter for value of a certian position inside the array
    		public int getValue(int position){
    		return arr[position];
    	}
    	}
    
    
    
    public class GameHelper {
    	
    	
    	public String getUserInput(String prompt) {
    		
    		String inputLine = null;
    		System.out.print(prompt + " ");
    		
    		try {
    			BufferedReader is = new BufferedReader(new 			
    
    	InputStreamReader(System.in));
    			inputLine = is.readLine();
    			
    			if (inputLine.length() == 0) return null;
    		}
    		
    		catch (IOException e) {
    			System.out.println("Exception: " + e);
    		}
    		
    		return inputLine;
    	}
         
    	
    	// getter method that converts String value received from the user into an 	
    
    	//integer
    	public int getUserInt(String prompt){
    		
    		String line = getUserInput(prompt);
    		int val = Integer.parseInt(line);
    		
    		return val;
    		
    	}
    	
    	// getter boolean method that returned true if the user pressed Y and false 
    
    	//otherwise
    	// this is for the step when the user is asked Deal or No Deal question
    	public boolean getUserYN(String prompt){
    		String line = getUserInput(prompt);
    		
    		return(line.equalsIgnoreCase("Y"));
    	}	
    
        }

  2. #2
    Join Date
    Mar 2013
    Location
    Iasi, Romania
    Posts
    53
    Code:
    import java.util.Random;
    import java.io.*;
    
    public class DealorNoDeal {
    
    	public static void main (String[] args)	{
    
    		System.out.println( "Welcome to Deal or No Deal Game!" );
    
    		System.out.println( "In this game, there are 10 cases containing" + 
    
    		"various amounts of money. Three of those cases contain no money."+ 
    
    		"Of the seven cases that do contain money, they contain the" + 		
    
    		"following amounts: $1, $10, $100, $1,000, $10,000, $100,000" +		
    
    				"and $1,000,000");
    
    		System.out.println("You will be asked to select a case to open."+ 	
    
    		"You'll have the opportunity to open up to 3 cases. But, if you" + 	
    
    		"decide you like the amount before the third case is opened, you"+ 	
    
    		"can stop the game at that point. But, if you use all three" + 		
    
    		"tries,you'll have to take the amount received on your" +		
    
    		"third try.");
    
    		System.out.println("Let's start the game!");
    
    //Setup looping mechanism to ensure user can only guess a maximum of three times.
    
    	
    	for (numofGuesses=0;numofGuesses < 3;) {
    		GameHelper helper = new GameHelper();
    		helper.getUserInput("Enter a case number between 0 and 9: ");
    
    		//Display the amount contained in the case selected by user
    		System.out.println("The case you selected contains: " + 		
    
    		(Val(arr[position])));
    		
    
    		helper.getUserYN("Deal or No Deal? Y or N");
    			if (line.equalsIgnoreCase("N"))	{
    				numofGuesses++; //If user answers "n" continue loop
    			}
    
    			else 	{
    
    			break; //If user answers "y" terminate the loop
    
    			}
    	}
    
    	//Print the amount user has won. Game over at this point.
    	System.out.println("The amount you've won is:" + (val(arr[position])));
     }
    
    }
    
    public class RandomArr {
    	
        private static Random rand = new Random ();
        
        // instance variable to hold dollar amounts inside an array
        private int [] arr = { 0,0,0,1,10,100,1000,10000,100000,1000000};
            
        // setter method that randomly assigns amounts to positions inside array
        public RandomArr(){
            int tempVal;
            int randPos;
           
            for ( int i=0; i<10; i++ ) {
                for ( int j=0; i<arr.length; i++ ) {
                    randPos = rand.nextInt ( arr.length );
                    tempVal = arr[j];
                    arr[j] = arr[randPos];
                    arr[randPos] = tempVal;
                }
            }
    	}
    	
    	// getter for value of a certian position inside the array
    		public int getValue(int position){
    		return arr[position];
    	}
    	}
    
    
    
    public class GameHelper {
    	
    	
    	public String getUserInput(String prompt) {
    		
    		String inputLine = null;
    		System.out.print(prompt + " ");
    		
    		try {
    			BufferedReader is = new BufferedReader(new 			
    
    	InputStreamReader(System.in));
    			inputLine = is.readLine();
    			
    			if (inputLine.length() == 0) return null;
    		}
    		
    		catch (IOException e) {
    			System.out.println("Exception: " + e);
    		}
    		
    		return inputLine;
    	}
         
    	
    	// getter method that converts String value received from the user into an 	
    
    	//integer
    	public int getUserInt(String prompt){
    		
    		String line = getUserInput(prompt);
    		int val = Integer.parseInt(line);
    		
    		return val;
    		
    	}
    	
    	// getter boolean method that returned true if the user pressed Y and false 
    
    	//otherwise
    	// this is for the step when the user is asked Deal or No Deal question
    	public boolean getUserYN(String prompt){
    		String line = getUserInput(prompt);
    		
    		return(line.equalsIgnoreCase("Y"));
    	}	
    
        }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles