AnthonyCosenza
asked on
Returning
ok heres another interesting situation....
ok i figured out the problem wit my while loop but now i hav returnin to.
for example...
the user enters "find"
....
} else if (userIn.startsWith("find") ) {
clt.finding(userIn);
....
this part of the while loop is ran which calls the finding method
which is:
public void finding (String findWhat) {
if (findWhat.equals("find")) {
System.out.println("Unknow n command");
} else {
System.out.println("Findin g");
}
}
now, after the method is called it prints out fine but i then need the program to go back to the while loop so that the user can keep usin the program... for example... if they want to quit they type "quit"
Thanks again..
ok i figured out the problem wit my while loop but now i hav returnin to.
for example...
the user enters "find"
....
} else if (userIn.startsWith("find")
clt.finding(userIn);
....
this part of the while loop is ran which calls the finding method
which is:
public void finding (String findWhat) {
if (findWhat.equals("find")) {
System.out.println("Unknow
} else {
System.out.println("Findin
}
}
now, after the method is called it prints out fine but i then need the program to go back to the while loop so that the user can keep usin the program... for example... if they want to quit they type "quit"
Thanks again..
for example bySomeMeansGetValue method should be something like this
public String bySomeMeansGetValue()
{
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.i n));
String str = "";
while (str != null) {
str = in.readLine();
return str;
}
} catch (IOException e) {
}
return null;
}
public String bySomeMeansGetValue()
{
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.i
String str = "";
while (str != null) {
str = in.readLine();
return str;
}
} catch (IOException e) {
}
return null;
}
ASKER
the problem with the if statement has been solved already... the problem is now tryin to get back from the other methods, for example.. finding().. so those two comments dont really help sorry
This should definately solve ur problem
If userIn starts with find then compulsory it calls finding method.
Could u elaborate ur problem??
boolean first = true;
while (userIn != null) {
//read userIn value
userIn=bySomeMeansGetValue ();
if (userIn.startsWith("quit") ) {
break;
}
else if (userIn.startsWith("find") ) {
clt.finding(userIn);
}
}
If userIn starts with find then compulsory it calls finding method.
Could u elaborate ur problem??
boolean first = true;
while (userIn != null) {
//read userIn value
userIn=bySomeMeansGetValue
if (userIn.startsWith("quit")
break;
}
else if (userIn.startsWith("find")
clt.finding(userIn);
}
}
ASKER
ok, this is wat i now have for the while loop... this seems to solve the problem that i was having before:
InputStreamReader in = new InputStreamReader(System.i n);
BufferedReader readIn = new BufferedReader(in);
String userIn;
while ((userIn = readIn.readLine()) != null) {
.....
} else if (userIn.startsWith("find") ) {
clt.finding(userIn);
} ....
}
and the finding() method is:
public void finding (String findWhat) {
if (findWhat.equals("find")) {
System.out.println("Unknow n command");
} else {
System.out.println("Findin g");
}
}
the problem i am havin now is if the "find" command is entered by the user it goes into the while loop, runs the method and then it isnt possible to run any other commands eg "quit"
do u understand my problem now??
InputStreamReader in = new InputStreamReader(System.i
BufferedReader readIn = new BufferedReader(in);
String userIn;
while ((userIn = readIn.readLine()) != null) {
.....
} else if (userIn.startsWith("find")
clt.finding(userIn);
} ....
}
and the finding() method is:
public void finding (String findWhat) {
if (findWhat.equals("find")) {
System.out.println("Unknow
} else {
System.out.println("Findin
}
}
the problem i am havin now is if the "find" command is entered by the user it goes into the while loop, runs the method and then it isnt possible to run any other commands eg "quit"
do u understand my problem now??
This is working perfectly at my end
public static void finding(String findWhat) {
if (findWhat.equals("find")) {
System.out.println("Unknow n command");
} else {
System.out.println("Findin g");
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
// TODO code application logic here
InputStreamReader in = new InputStreamReader(System.i n);
BufferedReader readIn = new BufferedReader(in);
String userIn="";
while ((userIn = readIn.readLine()) != null) {
if(userIn.startsWith("quit ")) {
break;
} else if (userIn.startsWith("find") ) {
finding(userIn);
}
}
}
public static void finding(String findWhat) {
if (findWhat.equals("find")) {
System.out.println("Unknow
} else {
System.out.println("Findin
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
// TODO code application logic here
InputStreamReader in = new InputStreamReader(System.i
BufferedReader readIn = new BufferedReader(in);
String userIn="";
while ((userIn = readIn.readLine()) != null) {
if(userIn.startsWith("quit
break;
} else if (userIn.startsWith("find")
finding(userIn);
}
}
}
ASKER
can u do a quit command after a find??
yes, what is the problem you are getting??
ASKER
thats strange.......
once i do the find command i cant run a quit command or any of the other commands..
very puzzled.. :S
once i do the find command i cant run a quit command or any of the other commands..
very puzzled.. :S
ASKER
Like i enter them but there is no result..
eg.. i can enter "quit" but it doesnt go and quit the program usin the method i hav created for it... it just goes onto the next line of the user input
eg.. i can enter "quit" but it doesnt go and quit the program usin the method i hav created for it... it just goes onto the next line of the user input
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Make sure you don't have unwanted whitespace
while ((userIn = readIn.readLine()) != null) {
userIn = userIn.trim();
if (userIn.startsWith("quit") ) {
break;
}
else if userIn.startsWith("find")) {
finding(userIn);
}
else {
System.out.println("Invali d command");
}
}
}
while ((userIn = readIn.readLine()) != null) {
userIn = userIn.trim();
if (userIn.startsWith("quit")
break;
}
else if userIn.startsWith("find"))
finding(userIn);
}
else {
System.out.println("Invali
}
}
}
ASKER
I actually found the problem a little later last nite..
It had to do with my close method which "quit" command calls not closing the socket properly.
Thanks for all ur help guys
It had to do with my close method which "quit" command calls not closing the socket properly.
Thanks for all ur help guys
while (userIn != null) {
if (userIn.startsWith("quit")
break;
}
else if (userIn.startsWith("find")
clt.finding(userIn);
}
else {
if( first ) {
.... extra statement ....
eg. System.out.println("testin
first = false;
}
}
//read userIn value
userIn=bySomeMeansGetValue
}