Revise GraphView in Listing 28.6 to display a weighted graph. Write a program that displays the graph
Question:
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 adding new cities with appropriate edges into the graph).
Listing
Transcribed Image Text:
Scattle 2097.0 Boston .0 Ney York 983.0 787.0 Chicago 1331.0 $07.0 190a:0 Denver $33.0 1260.0 1267.0 San Francisco 988.0 599.0 1015.0 Kansas eity 381.0 1663.0 bos Apgcles 864.0 496.0 Atlanta 1435.0 781.0 810:0 Dallas 239.0 Houston 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
Scattle 2097.0 Boston .0 Ney York 983.0 787.0 Chicago 1331.0 $07.0 190a:0 Denver $33.0 1260.0 1267.0 San Francisco 988.0 599.0 1015.0 Kansas eity 381.0 1663.0 bos Apgcles 864.0 496.0 Atlanta 1435.0 781.0 810:0 Dallas 239.0 Houston 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: 83% (12 reviews)
To display the weight the following modifications are made After getting the neighbors for the given ...View the full answer
Answered By
PALASH JHANWAR
I am a Chartered Accountant with AIR 45 in CA - IPCC. I am a Merit Holder ( B.Com ). The following is my educational details.
PLEASE ACCESS MY RESUME FROM THE FOLLOWING LINK: https://drive.google.com/file/d/1hYR1uch-ff6MRC_cDB07K6VqY9kQ3SFL/view?usp=sharing
3.80+
3+ 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
-
Write a program that displays the result of 9.5 4.5 2.53 2.5 3 45.5 3.5
-
Write a program that displays the following table: a 1 2 3 4 aA2 1 16 aA3 1 8 27 64
-
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 Seattle...
-
Power Company acquired 80 percent of Solar Company's outstanding common stock for $200,000 cash on January 2, 2021. The two companies continued to operate as separate entities after the combination....
-
From January 26, 1977, to September 18, 1983, George Meegan of Great Britain walked from Ushuaia, at the southern tip of South America, to Prudhoe Bay in Alaska, covering 30 600 km. In meters per...
-
Write data statements for the sources shown in Fig. 15-13. 1 3 Independent ac voltage source V, (t)=14 cos (@t+45) Independent ac current source i, (t) = 2.3 cos (ot-105) 2 4
-
A significant issue when a contract is breached is whether the cause of action is strictly in breach of contract or may be expanded to negligence and strict liability. The significance comes into...
-
Intangible Amortization Presented below is selected information for Palmiero Company. 1. Palmiero purchased a patent from Vania Co. for $1,500,000 on January 1, 2008. The patent is being amortized...
-
Business Firms have to experience various types of costs in producing their products or in providing their services. Explain the basis of costs classification as "Direct-Indirect" and...
-
Compare and contrast the feminist views of Simone de Beauvoir, Charlotte Perkins, and Audre Lorde. In what way do you think the time-frame in which they wrote impacted their views?
-
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...
-
Solve the IVP. Show the details of your work. y"' + 5y" + 24y' + 20y = x, y(0) = 1.94, y'(0) = -3.95, y" = -24
-
Will a VAT registered taxpayer have a VAT still due from his sales transaction with the government? Discuss and support your answer.
-
S Problem 5-23 (Algo) CVP Applications; Contribution Margin Ratio: Degree of Operating Leverage [LO5- 1, LO5-3, LO5-4, LO5-5, LO5-8] Feather Friends, Incorporated, distributes a high-quality wooden...
-
which one do you believe would best support/ or be utilized a SMD? What would be the ripple effect of an organization NOT measuring employee engagement? Explain at least 4 reasons.
-
Guiding questions: - - Identify the major challenges and implications for the HR practitioner in relation to your chosen topic. Explain the importance of constructive negotiation skills in managing...
-
Who knows how clean a water bottle is? It's pretty dark in most of them! GPS Marketers was asked to help market a new water bottle that has an ultraviolet light in the lid to kill mold, bacteria, and...
-
A simple trust had a long-term capital loss of $10,000 for 2013 and a long-term capital gain of $15,000 for 2014. Its net accounting income and DNI are equal. Explain the tax treatment for the 2013...
-
A number of years ago the United Food and Commercial Workers Union organized 800 workers of the 1035 employees at one of the Wilson Brothers food operations in Toronto, Ontario. The employees include...
-
(a) Suppose N packets arrive simultaneously to a link at which no packets are currently being transmitted or queued. Each packet is of length L and the link has transmission rate R. What is the...
-
Why will two ISPs at the same level of the hierarchy often peer with each other? How does an TXP earn money?
-
Some content providers have created their own networks. Describe Googles network. What motivates content providers to create these networks?
-
(a). In the context of Current Cost Accounting (CCA), briefly explain the meaning of the following terms. (i). Monetary working capital adjustment (2 marks) (ii). Gearing adjustment (2 marks)(b)....
-
How do laws originate? Explain the differences between various sources of law and describe the branches of government and their roles in creating, administering, and enforcing the law. In addition,...
-
1. Match the part of the microscope to the description on the right. 2. What is the total magnification if the ocular lens is 10x, and the objective lens is 100x? Show the calculations. 10 x 100 = 3....
Study smarter with the SolutionInn App