The switch case always runs the default code. I read something about a "new line" issue, but i think that is not the case here. Because i copy the first char from the "stringclient" string into a char variable. But when i run this with my ATMServer class in eclpise, it's working just fine. Only when i execute them from cmd, this problem appears. So anyone knows what's going on? Please help. Thanks.
import java.io.*;
import java.net.*;
public class ATMClient {
private static final int PORT = 20000;
private static final char DRAW_STR = 'Α';
private static final char DEPOSIT_STR = 'Κ';
private static final char BALANCE_STR = 'Υ';
private static final char EXIT_STR = 'Ε';
private static boolean hasEnded = false;
public static void main(String args[]) throws IOException {
Socket dataSocket = new Socket("localhost",PORT);
InputStream is = dataSocket.getInputStream();
BufferedReader in = new BufferedReader(new InputStreamReader(is));
OutputStream os = dataSocket.getOutputStream();
PrintWriter out = new PrintWriter(os, true);
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
String stringclient;
while(!hasEnded){
printMenu();
stringclient = input.readLine();
char optionCode = stringclient.charAt(0);
String tempData;
int amount;
switch(optionCode){
case EXIT_STR:
out.println(String.valueOf(EXIT_STR));
hasEnded = true;
continue;
case DRAW_STR:
tempData = stringclient.substring(1);
try{
amount = Integer.parseInt(tempData);
}catch(NumberFormatException e){
System.out.println("Το ποσό πρέπει να είναι αριθμός. Δοκιμάστε ξανά.");
System.out.println();
continue;
}
if(amount > 420){
System.out.println("Μπορείτε να κάνετε ανάληψη έως 420 ευρώ.");
System.out.println();
continue;
}
out.println(String.valueOf(DRAW_STR) + amount);
break;
case DEPOSIT_STR:
tempData = stringclient.substring(1);
try{
amount = Integer.parseInt(tempData);
}catch(NumberFormatException e){
System.out.println("Το ποσό πρέπει να είναι αριθμός. Δοκιμάστε ξανά.");
System.out.println();
continue;
}
out.println(String.valueOf(DEPOSIT_STR) + amount);
break;
case BALANCE_STR:
out.println(String.valueOf(BALANCE_STR));
break;
default:
System.out.println("Λάθος επιλογή. Δοκιμάστε ξανά.");
System.out.println();
continue;
}
String reply = in.readLine();
System.out.println(reply);
}
out.close();
os.close();
in.close();
is.close();
input.close();
dataSocket.close();
}
}