Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public boolean connect(java.lang.String city1, java.lang.String city2) If city1 and city2 are in the network, then connect them via a road. Returns true if, at the

public boolean connect(java.lang.String city1, java.lang.String city2) 

If city1 and city2 are in the network, then connect them via a road. Returns true if, at the end of the method, id1 and id2 are connected (which could mean they were connected before this method was invoked), and returns false otherwise (which really would only happen if city1 or city2 were not a member in the network.

Parameters:

city1 - the name of one city

city2 - the name of another city

Returns:

true if city1 and city2 are connected directly in the network, and false otherwise.

disconnect

public void disconnect(java.lang.String city1, java.lang.String city2) 

Removes city1 from city2's directly connected city list, and removes city2 from city1's directly connected list. Does nothing city1 or city2 are not members, or if they are members but are not directly connected.

Parameters:

city1 - the name of one city

city2 - the name of another city

areDirectlyConnected

public boolean areDirectlyConnected(java.lang.String city1, java.lang.String city2) 

Determines whether two cities are connected directly via a road or not.

Parameters:

city1 - the name of one city

city2 - the name of another city

Returns:

true if cities are directly connected, and false otherwise

areConnected

public boolean areConnected(java.lang.String city1, java.lang.String city2) 

Determines whether two cities are connected directly or through a chain of roads or not.

Parameters:

city1 - the name of one city

city2 - the name of another city (not necessarily different)

Returns:

true if cities are connected, and false otherwise

import java.util.ArrayList; import java.util.Arrays;

public class RoadNetwork {

private String [] data; private int size; public static int DEFAULT_CAPACITY = 500;

//Constructors public RoadNetwork() { data = new String[DEFAULT_CAPACITY]; size = 0; }

public RoadNetwork(int maxSize) { data = new String[maxSize]; size = 0; }

//Methods public boolean addCity(String name) { if(size >= data.length) { return false; } else { data[size] = name; size++; return true; }

}

public void removeCity(String name) { for(int i = 0; i < size; i ++) { if(name.equals(data[i])) { data[i] = data[size - 1]; data[size - 1] = null; size --; } } }

public boolean containsCity(String name) { for(int i = 0; i < size; i ++) { if(name.equals(data[i])) { return true; } } return false; }

public int getCityCount() { return size;

}

public String[] getCities() { return data;

}

//create new arrayList of all the cities and put connected cities into the arrayList public boolean connect(String city1, String city2) {

//complete method } //go to city1 list and remove city2 and go to city2 list and remove city1 public void disconnect(String city1, String city2) {

//complete method } //If there are any line that gets you from one city to another public boolean areConnected(String city1, String city2) {

//complete method

} // within the arrayList of the single city public boolean areDirectlyConnected(String city1, String city2) { //complete method }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions

Question

(Appendix) What are sales returns? Why do sales returns occur? LO86

Answered: 1 week ago

Question

The amount of work I am asked to do is reasonable.

Answered: 1 week ago

Question

The company encourages a balance between work and personal life.

Answered: 1 week ago