0
public class slots 
{

public static void main(String[]args)
{

    public  String pull() {
        int rand = (int)(Math.random()*3+1);
        if(rand == 1)
            return "cherries";
        else if(rand == 2)
            return "bar";
        else
            return "7";
    }
    string1 = pull();
    string2 = pull();
    string3 = pull();
}
}
class TripleString 
{
    public static final int MAX_LEN = 20;
    private String string1;
    private String string2;
    private String string3;

    TripleString()
    {
        string1 ="";
        string2 ="";
        string3 ="";
    }

    public void setTripleString (String str1, String str2, String str3) 
    {
        string1 = str1;
        string2 = str2;
        string3 = str3;
    }

    public String getstring1()
    {
        return string1;
    }

    public String getstring2()
    {
        return string2;
    }

    public String getstring3()
    {
        return string3;
    }

    private boolean vaildString( String str ) 
    {
        if (str.length() >0 && str.length() <= MAX_LEN) 
        {
            return true;
        }
        else 
        {
            return false;
        }
    }
}

I currently have this code and am trying to create a slot machine that will randomly return these values but there is a syntax error on string pull() that im not sure how to fix. Does anyone know how to make this work?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
eflam117
  • 23
  • 3

3 Answers3

4

You can't define another method inside of the main method; move pull out of main. Also, it looks like you meant to make pull a static method (since you will be calling it in a static context within main). Lastly, don't forget to declare the types of your variables in main, so you would want String string1 = pull().

arshajii
  • 127,459
  • 24
  • 238
  • 287
0

You're trying to use string1, string2 and string3 in your main method that's inside of your slots class, when you declare these variables in your TripleStrings class.

You should also (by convention) use Slots instead of slots as your class name. Every Java type should begin with an uppercase.

Rob
  • 15,732
  • 22
  • 69
  • 107
0

Change your code like this:

public class slots 
{

  public static void main(String[]args)
  {
    String string1 = pull();
    String string2 = pull();
    String string3 = pull();
  }

  public static String pull() {
    int rand = (int)(Math.random()*3+1);
    if(rand == 1)
      return "cherries";
    else if(rand == 2)
      return "bar";
    else
      return "7";
    }
  }

...

yaens
  • 169
  • 5