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...
-
Use Spice to solve the indicated problems and examples. Average power delivered by a 1 mV voltage source to a 1 resistor is 1 W. Apply the 1 mV voltage source to the input of an amplifier with a...
-
Almetals, Inc., a Michigan company, entered into a contract with the German firm Wickeder Westfalenstahl regarding the purchase of clad metal, a specialty metal used in a variety of industries but...
-
Foley Corporation has seven industry segments with total revenues as follows. Penley $600 Cheng $ 225 Konami 650 Takuhi 200 KSC 250 Molina 700 Red Moon 275 Based only on the revenues test, which...
-
CanMS-EXCEL connect to an ORACLE database using JDBC? I've spent an hour finding the answer to the question and I'm still not sure. Could you explain in detail?
-
A shunt-wound dc motor with the field coils and rotor connected in parallel (Fig) operates from a 120-V dc power line. The resistance of the field windings, RI , is 218 .n. The resistance of the...
-
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...
-
Five men, four children and two women are asked to stand in a queue at the post office. Find how many ways they can do this if: a. The women must be separated b. All of the children must be separated...
-
Given the following selected account balances of Sunny Manufacturing, prepare (a) its schedule of cost of goods manufactured and (b) its income statement for the year ended December 31. 1 01:54:17...
-
Perform an online or offline search Times New... 12 BIUA A Directions and Analysis Task 1: Learning About a Technology Firm Perform an online or offline search, and choose a technology firm near your...
-
Q1. Assume that you are charged with the orientation of a cohort of new managers in your organization. Discuss the key individual differences described in this chapter and explain how you would help...
-
Steve Maas, owner of Oliver's Markets, a chain of four regional grocery stores, believes that attention and energy on what to achieve as opposed to what to do makes the work environment at Oliver's...
-
Dushyant Sinha, CEO of Indian Center for Consultancy Private Limited (ICCPL), a public relation firm, was in pensive mood when his team manager presented him satisfaction levels of their past key...
-
A simple trust has the following receipts and expenditures for 2014. The trust instrument is silent with respect to capital gains, and state law concerning trust accounting income follows the Uniform...
-
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...
-
ACC 550 Cost Accounting Module 4-1 Discussion Another Take on Flexible Budgets and Variance Analysis Comprehensive Variance Analysis Based on Ex Post Optimal Budget. The author presents a new...
-
What is a functional group? Why is it important to recognize functional groups in organic chemistry? 2. Draw the structure of octane. 3. Name this compound. 4. When are hyphens and commas used in...
-
list 3 concepts in any subject area (ELA, Math, Science, Social Studies, etc.) that can be illustrated into a simple cartoon for students to explore, expand, or solve. Describe how the cartoon would...
Study smarter with the SolutionInn App