Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Java Assistance with a slotmachine.

    Hello, I could use some help with a slotmachine assignment I have gotten majority of the first class which is TripleString. I'm having trouble with the accessor string and the mutator string. Well I added String in front of the set string which is str1=s1; str2=s2; etc. Is this right? Eclpise is telling me with the accessor string to add a return getstr1(); instead of return str1();. Which one of all these things are right? Sorry if I sound a bit confusing I am a bit overwhelmed right now.

    import java.util.*;

    public class slotmachine{
    static Scanner input = new Scanner(System.in);
    /**
    * @param args
    */

    public static void main(String[] args) {
    // TODO Auto-generated method stub

    }


    }




    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 void setStrings(String s1, String s2, String s3){
    String str1 = s1; String str2 = s2; String str3 = s3;
    }
    public String getstr1(){
    return str1();
    }
    public String getStr2(){
    return str2();
    }
    public String getstr3(){
    return str3();
    }
    private boolean vaildString( String str ) {
    if (str.length() >0 && str.length() <= MAX_LEN) {

    return true;
    }
    else {

    return false;
    }
    }
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    These three methods for str1() through 3, simply do not exist. I would presume the intent is to return string1 - string3. setStrings method also doesn't do anything useful, so you should either remove it or correct it.

    Also, in the future please wrap your code in [php][/php] or [code][/code] tags to preserve formatting.

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, so do i create a method or each of the str1-3?

    Quote Originally Posted by Fou-Lu View Post
    These three methods for str1() through 3, simply do not exist. I would presume the intent is to return string1 - string3. setStrings method also doesn't do anything useful, so you should either remove it or correct it.

    Also, in the future please wrap your code in [php][/php] or [code][/code] tags to preserve formatting.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,980
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I don't know why you'd want to. You already have getStr1 through 3, so simply return the property that its representing in there.


  •  

    Posting Permissions

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