Answer the question
In order to leave comments, you need to log in
Why doesn't [Getters and Setters] work?
there are 2 files.
String IP must change. but it doesn't happen, why?
THE CODE
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Client
{
private BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
private static String IP;
public Client() throws IOException
{
IP = "192.168.1.5";
index(IP);
}
public static void setIP(String IP)
{
Client.IP = IP;
}
private void index(String IP) throws IOException
{
System.out.print("What do you want to do? --> ");
String command = reader.readLine();
if (command.equals("Change my IP adress"))
{
System.out.println("Your IP before changing: "+getIP());
new Soft(IP);
System.out.println("Your IP after changing: "+getIP());
}
}
public static String getIP()
{
return IP;
}
public static void main(String[] args) throws IOException
{
new Client();
}
}
import java.util.Random;
public class Soft
{
private String IP;
Random rand = new Random();
public Soft(String IP)
{
this.IP = IP;
changeMyIPAdress(IP);
}
private void changeMyIPAdress(String IP)
{
this.IP = rand.nextInt(200)+"."+rand.nextInt(200)+"."+rand.nextInt(200)+rand.nextInt(200);
Client.setIP(IP);
}
}
Answer the question
In order to leave comments, you need to log in
To catch such errors, use the debug mode:
private void changeMyIPAdress(String IP)
{
this.IP = rand.nextInt(200)+"."+rand.nextInt(200)+"."+rand.nextInt(200)+rand.nextInt(200);
Client.setIP(IP); // Client.set(this.IP);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question