Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-08-2012, 07:15 AM   PM User | #1
iwn730
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
iwn730 is an unknown quantity at this point
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;
}
}
}
iwn730 is offline   Reply With Quote
Old 11-08-2012, 01:54 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 11-08-2012, 04:15 PM   PM User | #3
iwn730
New to the CF scene

 
Join Date: Nov 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
iwn730 is an unknown quantity at this point
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.
iwn730 is offline   Reply With Quote
Old 11-08-2012, 04:18 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:40 AM.


Advertisement
Log in to turn off these ads.