/* * IPv4address.java * * Created on September 16, 2003, 6:00 PM */ /** * * @author Tazeen */ import java.lang.Integer; public class IPv4address implements address { private int a = 0; private int b = 0; private int c = 0; private int d = 0; /** Creates a new instance of IPv4address */ public IPv4address() { } public IPv4address(int w, int x, int y, int z) throws addressOutOfRangeException { if (!inRange(w)) throw new addressOutOfRangeException(Integer.toString(w)+" is not within 0 and 255"); else if (!inRange(x)) throw new addressOutOfRangeException(Integer.toString(x)+" is not within 0 and 255"); else if (!inRange(y)) throw new addressOutOfRangeException(Integer.toString(y)+" is not within 0 and 255"); else if (!inRange(z)) throw new addressOutOfRangeException(Integer.toString(z)+" is not within 0 and 255"); else { a = w; b = x; c = y; z = z; } } public String toString() { return Integer.toString(a) + "." + Integer.toString(b) + "." + Integer.toString(c) + "." + Integer.toString(d); } public int getA() { return a; } public int getB() { return b; } public int getC() { return c; } public int getD() { return d; } public boolean equals(IPv4address a1) { if ((a1.getA() == getA()) && (a1.getB() == getB()) && (a1.getC() == getC()) && (a1.getD() == getD())) return true; else return false; } private boolean inRange(int x) { return (x>=0) && (x<=255); } }