Question: public class Q4Sources { public Q4Sources() { } /** * Add a pipe to the network. The new pipe does not have any connections. *
public class Q4Sources { public Q4Sources() { } /** * Add a pipe to the network. The new pipe does not have any connections. * The method should return the id of the new pipe. */ public int add() { // FIXME return -1; } /** * Add a pipe to the network with an incoming connection from an * already existing pipe in the network, if this does not break any * of the network rules: * - pipe fromPipeId must be one that exists in the network (previously * added and not removed); and * - pipe fromPipeId must have at most 2 already existing outgoing * connections. * * If adding the new pipe would break these rules, the method should * not add the pipe, and return -1. Otherwise, the method should update * the network and return the id of the new pipe. */ public int addFrom(int fromPipeId) { // FIXME return -1; } /** * Add a pipe to the network with an outgoing connection to an * already existing pipe in the network, if this does not break any * of the network rules: * - pipe toPipeId must be one that exists in the network (previously * added and not removed); and * - pipe toPipeId must have at most 2 already existing incoming * connections. * * If adding the new pipe would break these rules, the method should * not add the pipe, and return -1. Otherwise, the method should update * the network and return the id of the new pipe. */ public int addTo(int toPipeId) { // FIXME return -1; } /** * Remove a pipe from the network. This also removes all connections to * and from the pipe (but not the pipes it is connected to). * * If the pipeId does not exist in the network (has not been added or * has already been removed) then the method should not do anything. */ public void remove(int pipeId) { // FIXME } /** * Return the number of sources in the network. * * A source is a pipe that has no incoming connections. */ public int nSources() { // FIXME return 0; } } // Warning do not modify the parameters of the methods you need to implement! // Try using ArrayLists and other Collection data types.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
