Hi, I'm currently writing a code for my 4th year project at the moment in Java.
To start off I'm first trying to ping two PCs, but I'm at the very beginning of this process.
At the moment I've created a class called Network Address
It will store the Network Address of the PC.
I'm having a problem though, because I cannot print the network add. all at once (because there are 3 full stops in it) I've broken the address up into 4 pieces.
First section = 192.
Second Section = 168.
Third Section = 1.
Fourth = 254
class NetworkAddress {
public double FirstPart; // 1st part of Network Address
public double SecondPart; // 2nd part of Network Address
public double ThirdPart; // 3rd part of Network Address
public double FourthPart; // 4th part of Network Address
public NetworkAddress(double Part1, double Part2, double Part3, double Part4) {
this.FirstPart = Part1;
this.SecondPart = Part2;
this.ThirdPart = Part3;
this.FourthPart = Part4;
}
public String toString(){
return "Network Address = "+FirstPart+SecondPart+ThirdPart+FourthPart;
}
}
import pc.NetworkAddress;
public class Test_PC_Class {
public static void main(String[] args) {
NetworkAddress PC0_IP = new NetworkAddress(192.,168.,1.,254);
System.out.println(PC0_IP);
}
}
The result I get is:
Network Address = 192.0168.01.0254.0
Is there any way of still using the decimal for the double but removing the zero afterwards?
Thank you.
To start off I'm first trying to ping two PCs, but I'm at the very beginning of this process.
At the moment I've created a class called Network Address
It will store the Network Address of the PC.
I'm having a problem though, because I cannot print the network add. all at once (because there are 3 full stops in it) I've broken the address up into 4 pieces.
First section = 192.
Second Section = 168.
Third Section = 1.
Fourth = 254
class NetworkAddress {
public double FirstPart; // 1st part of Network Address
public double SecondPart; // 2nd part of Network Address
public double ThirdPart; // 3rd part of Network Address
public double FourthPart; // 4th part of Network Address
public NetworkAddress(double Part1, double Part2, double Part3, double Part4) {
this.FirstPart = Part1;
this.SecondPart = Part2;
this.ThirdPart = Part3;
this.FourthPart = Part4;
}
public String toString(){
return "Network Address = "+FirstPart+SecondPart+ThirdPart+FourthPart;
}
}
import pc.NetworkAddress;
public class Test_PC_Class {
public static void main(String[] args) {
NetworkAddress PC0_IP = new NetworkAddress(192.,168.,1.,254);
System.out.println(PC0_IP);
}
}
The result I get is:
Network Address = 192.0168.01.0254.0
Is there any way of still using the decimal for the double but removing the zero afterwards?
Thank you.
Last edited: