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

Thread: Newbie problem

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

    Default Newbie problem

    Hey people, i've just started programing java and i've written this.
    It's a paper rock scissors program program, and im from sweden, so the variables are i swedish, sorry
    My problem is that when i compile this and choose, the letter "s" for sten (stone), it prints '

    dator; *sten sax or påse* spelare; påse


    but is should print dator; *sten sax or påse* spelare; sten
    I've looked over the code like 10 times and i don't se the problem...
    i also have another enum class witch just says " enum Dval {sten, sax, påse} enum Sval{sten sax påse}

    it's probably really simple, but im new to this sorry, can anyone help me?

    import java.util.Scanner;
    import java.util.Random;
     
    public class StenSaxPåse {
     
     
    	public static void main(String[] args) {
    		Scanner skann = new Scanner(System.in);
    		Random datorval = new Random();
     
    		char spelarval;
    		int dataval;
     
    		Sval spelare;
    		Dval datorr;
    		boolean sten;
    		boolean sax;
    		boolean påse;
     
    		dataval = datorval.nextInt(3);
    		System.out.print(0);
     
    		if (dataval == 00) {
    			datorr = Dval.sten;
    		}
    		else if (dataval == 01) {
    			datorr = Dval.sax;
    		}
    		else if (dataval == 02){
    			datorr = Dval.påse;
    		}
    		else { datorr = Dval.påse; }
     
     
     
     
    		System.out.println("Hej");
    		System.out.println("S för sten X för sax eller P för påse");
     
    		spelarval = skann.findInLine(".").charAt(0);
     
     
    		påse = spelarval == 'P' || spelarval == 'p';
    		sten = spelarval == 'S' || spelarval == 's';
    		sax = spelarval == 'X'  || spelarval == 'x';
     
    		System.out.println(påse);
    		System.out.println(sten);
    		System.out.println(sax);
     
    		if (påse) {
    			spelare = Sval.påse;
    		}
    		if (sten) {
    			spelare = Sval.sten;
    		}
    		if (sax) {
    			spelare = Sval.sax;
    		}
    		else {spelare = Sval.påse;
    		}
     
    		if (spelare == Sval.påse && datorr == Dval.sax) {
    			System.out.println("dator; sten   Spelare ; påse");
    		}
    		if (spelare == Sval.påse && datorr == Dval.sten ) {
    			System.out.println("dator; sten     spelare; påse");
    		}
    		if (spelare == Sval.påse && datorr == Dval.påse) {
    			System.out.println("dator; påse    spelare; påse");
    		}
    		if (spelare == Sval.sten && datorr == Dval.sax) {
    			System.out.println("Dator; sax   spelare;   sten");	
    		}
    		if (spelare == Sval.sten && datorr == Dval.påse) {
    			System.out.println("Dator; påse   spelare;   sten");	
    		}
    		if (spelare == Sval.sten && datorr == Dval.sten) {
    			System.out.println("Dator; sten   spelare;   sten");	
    		}
    		if (spelare == Sval.sax && datorr == Dval.sax) {
    			System.out.println("Dator;  sax    spelare;   sax");	
    		}
    		if (spelare == Sval.sax && datorr == Dval.sten) {
    			System.out.println("Dator; sten    spelare;   sax");	
    		}
    		if (spelare == Sval.sax && datorr == Dval.påse) {
    			System.out.println("Dator; påse    spelare;   sax");	
     
    		}
     
     
    	}
    }
    Last edited by JavaPF; January 27th, 2011 at 04:17 AM. Reason: Please use [highlight=Java] code [/highlight] tags


  2. #2
    Member
    Join Date
    Jan 2011
    Location
    Phoenix
    Posts
    49
    Thanks
    2
    Thanked 2 Times in 2 Posts

    Default Re: Newbie problem

    hey,

    i do apologize but i am struggling throught the language barrier. it seems that there are other classes that you are calling, can you post that code too? also if it isnt too much to ask can you try to translate the variables?

    as im not quite understanding the program entirely this would be very helpful

    thanks

    EDIT: im thinking that you should redo the statements after the findinline method call...

    String spelarval = new String("");
     
    if (spelarval.equalsIgnoreCase==('p'))
    påse=true;
     
    //continue like this for sten and sax
    Last edited by that_guy; January 27th, 2011 at 05:32 AM.

Similar Threads

  1. Output problem (newbie)
    By Asido in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 8th, 2010, 12:19 PM
  2. newbie GUI/ event handling problem
    By zyspt in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 10th, 2010, 11:36 AM
  3. Newbie Programming problem
    By Pingu in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 01:10 AM
  4. Re: Java Newbie Code Problem
    By erinbasim in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 01:05 AM
  5. [SOLVED] Java Newbie Code Problem
    By lee in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 16th, 2010, 02:05 PM

Tags for this Thread