Skip to content
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.

73 changes: 73 additions & 0 deletions src/FlightRoutesGraph.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import edu.greenriver.sdev333.BSTSet;
import edu.greenriver.sdev333.MathSet;

import java.util.HashMap;
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<>();
// edges = new HashSet<>();
}

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("ORD");
g.addNode("ATL");
g.addNode("MCO");
g.addNode("DEN");

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

//look for direct flights from JFK
MathSet<String> directFromJFK = g.getNeighbors("JFK");
MathSet<String> directFromATL = g.getNeighbors("ATL");

}
}
149 changes: 148 additions & 1 deletion src/Main.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,152 @@
import edu.greenriver.sdev333.*;

/**
* @author Bao Huynh
* Date: 03/15/2023
* Class: SDEV333
* FINAL PROJECT
*/
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
//Create 2 sets
// add items to each of the sets (some same, some different)
//Test
//set intersection
//set union
//set different

MathSet<String> set1 = new BSTSet<>();
MathSet<String> set2 = new BSTSet<>();

//add elements to the sets
set1.add("1");
set1.add("2");
set1.add("3");
set1.add("4");
set1.add("5");

set2.add("1");
set2.add("6");
set2.add("7");

System.out.print("SET A: ");
for(String num : set1.keys()){
System.out.print(num + " ");
}


System.out.print("\nSET B: ");
for(String num : set2.keys()){
System.out.print(num + " ");
}

//Test contains
System.out.println("\nSET A contains number 1? " + set1.contains("1"));
System.out.println("SET B contains number 1? " + set2.contains("1"));

//Test size
System.out.println("SET A size: " + set1.size());
System.out.println("SET B size: " + set2.size());

//Test isEmpty
System.out.println("SET A empty? " + set1.isEmpty());
System.out.println("SET B empty? " + set2.isEmpty());

//Test Union
//union set a and set b, save into result1
MathSet<String> result1 = set1.union(set2);
System.out.print("UNION SET A and SET B: ");
for (String num : result1.keys()){
System.out.print(num + " ");
}

//Test Intersection
MathSet<String> result2 = set1.intersection(set2);
System.out.print("\nINTERSECTION SET A and SET B: ");
for (String num : result2.keys()){
System.out.print(num + " ");
}

//Test Different
MathSet<String> result3 = set1.difference(set2);
System.out.print("\nDIFFERENCE SET A and SET B: ");
for (String num : result3.keys()){
System.out.print(num + " ");
}

MathSet<String> result4 = set2.difference(set1);
System.out.print("\nDIFFERENCE SET B and SET A: ");
for (String num : result4.keys()){
System.out.print(num + " ");
}

System.out.println("\n------------------------------------------");
MathSet<String> set3 = new SeparateChainingHashTable<>(20);
MathSet<String> set4 = new BSTSet<>();

set3.add("Dog");
set3.add("Cat");
set3.add("Chicken");

set4.add("Fish");
set4.add("Pig");
set4.add("Wolf");
set4.add("Chicken");
set4.add("Bird");

System.out.print("SET C: ");
for(String num : set3.keys()){
System.out.print(num + " ");
}


System.out.print("\nSET D: ");
for(String num : set4.keys()){
System.out.print(num + " ");
}

//Test contains
System.out.println("\nSET C contains Fish? " + set3.contains("Fish"));
System.out.println("SET D contains Fish? " + set4.contains("Fish"));

//Test size
System.out.println("SET C size: " + set3.size());
System.out.println("SET D size: " + set4.size());

//Test isEmpty
System.out.println("SET C empty? " + set3.isEmpty());
System.out.println("SET D empty? " + set4.isEmpty());

//Test Union
//union set c and set d, save into result5
MathSet<String> result5 = set3.union(set4);
System.out.print("UNION SET C and SET D: ");
for (String num : result5.keys()){
System.out.print(num + " ");
}

//Test Intersection
MathSet<String> result6 = set3.intersection(set4);
System.out.print("\nINTERSECTION SET C and SET D: ");
for (String num : result6.keys()){
System.out.print(num + " ");
}

//Test Different
MathSet<String> result7 = set3.difference(set4);
System.out.print("\nDIFFERENCE SET C and SET D: ");
for (String num : result7.keys()){
System.out.print(num + " ");
}

MathSet<String> result8 = set4.difference(set3);
System.out.print("\nDIFFERENCE SET D and SET C: ");
for (String num : result8.keys()){
System.out.print(num + " ");
}




}
}
Loading