Need help w/ java class

User avatar
Waffles
Posts: 6876
Joined: Mon Dec 11, 2006 3:45 am

Need help w/ java class

Post by Waffles »

No, that will take the string as is. You will need 7 indexof statements.
Image
User avatar
sirricealot
Posts: 841
Joined: Sat Feb 19, 2011 3:35 pm

Need help w/ java class

Post by sirricealot »

Waffles;296976 wrote:No, that will take the string as is. You will need 7 indexof statements.
int foundSymbol = password.indexOf("!);
int foundSymbol = password.indexOf("@);
int foundSymbol = password.indexOf("#);
int foundSymbol = password.indexOf("$);
int foundSymbol = password.indexOf("%);
int foundSymbol = password.indexOf("^);
int foundSymbol = password.indexOf("/&);
int foundSymbol = password.indexOf("*);
if(foundSymbol >=0)



Like that? Oh and I just realized I need to add equals.ignoreCase somewhere
2006 Chevy Cobalt SS/NA 2.4L IL: FEERME7
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
User avatar
Waffles
Posts: 6876
Joined: Mon Dec 11, 2006 3:45 am

Need help w/ java class

Post by Waffles »

Not quite that will only test the last one. You are resetting your variable each time, then only testing the last time.
Image
User avatar
sirricealot
Posts: 841
Joined: Sat Feb 19, 2011 3:35 pm

Need help w/ java class

Post by sirricealot »

Waffles;296979 wrote:Not quite that will only test the last one. You are resetting your variable each time, then only testing the last time.
It gave me a compile error anyways. If i have to have seperate indexOf statements for the special characters how would I go about putting those together? Obviously the !@#$%^&* wont work together as one whole string.
2006 Chevy Cobalt SS/NA 2.4L IL: FEERME7
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
User avatar
Waffles
Posts: 6876
Joined: Mon Dec 11, 2006 3:45 am

Need help w/ java class

Post by Waffles »

Try this(my java is rusty so it might not work):

Code: Select all

int foundSymbol = 0
int foundSymbol = foundSymbol + password.indexOf("!") + 1;
int foundSymbol = foundSymbol + password.indexOf("@") + 1;
int foundSymbol = foundSymbol + password.indexOf("#") + 1;
int foundSymbol = foundSymbol + password.indexOf("$") + 1;
int foundSymbol = foundSymbol + password.indexOf("%") + 1;
int foundSymbol = foundSymbol + password.indexOf("^") + 1;
int foundSymbol = foundSymbol + password.indexOf("/&") + 1;
int foundSymbol = foundSymbol + password.indexOf("*") + 1;
if(foundSymbol  > 0){}
So that I am doing is setting foundSymbol to 0. If index of does not find the character in the string it returns -1. -1 + 1 = 0. Then if one of them hits in the index it will return a 1 or greater. So if foundSymbol is larger than 0 you contain one of the characters.

You also forgot the closing quotes in your string.
Image
User avatar
sirricealot
Posts: 841
Joined: Sat Feb 19, 2011 3:35 pm

Need help w/ java class

Post by sirricealot »

Waffles;296981 wrote:Try this(my java is rusty so it might not work):

Code: Select all

int foundSymbol = 0
int foundSymbol = foundSymbol + password.indexOf("!") + 1;
int foundSymbol = foundSymbol + password.indexOf("@") + 1;
int foundSymbol = foundSymbol + password.indexOf("#") + 1;
int foundSymbol = foundSymbol + password.indexOf("$") + 1;
int foundSymbol = foundSymbol + password.indexOf("%") + 1;
int foundSymbol = foundSymbol + password.indexOf("^") + 1;
int foundSymbol = foundSymbol + password.indexOf("/&") + 1;
int foundSymbol = foundSymbol + password.indexOf("*") + 1;
if(foundSymbol  > 0){}
So that I am doing is setting foundSymbol to 0. If index of does not find the character in the string it returns -1. -1 + 1 = 0. Then if one of them hits in the index it will return a 1 or greater. So if foundSymbol is larger than 0 you contain one of the characters.

You also forgot the closing quotes in your string.
Same error I've been getting with the multiple indexOf.

java:45: error: variable foundSymbol is already defined in method main(String[])

but I got like 8 of those, 45 and up.
2006 Chevy Cobalt SS/NA 2.4L IL: FEERME7
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon
User avatar
sirricealot
Posts: 841
Joined: Sat Feb 19, 2011 3:35 pm

Need help w/ java class

Post by sirricealot »

After struggling and contacting the teacher numerous times I ended up submitting an assignment that didnt run and wasnt finished, i still managed to get an 80/100 though. Thanks for the help. This week he provided us with some sample code and all we have to do is add to it in order to complete the program, much easier!
2006 Chevy Cobalt SS/NA 2.4L IL: FEERME7
2010 Kawasaki Ninja 250r IL: RUNYON
xbxlive: sirricealot07
ps3: sirricealot7
David Runyon