In: Computer Science
You will follow a contract-first approach using interfaces. Here are the main specifications of the contract to build the graph application. There are four interfaces.
ILocation: defines a generic interface for any location object
ILocation |
ILocation2D: defines an interface for 2D locations
ILocation2D |
ILocation3D:
ILocation3D |
ICity: defines an interface for City objects.
ICity |
IRoute: define a generic interface for a route.
IRoute |
Here are all interfaces created as per specification:
1. ILocation:
package comaprableinterfaces;
public interface ILocation extends Comparable {
//Empty interfave
}
2. ILocation2D:
package comaprableinterfaces;
//defines an interface for 2D locations
//it extends the generic interface ILocation
public interface ILocation2D extends ILocation {
int x=0;
int y=0;
//gets and sets its x and y coordinates
void setX(int x);
void setY(int y);
int getX();
int getY();
}
3.ILocation3D:
package comaprableinterfaces;
//It extends the interface ILocation2D
public interface ILocation3D extends ILocation2D {
int z=0;
//gets and sets its z coordinate.
void setZ(int z);
int getZ();
}
4.ICity:
package comaprableinterfaces;
//defines an interface for City objects. and is comparable
public interface ICity extends Comparable<ICity> {
String name=null;
ILocation location=null;
/*
* gets and sets the name (String), location (ILocation)
*/
void setName(String name);
void SetLocation(ILocation location);
String getName();
ILocation getLocation();
}
5. IRoute:
package comaprableinterfaces;
import java.util.List;
//define a generic interface for a route
//it is Comparable and can be compared to another IRoute object.
public interface IRoute extends Comparable<IRoute> {
//gets the path as a List of ICity object
List<ICity> path=null;
//returns the length of path as a double
double lengthofPath();
//returns the location of the start location of the path as ILocation object
ILocation startLocationOfPath();
//returns the location of the destination location of the path as ILocation object
ILocation destinationLocationOfPath();
}
All Interface screenshots: