Revise GraphView in Listing 28.6 to display a weighted graph and a minimum spanning tree for the
Question:
Revise GraphView in Listing 28.6 to display a weighted graph and a minimum spanning tree for the graph in Figure 29.1, as shown in Figure 29.26. The edges in the MST are shown in red.
Listing
Transcribed Image Text:
Seattle Boston 2097.0 983.0 787.0 Chicago 4.0 Neyw York 1331.0 807.0 100a.0 $33.0 Denver 1260.0 1267.0 San Francisco 988.0 599.0 1015.0 Kansas eity 381.0 1663.0 Los Apgcles 864.0 496.0 Atlanta 1435.0 781.0. 810.0 Dallas 239.0 Houstor 661.0 1187.0 Miami 1 import javafx.scene.layout.Pane; 2 import javafx.scene.shape.Circle; 3 import javafx.scene.shape.Line; 4 import javafx.scene.text.Text; 5 6 public class GraphView extends Pane { private Graph extends Displayable> graph; public GraphView(Graph extends Displayable> graph) { this.graph = graph; 10 11 // Draw vertices java.util.List extends Displayable> vertices = graph.getVertices(); for (int i = 0; i < graph.getSize(); i++) { int x = vertices.get(i).getX(); int y = vertices.get(i).getY(); String name = vertices.get(i).getName (); 12 13 14 15 16 17 18 19 20 21 22 23 24 getChildren().add(new Circle(x, y, 16)); // Display a vertex getChildren().add(new Text(x - 8, y - 18, name)); // Draw edges for pairs of vertices for (int i = 0; i < graph.getSize(); i++) { java.util.List
Seattle Boston 2097.0 983.0 787.0 Chicago 4.0 Neyw York 1331.0 807.0 100a.0 $33.0 Denver 1260.0 1267.0 San Francisco 988.0 599.0 1015.0 Kansas eity 381.0 1663.0 Los Apgcles 864.0 496.0 Atlanta 1435.0 781.0. 810.0 Dallas 239.0 Houstor 661.0 1187.0 Miami 1 import javafx.scene.layout.Pane; 2 import javafx.scene.shape.Circle; 3 import javafx.scene.shape.Line; 4 import javafx.scene.text.Text; 5 6 public class GraphView extends Pane { private Graph extends Displayable> graph; public GraphView(Graph extends Displayable> graph) { this.graph = graph; 10 11 // Draw vertices java.util.List extends Displayable> vertices = graph.getVertices(); for (int i = 0; i < graph.getSize(); i++) { int x = vertices.get(i).getX(); int y = vertices.get(i).getY(); String name = vertices.get(i).getName (); 12 13 14 15 16 17 18 19 20 21 22 23 24 getChildren().add(new Circle(x, y, 16)); // Display a vertex getChildren().add(new Text(x - 8, y - 18, name)); // Draw edges for pairs of vertices for (int i = 0; i < graph.getSize(); i++) { java.util.List neighbors = graph.getNeighbors (i); int x1 = graph.getVertex(i).getX(); int yl = graph.getVertex(i).getY(); for (int v: neighbors) { int x2 = graph.getVertex(v).getX(); int y2 = graph.getVertex(v).getY(); 25 26 27 28 29 30 31 32 // Draw an edge for (i, v) getChildren ().add(new Line(x1, yl, x2, y2)); 33 34 35 36 37 38 }
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 69% (13 reviews)
Display Minimum Spanning Tree Program Plan Create two interface classes called AbstractGraph and Graph that contains the common behavior of the classes for Graph and AbstractGraph Crete a class weight...View the full answer
Answered By
Madhur Jain
I have 6 years of rich teaching experience in subjects like Mathematics, Accounting, and Entrance Exams preparation. With my experience, I am able to quickly adapt to the student's level of understanding and make the best use of his time.
I focus on teaching concepts along with the applications and what separates me is the connection I create with my students. I am well qualified for working on complex problems and reaching out to the solutions in minimal time. I was also awarded 'The Best Tutor Award' for 2 consecutive years in my previous job.
Hoping to get to work on some really interesting problems here.
5.00+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Revise GraphView in Listing 28.6 to display a weighted graph. Write a program that displays the graph in Figure 29.1 as shown in Figure 29.25. (Instructors may ask students to expand this program by...
-
Modify GraphView in Listing 28.6 to add a new data field tree with a set method. The edges in the tree are displayed in red. Write a program that displays the graph in Figure 28.1 and the DFS/BFS...
-
Given a graph G and a minimum spanning tree T, suppose that we decrease the weight of one of the edges in T. Show that T is still a minimum spanning tree for G. More formally, let T be a minimum...
-
During the year ended 30 June 20X5, Gem Stone Ltd acquired two areas of interest Site A and Site B. The exploration and evaluation activities at Site A amounted to $64454401. The costs relate to the...
-
In 1889, at Jubbulpore, India, a tug-of-war was finally won after 2 h 41 min, with the winning team displacing the center of the rope 3.7 m. In centimeters per minute, what was the magnitude of the...
-
What are the major lessons you can derive from this exercise? lop2
-
What other steps, aside from home visits and conspicuous monitoring, can be taken by employers to reduce absence levels? Which approach do you think is likely to be most effective? LO9
-
Prepare a skeleton statement of revenues, expenditures, and changes in fund balances using the headings in Illustration 2-11 (e.g., Revenues, Expenditures, and Excess (Deficiency) of Revenues over...
-
Suppose the risk-free return is 6%. The beta of a managed portfolio is 1.5, the alpha is 3%, and the average return Is 18%. Based on Jensen's measure of portfolio performance, you would calculate the...
-
Determine the volume of the solid formed by revolving the shaded area about the x axis using the second theorem of Pappus?Guldinus. The area and centroid of the shaded area should first be obtained...
-
Write a program that reads a connected graph from a file. The graph is stored in a file using the same format specified in Programming Exercise. Your program should prompt the user to enter the name...
-
Write a program that lets the users create a weighted graph dynamically. The user can create a vertex by entering its name and location, as shown in Figure 29.27. The user can also create an edge to...
-
What are some examples of accounting reports in prose form?
-
Ross Co. is an oil and gas company located in the Western United States. Ross follows U.S. GAAP in recording and reporting its financial transactions and has a year-end of 12/31. During the fiscal...
-
The following unadjusted trial balance is for ACE CONSTRUCTION CO. as of the end of its 2017 fiscal year. The June 30, 2016, credit balance of the owners capital account was $57,000, and the owner...
-
Photon Technologies, Inc., a manufacturer of batteries for mobile phones, signed a contract with a large electronics manufacturer to produce three models of lithium-ion battery packs for a new line...
-
Mastery Problem: Capital Investment Analysis HomeGrown Company HomeGrown Company is a chain of grocery stores that are similar to indoor farmer's markets, providing fresh, local produce, meats, and...
-
McDonald's and CSR There more than 32,000 restaurants around the world (www.aboutmcdonalds.com/etc/medialib/csr/docs. that carry the McDonald's label and logo. As such, they...
-
Tom is cooking a large turkey breast for a holiday meal. He wants to be sure that the turkey is safe to eat, which requires a minimum internal temperature of 165F. Tom uses a thermometer to measure...
-
The sales department of P. Gillen Manufacturing Company has forecast sales in March to be 20,000 units. Additional information follows: Finished goods inventory, March 1 . . . . . . . . . . . . . . ....
-
Consider sending a packet from a source host to a destination host over a fixed route. List the delay components in the end-to-end delay. Which of these delays are constant and which are variable?
-
(a) Visit the site www.traceroute.org and perform traceroutes from two different cities in France to the same destination host in the United States. How many links are the same in the two...
-
Consider Figure 1.19(b). Now suppose that there are M paths between the server and the client. Nu two paths share any link. Path k (k = 1,...,M) consists of N links with transmission rates R k 1 , R...
-
Suppose your firm is considering investing in a project with the cash flows shown below, that the required rate of return on projects of this risk class is 8 percent, and that the maximum allowable...
-
A credit union entered a lease contract valued at $ 6100. The contract provides for payments at the end of each month for 8 years. If interest is 4 % compounded quarterly, determine the present value...
-
f(x) - J cincidit f(x) - J cincidit
Study smarter with the SolutionInn App