Question
Use the example Graph.javaPreview the document class and Edge.javaPreview the document class as a starting point for this assignment, you'll need to make your own main class to create an instance of the Graph class.

For this assignment we are going to create a map of a city subway system using a Graph data structure. The Metro Station Map that you'll use for this assignment is here: Assignment 9 - Metro Station Map.PNG

Enter all the information from the Metro Station Map into your Graph following these guidelines:

1) Add the network of stations and the travel times (weights) to the graph. Your graph should be undirected, so your method that creates edges (or connections) should create them in both directions (from u to v and from v to u).

3) Using your Graph object, determine the travel time from station 6 to station 2 when taking the following path: 6,3,1,2

For part 3, DO NOT just sum up the travel times from the Map that was provided. Your code should use the graph you created and follow the path from station to station to sum up the travel times along the way.



graph.java:



import java.util.*;



class Graph

{

// An array of lists of Edge objects

LinkedList<Edge> G[];

// Parameterized constructor

public Graph(int n)

{

G = new LinkedList[n];



}

// Check if node U is connected to node V

public boolean isConnected(int u,int v)

{



}

// For node U, add a new connection to node V, with weight W

// Also add the reverse connection so our Graph is undirected

public void addEdge(int u,int v,int w)

{



}

// Override the java default toString() method so we can print

// our Graph in the format we want

@Override

public String toString()

{



}

}



}

edge.java:



// Edge object that is stored for each connection to another node

class Edge

{

int v,w;

public Edge(int v,int w)

{

this.v=v; this.w=w;

}

@Override

public String toString()

{

return "("+v+","+w+")";

}

}

Verizon LTE 7:34 PM 86% її Assignment 9-Metro Station Map Assignment 9: Graph Metro Station Map with Travel Time in Minutes 2 26 5 13 28 19 38 3 35 1 27 4 Dashboard Calendar To Do Notifications Inbox
Metro Station Map
0 0
Add a comment Improve this question Transcribed image text
Know the answer?
Add Answer to:
Use the example Graph.javaPreview the document class and Edge.javaPreview the document class as a starting point...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the java Graph class below which represents an undirected graph in an adjacency list. How...

    Consider the java Graph class below which represents an undirected graph in an adjacency list. How would you add a method to delete an edge from the graph? // Exercise 4.1.3 (Solution published at http://algs4.cs.princeton.edu/) package algs41; import stdlib.*; import algs13.Bag; /** * The <code>Graph</code> class represents an undirected graph of vertices * named 0 through V-1. * It supports the following operations: add an edge to the graph, * iterate over all of the neighbors adjacent to a vertex....

  • How would I traverse through this graph? Provide example code, please! class Edge {    int src,...

    How would I traverse through this graph? Provide example code, please! class Edge {    int src, dest;    Edge(int src, int dest)    {        this.src = src;        this.dest = dest;    } }; // class to represent a graph object class Graph {    // A list of lists to represent adjacency list    List<List<Integer>> adj = new ArrayList<>();    // Constructor to construct graph    public Graph(List<Edge> edges)    {        // allocate memory for adjacency list        for (int i = 0; i < edges.size(); i++) {            adj.add(i,...

  • I need help with todo line please public class LinkedList { private Node head; public LinkedList()...

    I need help with todo line please public class LinkedList { private Node head; public LinkedList() { head = null; } public boolean isEmpty() { return head == null; } public int size() { int count = 0; Node current = head; while (current != null) { count++; current = current.getNext(); } return count; } public void add(int data) { Node newNode = new Node(data); newNode.setNext(head); head = newNode; } public void append(int data) { Node newNode = new Node(data);...

  • Help !! I need help with Depth-First Search using an undirected graph. Write a program, IN JAVA, ...

    Help !! I need help with Depth-First Search using an undirected graph. Write a program, IN JAVA, to implement the depth-first search algorithm using the pseudocode given. Write a driver program, which reads input file mediumG.txt as an undirected graph and runs the depth-first search algorithm to find paths to all the other vertices considering 0 as the source. This driver program should display the paths in the following manner: 0 to ‘v’: list of all the vertices traversed to...

  • Q) Modify the class Linked List below to make it a Doubly Linked List. Name your...

    Q) Modify the class Linked List below to make it a Doubly Linked List. Name your class DoublyLinkedList. Add a method addEnd to add an integer at the end of the list and a method displayInReverse to print the list backwards. void addEnd(int x): create this method to add x to the end of the list. void displayInReverse(): create this method to display the list elements from the last item to the first one. Create a main() function to test...

  • Hello, i am working on java program which implements Graph as an adjacency list structure. code...

    Hello, i am working on java program which implements Graph as an adjacency list structure. code is the implementation of RailNetwork. i need help to change the code so it could hold String instead of integers. so, for example, Station "Station name" is connected to "Station name" and also i need to add class edge which basically will be a direction for those give stations. so the output will be like "Station name" is connected to "Station name" with "this...

  • When compiling the LinkedList and Iterator class, the following error is being produced: Note: LinkedList.java uses...

    When compiling the LinkedList and Iterator class, the following error is being produced: Note: LinkedList.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Any suggestions? public class LinkedList<T> {    Node<T> itsFirstNode;    Node<T> itsLastNode;    private int size;    public LinkedList() {        itsFirstNode = null;        itsLastNode = null;          size = 0;    }    public Iterator<T> getIterator() {        return new Iterator(this);    }    // THIS WILL NEED...

  • In JAVA Write a method which performs Dijkstra's algorithm on a Graph from a given stating...

    In JAVA Write a method which performs Dijkstra's algorithm on a Graph from a given stating node. It should return a Map containing the shortest distances to each node. You may need to make your own edge class as described in the tutorial to handle weights. public static Map<V.Double diikstra(Graph<V, Es graph, V start)t H

  • Given a singly-linked list interface and linked list node class, implement the singly-linked list which has...

    Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...

  • Templates Apartment.java package hwk7; public class Apartment {    int numOfApartments; // the number of apartments...

    Templates Apartment.java package hwk7; public class Apartment {    int numOfApartments; // the number of apartments of this type    Room[] rooms; // rooms in this type of apartment       Apartment(int numOfApartments, Room[] rooms) {        this.numOfApartments = numOfApartments;        this.rooms = rooms;    }       // Return the window orders for one apartment of this type as TotalOrder object    TotalOrder orderForOneUnit() {        // TODO    }       // Return the window...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT