From d7e33eaa1e17c3bf36fc98a84a82023a640566b7 Mon Sep 17 00:00:00 2001 From: junnynoriega <117204537+junnynoriega@users.noreply.github.com> Date: Wed, 8 Mar 2023 14:13:35 -0800 Subject: [PATCH 1/6] Create README.md --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..a79c45a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# FinalProject From 06b0629324156e42b8c596f7e9e6b56fd6d053ca Mon Sep 17 00:00:00 2001 From: junnynoriega-arenas Date: Wed, 8 Mar 2023 14:21:23 -0800 Subject: [PATCH 2/6] Added name(author) to Queue --- src/edu/greenriver/sdev333/Queue.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/edu/greenriver/sdev333/Queue.java b/src/edu/greenriver/sdev333/Queue.java index 638d71c..b9e4c45 100644 --- a/src/edu/greenriver/sdev333/Queue.java +++ b/src/edu/greenriver/sdev333/Queue.java @@ -3,6 +3,7 @@ import java.util.Iterator; /** + * @author junnynoriega-arenas * FIFO queue, page 151 of the red book */ public class Queue implements Iterable { From 4a0ad5b0beac67340f815177496594ba9759b985 Mon Sep 17 00:00:00 2001 From: junnynoriega Date: Sat, 25 Mar 2023 19:39:35 -0700 Subject: [PATCH 3/6] Added name to Main.java --- src/Main.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Main.java b/src/Main.java index 3e59c38..258ff9f 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,3 +1,10 @@ +/** + * @Junny Noriega-Arenas + * Final Project Part 1 + * SDEV 333 + * Description: Create two classes that implements the MathSet interface, which represents a mathematical set. + */ + public class Main { public static void main(String[] args) { System.out.println("Hello world!"); From 11d52594717db07056b451359815e7203ccf2891 Mon Sep 17 00:00:00 2001 From: junnynoriega Date: Sat, 25 Mar 2023 20:49:06 -0700 Subject: [PATCH 4/6] Worked on BSTSet.java from in-class 3/8 --- src/edu/greenriver/sdev333/BSTSet.java | 162 +++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 src/edu/greenriver/sdev333/BSTSet.java diff --git a/src/edu/greenriver/sdev333/BSTSet.java b/src/edu/greenriver/sdev333/BSTSet.java new file mode 100644 index 0000000..f2548f7 --- /dev/null +++ b/src/edu/greenriver/sdev333/BSTSet.java @@ -0,0 +1,162 @@ +package edu.greenriver.sdev333; + +import static javax.swing.UIManager.get; + +public class BSTSet> implements MathSet { + // node helper class + private class Node { + private KeyType key; + private Node left; + private Node right; + private int N; + + public Node (KeyType key, int N) { + this.key = key; + this.N = N; + } + } + + // field + private Node root; + + /** + * Puts the specified key into the set. + * + * @param key key to be added into the set + */ + @Override + public void add(KeyType key) { + // starts the recursion + root = add(root, key); + + } + public Node add(Node current, KeyType key) { + // current is the root of the subtree we are looking at + + // we are at where we are supposed to be + if (current == null) { + return new Node(key,1); + } + + int cmp = key.compareTo(current.key); + // cmp will be -1 (negative) if key < current.key + // cmp will be 0 (zero) if key == current.key + // cmp will be +1 (positive) if key > current.key + + if (cmp < 0) { + // go left + current.left = add(current.left,key); + } + else if (cmp > 0) { + // go right + current.right = add(current.right,key); + } + else { + // key already exists, replace the data(val) + current.key = key; + } + + return current; + } + + /** + * Is the key in the set? + * + * @param key key to check + * @return true if key is in the set, false otherwise + */ + @Override + public boolean contains(KeyType key) { + return get(key) != null; + } + + /** + * Is the set empty? + * + * @return true if the set is empty, false otherwise + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Number of keys in the set + * + * @return number of keys in the set. + */ + @Override + public int size() { + return 0; + } + + /** + * Determine the union of this set with another specified set. + * Returns A union B, where A is this set, B is other set. + * A union B = {key | A.contains(key) OR B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to union + * @return the union of this set with other + */ + @Override + public MathSet union(MathSet other) { + return null; + } + + /** + * Determine the intersection of this set with another specified set. + * Returns A intersect B, where A is this set, B is other set. + * A intersect B = {key | A.contains(key) AND B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to intersect + * @return the intersection of this set with other + */ + @Override + public MathSet intersection(MathSet other) { + return null; + } + + /** + * Determine the difference of this set with another specified set. + * Returns A difference B, where A is this set, B is other set. + * A difference B = {key | A.contains(key) AND !B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to difference + * @return the difference of this set with other + */ + @Override + public MathSet difference(MathSet other) { + // create an empty set that will hold the result + MathSet result = new BSTSet(); + + // iterate (walk) through all items in this +// Iterator itr = (Iterator) this.keys(); +// while (itr.hasNext()) { +// KeyType currentKey = itr.next(); +// if (other.contains(currentKey)) { +// result.add(currentKey); +// } +// } + + for (KeyType currentKey: this.keys()) { + if (!other.contains(currentKey)) { + result.add(currentKey); + } + } + + return result; + } + + /** + * Retrieves a collection of all the keys in this set. + * + * @return a collection of all keys in this set + */ + @Override + public Iterable keys() { + return null; + } +} From 330e0d589f7c7dd73ef486ef66fb2c6f5862d037 Mon Sep 17 00:00:00 2001 From: junnynoriega Date: Sat, 25 Mar 2023 22:08:24 -0700 Subject: [PATCH 5/6] Added SCHashSet.java --- src/Main.java | 12 +++ src/edu/greenriver/sdev333/SCHashSet.java | 99 +++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 src/edu/greenriver/sdev333/SCHashSet.java diff --git a/src/Main.java b/src/Main.java index 258ff9f..be3eabc 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,3 +1,8 @@ +import edu.greenriver.sdev333.BSTSet; +import edu.greenriver.sdev333.MathSet; + +import java.util.Scanner; + /** * @Junny Noriega-Arenas * Final Project Part 1 @@ -8,5 +13,12 @@ public class Main { public static void main(String[] args) { System.out.println("Hello world!"); + + String inputString = "S E A R C H E X A M P L E"; + + Scanner input = new Scanner(inputString); + + MathSet st = new BSTSet<>(); + } } \ No newline at end of file diff --git a/src/edu/greenriver/sdev333/SCHashSet.java b/src/edu/greenriver/sdev333/SCHashSet.java new file mode 100644 index 0000000..3e0d9a3 --- /dev/null +++ b/src/edu/greenriver/sdev333/SCHashSet.java @@ -0,0 +1,99 @@ +package edu.greenriver.sdev333; + +public class SCHashSet> implements MathSet { + // field + private int M; + + /** + * Puts the specified key into the set. + * + * @param key key to be added into the set + */ + @Override + public void add(KeyType key) { + + } + + /** + * Is the key in the set? + * + * @param key key to check + * @return true if key is in the set, false otherwise + */ + @Override + public boolean contains(KeyType key) { + return false; + } + + /** + * Is the set empty? + * + * @return true if the set is empty, false otherwise + */ + @Override + public boolean isEmpty() { + return false; + } + + /** + * Number of keys in the set + * + * @return number of keys in the set. + */ + @Override + public int size() { + return 0; + } + + /** + * Determine the union of this set with another specified set. + * Returns A union B, where A is this set, B is other set. + * A union B = {key | A.contains(key) OR B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to union + * @return the union of this set with other + */ + @Override + public MathSet union(MathSet other) { + return null; + } + + /** + * Determine the intersection of this set with another specified set. + * Returns A intersect B, where A is this set, B is other set. + * A intersect B = {key | A.contains(key) AND B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to intersect + * @return the intersection of this set with other + */ + @Override + public MathSet intersection(MathSet other) { + return null; + } + + /** + * Determine the difference of this set with another specified set. + * Returns A difference B, where A is this set, B is other set. + * A difference B = {key | A.contains(key) AND !B.contains(key)}. + * Does not change the contents of this set or the other set. + * + * @param other specified set to difference + * @return the difference of this set with other + */ + @Override + public MathSet difference(MathSet other) { + return null; + } + + /** + * Retrieves a collection of all the keys in this set. + * + * @return a collection of all keys in this set + */ + @Override + public Iterable keys() { + return null; + } +} From cbffef42f3c25b3028209bba36cf15ccd25ae42a Mon Sep 17 00:00:00 2001 From: junnynoriega Date: Sat, 25 Mar 2023 22:55:32 -0700 Subject: [PATCH 6/6] Added FlightRoutesGraph.java --- src/FlightRoutesGraph.java | 75 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/FlightRoutesGraph.java diff --git a/src/FlightRoutesGraph.java b/src/FlightRoutesGraph.java new file mode 100644 index 0000000..ea3cbc8 --- /dev/null +++ b/src/FlightRoutesGraph.java @@ -0,0 +1,75 @@ +import edu.greenriver.sdev333.BSTSet; +import edu.greenriver.sdev333.MathSet; +import edu.greenriver.sdev333.SCHashSet; + +public class FlightRoutesGraph { + // two sets needed to modal a graph (network) + // 1. a set of verticals (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 nodes; + private MathSet edges; + + public FlightRoutesGraph() { + nodes = new BSTSet<>(); // BST ok here b/c strings are comparable + edges = new SCHashSet<>(); // must use HashSet here 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 getNeighbors(String city) { + // create an empty set to hold the results + MathSet 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","ATL"); + // more to go if you want... + + //look for direct flights from JFK + MathSet directJFK = g.getNeighbors("JFK"); + MathSet directFromATL = g.getNeighbors("ATL"); + } +}