My question is about duplicate print, received from the code below
package Project_Package;
import java.io.*;
import java.net.*;
import java.util.Scanner;
class TCPClient_with_serialized {
public static void main(String argv[]) throws Exception {
String Result = null;
Object s = null;
Object l = null;
Info Detail = null;
int Sign=0;
String Type, username, password;
Socket clientSocket = new Socket("localhost", 10000);
Scanner inFromUser = new Scanner(System.in);
ObjectOutputStream outToServer = new
ObjectOutputStream(clientSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));
while (true) {
System.out.println("----Choose user interface:----");
System.out.println("#1 House Committee");
System.out.println("#2 Tenant");
Type = inFromUser.nextLine();
switch (Type) {
case "1":
break;
case "2":
System.out.println("----Dear Tenant:----");
System.out.println("#1 Login With your Username and Password");
System.out.println("#2 Change your password");
String Choise = inFromUser.next();
if (Choise.matches("1")) {
System.out.println("enter Username");
username = inFromUser.next();
System.out.println("enter Password");
password = inFromUser.next();
Detail = new Info(username, password, Type, Choise);
outToServer.writeObject(Detail);
String modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
if (modifiedSentence.matches("Ok")) {
System.out.println("----Dear Tenant:----");
System.out.println("#1 Would you like to see your payments");
System.out.println("#2 Would you like to complain about a flaw");
Sign = inFromUser.nextInt();
outToServer.writeInt(Sign);
if (Sign==1) {
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
}
}
}
if (Choise.matches("2")) {
System.out.println("enter Username");
username = inFromUser.next();
System.out.println("enter your New Password");
password = inFromUser.next();
Detail = new Info(username, password, Type, Choise);
outToServer.writeObject(Detail);
String modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: " + modifiedSentence);
break;
}
default:
break;
}
}
}
}
So the problem appears in the next part below that part of code been printed twice in scenario that the user/client clicked 2 and then 3, instead of once.
I think that the problem is in the break
statement inside the loops
but I am not sure of that.
("----Choose user interface:----");
("#1 House Committee");
("#2 Tenant");