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

Thread: rock paper si

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default rock paper si

    hi, got a problem with my code i'm getting the following error


    Bladsteenschaar5.java:39: illegal start of expression
    public void speelde(){
    ^
    Bladsteenschaar5.java:39: illegal start of expression
    public void speelde(){
    ^
    Bladsteenschaar5.java:39: ';' expected
    public void speelde(){
    ^
    3 errors

    I know its something to do with my }{ but i can't find it so need help.

    public class Bladsteenschaar5 {
    public void speel() {

    final int BLAD = 0;
    final int STEEN = 1;
    final int SCHAAR = 2;
    int keuzeSpeler = 0;

    // zolang er geen geldige keuze is, lees je het nog eens in
    boolean leesNogEensIn = true;

    while (leesNogEensIn) {

    System.out.println("Maak je keuze: blad, steen of schaar :");
    String keuze = Input.readString().toLowerCase();

    // we moeten het naar kleine letters omzetten, omdat misschien iemand Blad of blad of BLAD
    // heeft ingetikt en eigenlijk is dat allemaal hetzelfde
    // later gaan we dit dan vergelijken met kleine letters
    System.out.println("Uw keuze is : " + keuze);

    int computer;

    computer = (int) (Math.random() * 3);

    ;
    if (keuze.equals("blad")) {
    keuzeSpeler = 0;
    leesNogEensIn = false; // goede ingave dus moet niet meer ingelezen worden
    } else if (keuze.equals("steen")) {
    keuzeSpeler = 1;
    leesNogEensIn = false; // goede ingave dus moet niet meer ingelezen worden
    } else if (keuze.equals("schaar")) {
    keuzeSpeler = 2;
    leesNogEensIn = false; // goede ingave dus moet niet meer ingelezen worden
    }
    }

    public void speelde(){
    switch (computer) {
    case 0: // BLAD
    switch (keuzeSpeler)
    {
    case 0: // BLAD
    System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : BLAD => Gelijkspel");
    break;
    case 1: //STEEN
    System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : BLAD => COMPUTER wint");
    break;
    case 2: // SCHAAR
    System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : BLAD => SPELER wint");
    break;
    default:
    System.out.println("Verkeerde ingave");
    break;
    }
    break;
    case 1: // STEEN
    switch (keuzeSpeler)
    {
    case 0: // BLAD
    System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : STEEN => SPELER wint");
    break;
    case 1: //STEEN
    System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : STEEN => Gelijkspel");
    break;
    case 2: // SCHAAR
    System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : STEEN => COMPUTER wint");
    break;
    default:
    System.out.println("Verkeerde ingave");
    break;
    }
    break;
    case 2: // SCHAAR
    switch (keuzeSpeler)
    {
    case 0: // BLAD
    System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : SCHAAR => COMPUTER wint");
    break;
    case 1: //STEEN
    System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : SCHAAR => SPELER wint");
    break;
    case 2: // SCHAAR
    System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : SCHAAR => Gelijkspel");
    break;
    default:
    System.out.println("Verkeerde ingave");
    break;
    }
    break;

    }


    }


    }
    public static void main(String[] args) {
    Bladsteenschaar5 b = new Bladsteenschaar5();
    b.speel();
    b.speelde();
    }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: rock paper si

    You need to wrap your code in code tags to preserve its formatting. Press the Go Advanced button, select the code and press the #icon.

    Have you checked that all }s are correctly paired with a }?
    Many IDEs and editors have a feature that will do that. Put the cursor on the { press a key combination (CTRL+] in my editor) and the cursor moves to the paired }

    Another aid for solving this problem is to label all the } with a comment about what scope they are ending.

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: rock paper si

    public class Bladsteenschaar5 {
       public void speel() {
     
            final int BLAD = 0;
            final int STEEN = 1;
            final int SCHAAR = 2;
            int keuzeSpeler = 0;
     
            // zolang er geen geldige keuze is, lees je het nog eens in
            boolean leesNogEensIn = true;
     
            while (leesNogEensIn) {
     
                System.out.println("Maak je keuze: blad, steen of schaar :");
                String keuze = Input.readString().toLowerCase();
     
                // we moeten het naar kleine letters omzetten, omdat misschien iemand Blad of blad of BLAD
                // heeft ingetikt en eigenlijk is dat allemaal hetzelfde
                // later gaan we dit dan vergelijken met kleine letters
                System.out.println("Uw keuze is : " + keuze);
     
                int computer;
     
                computer = (int) (Math.random() * 3);
     
                ;
                if (keuze.equals("blad")) {
                    keuzeSpeler = 0;
                    leesNogEensIn = false; // goede ingave dus moet niet meer ingelezen worden
                } else if (keuze.equals("steen")) {
                    keuzeSpeler = 1;
                    leesNogEensIn = false; // goede ingave dus moet niet meer ingelezen worden
                } else if (keuze.equals("schaar")) {
                    keuzeSpeler = 2;
                    leesNogEensIn = false; // goede ingave dus moet niet meer ingelezen worden
         }
    }
     
    	public void speelde(){
                switch (computer) {
                    case 0: // BLAD
                        switch (keuzeSpeler)
                        {
                            case 0: // BLAD
                                System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : BLAD => Gelijkspel");
                                break;
                            case 1: //STEEN
                                System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : BLAD => COMPUTER wint");
                                break;
                            case 2: // SCHAAR
                                System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : BLAD => SPELER wint");
                                break;
                            default:
                        	System.out.println("Verkeerde ingave");
                       		break;
                        }
                        break;
                    case 1: // STEEN
                        switch (keuzeSpeler)
                        {
                            case 0: // BLAD
                                System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : STEEN => SPELER wint");
                                break;
                            case 1: //STEEN
                                System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : STEEN => Gelijkspel");
                                break;
                            case 2: // SCHAAR
                                System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : STEEN => COMPUTER wint");
                                break;
                            default:
                        	System.out.println("Verkeerde ingave");
                       		break;
                        }
                        break;
                    case 2: // SCHAAR
                        switch (keuzeSpeler)
                        {
                            case 0: // BLAD
                                System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : SCHAAR => COMPUTER wint");
                                break;
                            case 1: //STEEN
                                System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : SCHAAR => SPELER wint");
                                break;
                            case 2: // SCHAAR
                                System.out.println("Speler koos " + keuze.toUpperCase() + ", De computer kiest : SCHAAR => Gelijkspel");
                                break;
                            default:
                       		 System.out.println("Verkeerde ingave");
                       		 break;
                        }
                        break;
     
                }
     
     
            }
     
     
    }
        public static void main(String[] args) {
            Bladsteenschaar5 b = new Bladsteenschaar5();
            b.speel();
            b.speelde();
        }
    }

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: rock paper si

    public void speel() {
    Where this function ends???? Probably, } is missing here.

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: rock paper si

    i fixed it, thanks. used do while .

    public class Bladsteenschaar6 {
    	final int blad = 0;
        final int steen = 1;
        final int schaar = 2;
        int computer;
        int keuzeSpeler;
        String keuze;
     
     
       	public void kies() {
     
     
       		do {
        	System.out.println("Kies: blad, steen of schaar");
    		keuze = Input.readString().toLowerCase(); 
    		System.out.println("uw keuze is : " + keuze);
    		} 	
    		while ( !keuze.equals("blad") && !keuze.equals("steen") && !keuze.equals("schaar") );
     
    	}
     
    	public void omzetting() {
    		computer = (int) (Math.random() * 3);
     
    		if (keuze.equals("blad")) {
                keuzeSpeler = 0;
            }
            else if (keuze.equals("steen")) {
                    keuzeSpeler = 1;
            } 
            else if (keuze.equals("schaar")) {
                    keuzeSpeler = 2;
         	}
     
    }
     
    	public void vergelijk() {
     
    		switch (computer) {
    			case 0: //blad
    				switch (keuzeSpeler)
    				{
    					case 0: //blad
    						System.out.println("Speler koos " + keuze + ", De computer kiest : blad => Gelijkspel");
    						break;
    					case 1: //steen
    						System.out.println("Speler koos " + keuze + ", De computer kiest : blad => Computer wint");
    						break;
    					case 2: //schaar
    						System.out.println("Speler koos " + keuze + ", De computer kiest : blad => SPELER wint");
    						break;
    				}
    				break;
     
    			case 1: //steen
    				switch (keuzeSpeler)
    				{
    					case 0: //blad
    						System.out.println("Speler koos " + keuze + ", De computer kiest : steen => Speler wint");
    						break;
    					case 1: //steen
    						System.out.println("Speler koos " + keuze + ", De computer kiest : steen => Gelijkspel");
    						break;
    					case 2: //schaar
    						System.out.println("Speler koos " + keuze + ", De computer kiest : steen => Computer wint");
    						break;
    				}
    				break;
     
    			case 2: //schaar
    				switch (keuzeSpeler)
    				{
    					case 0: //blad
    						System.out.println("Speler koos " + keuze + ", De computer kiest : schaar => Computer wint");
    						break;
    					case 1: //steen
    						System.out.println("Speler koos " + keuze + ", De computer kiest : schaar => Speler wint");
    						break;
    					case 2: //schaar
    						System.out.println("Speler koos " + keuze + ", De computer kiest : schaar =>  Gelijkspel");
    						break;
    				}
    				break;
     
    			}
    		}
     
     
     
     
     
     
     
     
        public static void main(String[] args) {
            Bladsteenschaar6 b = new Bladsteenschaar6();
            b.kies();
            b.omzetting();
            b.vergelijk();
     
        }
    }

Similar Threads

  1. Rock Paper Scissors Spock Lizard Player Problem
    By flyingcurry in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 3rd, 2011, 10:53 AM
  2. [SOLVED] Specific Text Extraction from PDF Research paper documents
    By user101 in forum Threads
    Replies: 1
    Last Post: September 8th, 2010, 11:30 AM
  3. The positioning and alignment of the text on the paper to be printed
    By java_fledgeling in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: June 8th, 2010, 08:54 PM
  4. MyThesis: rock,paper,scissor..on mobile
    By Cross`17 in forum Java ME (Mobile Edition)
    Replies: 2
    Last Post: April 22nd, 2010, 08:33 AM
  5. Paper on a Java Program
    By dude in forum Java Theory & Questions
    Replies: 1
    Last Post: December 4th, 2009, 05:40 PM