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...
-
Evaluate each of the given expressions by performing the indicated operations. 10(8)(3) (10 50)
-
What account is debited when a partner withdraws supplies for personal use?
-
Marjorie is a software systems engineer for Hacker Corporation. In November 2008, she inherited two parcels of land in Brower Township from her grandfather. Her grandfathers estate valued the...
-
Question 1 3 ( 1 point ) Li buys a $ 1 0 0 0 0 0 life insurance policy, which requires an annual premium of $ 4 2 0 or a monthly premium of $ 3 7 . In either case, the premium is payable at the...
-
You designed the new database for City Jail. Now you need to create all the tables for the database. First, create all the tables using the information outlined in Section A. Second, make 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...
-
Data warehousing is an important part of most large-scale commercial electronic commerce sites. Assume you are an executive with a leading company like Amazon.com; develop. a list of questions that...
-
Do you support CMS's decision to adopt the "stand-in-the-shoes" amendments to the Stark Law
-
A corporation commenced operations on January 1, 2019. It has the following account balances at December 31, 2019: Accounts Payable $35,000 Accounts 45,000 Receivable Bank Loan 65,000 Building 67,000...
-
(case) Inserting the Team Concept into Compensation or not Questions: What do you believe is the cause of the customer churn? What would you do to stop the customer churn?
-
Metatrend's stock will generate earnings of $6 per share next year. The discount rate for the stock is 15% and the company's ROE is also 15%. Find the growth rate of dividends and the expected stock...
-
Lester is developing a routine business message. He is working on his primary message. How long should it be ? fewer than 1 0 words fewer than 5 words at least 2 5 words between 1 0 and 2 0 words
-
Randall and Dianne Wall live in St. Louis, Missouri. Randall and Dianne are each 30 years old, neither smokes, and they have no children or other dependents. Randall is attending law school full time...
-
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?
-
Bruin, Incorporated, has identified the following two mutually exclusive projects: Year Cash Flow (A) Cash Flow (B) 0 -$ 54,000 -$ 54,000 1 30,000 17,600 2 24,000 21,600 3 4 18,000 26,000 12,800...
-
DR. P is considering a new project based on the information below. What is the Expected NPV of the project? WACC for the project data in thousands 0.074 0 1 2 3 Initial costs 2,654 Prob Scenario 1...
-
Suppose that Bryson Corporation's projected free cash flow for next year is FCF1 = $170,000, and that FCF is expected to grow at a constant rate of 6.5%. If the company's required rate of return on...
Study smarter with the SolutionInn App