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...
-
In Exercises determine the convergence or divergence of the sequence with the given nth term. If the sequence converges, find its limit. an = COS TTN n
-
What account is debited when a partner withdraws cash for personal use?
-
San Mateo Health Care Inc. is owned and operated by Rachel Fields, the sole stockholder. During January 20Y6, San Mateo Health Care entered into the following transactions: Jan. 1 Received $27,000...
-
Here are the expected cash flows for three projects: Cash Flows (dollars) nts Project Year 0 Year 1 Year 2 Year 3 Year 4 A -5,600 +1,150 +1,150 +3,300 0 B -1,600 0 +1,600 +2,300 eBook +3,300 C -5,600...
-
How many ants will climb on a piece of a peanut butter sandwich left on the ground near an ant hill? To study this, a student in Australia left a piece of a sandwich for several minutes, then covered...
-
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...
-
Imagine that your boss has just asked you to replace the plant manager of a medium-sized facility with 120 employees in South America. Give two (2) theories of work motivation that you would use to...
-
Question 31 (2 points) A while back, I called Glass Unlimited and asked for an estimate to replace nine windows in my house. The seals had broken and each window was at various stages of fogging up....
-
Describe how the Federal Reserve controls the interest rates to stimulate or slow down the economy. is this a productive activity or should the economy be left alone to grow or contract on its own?
-
Use a for loop and the disp command to write 2. Repeat Problem 1 using a while loop. the MATLAB code required to display all integers from 0 to 10 to the Command Window. Write a script below: Write a...
-
The following data is provided for Garcon Company and Pepper Company for the year ended December 31. Finished goods inventory, Garcon Company Company $ Pepper beginning 13,300 18,550 Work in process...
-
Cash equation [LO 18.3] Balarang Lid has an equity value of $ 13 315. Non-current debt is $8200. Net working capital, other than cash, is $2750. Non-current assets are $17 380. How much cash does the...
-
Caroline, age 66 and filing single as a dependent of another, received the following income items for 2016: Social Security benefits (nontaxable)....................................$ 3,000 Pension...
-
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...
-
You are considering the purchase of one of two machines used in your manufacturing plant. Machine A has a life of two years, costs $85 initially, and then requires $130 per year in maintenance costs....
-
Adonis and Eustacia Andino are planning to buy a $200,000 home near Bethel Corners, New York. The home is in "snow country," about a mile from Lake Ontario and is situated on the Salmon River, which...
-
1. Someone needs to borrow $20,000 to buy a car and the person has determined that monthly payments of $350 are affordable. The bank offers a 3-year loan at 5% APR, a 5-year loan at 6%, and a 6-year...
Study smarter with the SolutionInn App