Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final Project now working #6

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file not shown.
Binary file added out/production/FinalProject/Main.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
78 changes: 78 additions & 0 deletions src/FlightRoutesGraph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import edu.greenriver.sdev333.BSTSet;
import edu.greenriver.sdev333.MathSet;
import edu.greenriver.sdev333.SeparateChainingHashTable;

import java.util.HashSet;

public class FlightRoutesGraph {
// two sets needed to model a graph (network)
// 1. a set of vertices (points, nodes) - airports
// 2. a set of edges (connections, lines, relationships)
// ^ route between airports

private class Edge {
private String node1;
private String node2;

public Edge(String from, String to) {
node1 = from;
node2 = to;
}
}

private MathSet<String> nodes;
private MathSet<Edge> edges;

public FlightRoutesGraph() {
nodes = new BSTSet<>(); // ok here b/c strings are comparable
edges = new SeparateChainingHashTable<>(); // must use HashSet b/c edges are not comparable
}

public void addNode(String city) {
nodes.add(city);
}

public void addEdge(String city1, String city2) {
Edge connection = new Edge(city1, city2);
edges.add(connection);
}

MathSet<String> getNeighbors(String city) {
MathSet<String> neighbors = new BSTSet<>();

// loop through the edges and check
// if the city is either in node1 or node2
for (Edge e : edges.keys()) {
if (e.node1.equals(city)) {
neighbors.add(e.node2);
}
else if (e.node2.equals(city)) {
neighbors.add(e.node1);
}
}
return neighbors;
}


public static void main(String[] args) {
FlightRoutesGraph g = new FlightRoutesGraph();

// add all the cities first (nodes)
g.addNode("JFK");
g.addNode("ATL");
g.addNode("HOU");
g.addNode("ORD");
g.addNode("DEN");


// add connections between cities
g.addEdge("JFK" , "MCO");
g.addEdge("ATL" , "MCO");
g.addEdge("DEN" , "ORD");
g.addEdge("ORD" , "ATL");

MathSet<String> directFROMJFK = g.getNeighbors("JFK");
MathSet<String> directFromATL = g.getNeighbors("ATL");

}
}
54 changes: 53 additions & 1 deletion src/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
import edu.greenriver.sdev333.BSTSet;
import edu.greenriver.sdev333.MathSet;
import edu.greenriver.sdev333.SeparateChainingHashTable;

public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");

System.out.println("BSTSet tests:");
SeparateChainingHashTable<String> firstSet = new SeparateChainingHashTable<String>();
SeparateChainingHashTable<String> secondSet = new SeparateChainingHashTable<String>();

System.out.println("isEmpty before adding to firstSet: " + firstSet.isEmpty());
firstSet.add("a");
firstSet.add("b");
firstSet.add("c");
firstSet.add("d");
secondSet.add("a");
secondSet.add("e");
secondSet.add("f");
secondSet.add("g");
secondSet.add("h");
System.out.println("Size after adding to firstSet = " + firstSet.size());


// display each key in BST sets
System.out.println("isEmpty after adding string to set: " + firstSet.isEmpty() + " Size is now: " + firstSet.size());
System.out.println("Iterable test - print each key in firstSet with forEach loop");
for (String str : firstSet.keys()) {
System.out.println(str);
}
System.out.println("Second set keys:");
for (String str : secondSet.keys()) {
System.out.println(str);
}

// Union testing
System.out.println("Union:");
MathSet<String> unionSet = firstSet.union(secondSet);
for (String str : unionSet.keys()) {
System.out.println(str);
}
// Intersection testing
System.out.println("Intersection:");
MathSet<String> intersectionSet = firstSet.intersection(secondSet);
for (String str : intersectionSet.keys()) {
System.out.println(str);
}
// Difference testing
System.out.println("Difference:");
MathSet<String> differenceSet = firstSet.difference(secondSet);
for (String str : differenceSet.keys()) {
System.out.println(str);
}


}
}
Loading