Modify GraphView in Listing 28.6 to add a new data field tree with a set method. The
Question:
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 tree starting from a specified city, as shown in Figures 28.13 and 28.16. If a city not in the map is entered, the program displays an error message in the label.
Listing
Transcribed Image Text:
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
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 30 31 32 // Draw an edge for (i, v) getChildren ().add(new Line(x1, y1, x2, y2)); 33 34 35 36 37 38 } 233 mmm m3mm Seattle (0) Boston (6) Chicago (5) New York (7) Denver (a San Francisco (1) Kansas City (4) Los Angeles (2) Atlanta (8) Dallas (10) Houston (11) Miami (9)
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 82% (17 reviews)
Program Plan Create a class ViewDfsBfs that extends Application class Start method is used to set the stage and display it to the user setOnAction method in Button class is called every time user clic...View the full answer
Answered By
Gauri Hendre
I worked as EI educator for Eduphy India YT channel. I gave online tutorials to the students who were living in the villages and wanted to study much more and were preparing for NEET, TET. I gave tutions for topics in Biotechnology. I am currently working as a tutor on course hero for the biochemistry, microbiology, biology, cell biology, genetics subjects. I worked as a project intern in BAIF where did analysis on diseases mainly genetic disorders in the bovine. I worked as a trainee in serum institute of India and Vasantdada sugar institute. I am working as a writer on Quora partner program from 2019. I writing on the topics on social health issues including current COVID-19 pandemic, different concepts in science discipline. I learned foreign languages such as german and french upto A1 level. I attended different conferences in the science discipline and did trainings in cognitive skills and personality development skills from Lila Poonawalla foundation. I have been the member of Lila poonawalla foundation since 2017. Even I acquired the skills like Excel spreadsheet, MS Office, MS Powerpoint and Data entry.
5.00+
4+ 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...
-
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...
-
Modify Listing 28.1, TestGraph.java, to create a file representing graph1. The file format is described in Programming Exercise 28.1. Create the file from the array defined in lines 8?21 in Listing...
-
The following information provides details of costs, volume and cost drivers for a particular period in respect of ABC plc, a hypothetical company: ( Details Direct Material $25 Cost Direct Labor 4/3...
-
The antibiotic paromomycin binds to a ribosome and induces the same conformational changes in 16S rRNA residues A1492 and A1493 as are induced by codon-anticodon pairing (Fig. 27-32). Propose an...
-
Convert to radian measure. Round the answer to two decimal places. 584
-
Describe a conflict that may arise between the shareholders of a company and the debtholders of the company. Discuss what the debtholders might do to resolve that conflict and explain why you feel...
-
Below are financial statements that have been reformulated using the templates in this chapter. Some items are missing; they are indicated by capital letters. a. Supply the missing numbers using the...
-
Compute the NPV for Project M if the appropriate cost of capital is 7 percent. (Negative amount should be indicated by a minus sig Do not round intermediate calculations and round your final answer...
-
Black Media Inc. owns and operates a large number of news-papers across Canada. On 1 October 20X5, the board of directors voted unanimously to dispose of one of those newspapers, The Daily Con. Black...
-
Given an undirected graph G = (V, E) and an integer k, find an induced subgraph H of G of maximum size such that all vertices of H have a degree > = k, or conclude that no such induced subgraph...
-
Modify Listing 28.10, ConnectedCircles.java, to display sets of connected circles in different colors. That is, if two circles are connected, they are displayed using the same color; otherwise, they...
-
Write in normal form and solve by the simplex method, assuming all x j to be nonnegative. Maximize the daily output in producing x 1 chairs by Process P 1 and x 2 chairs by Process P 2 subject to 3x...
-
Cash Accounts Receivable Inventory Acme Company Balance Sheet As of January 5, 2023 (amounts in thousands) 9,700 Accounts Payable 4,500 Debt 3,800 Other Liabilities Property Plant & Equipment 16,400...
-
Amazon.com has patented the "one-click" ordering innovation, this is an example of a A.) business methods patent B.) copyright C.) trade secret D.) public domain use 0 answers
-
In the example, the first value for the Principal PMT was 199.10 in cell E18. Answers for the questions must follow the example answer. (1-2 use first picture) 1. Calculate the Principal PMT and...
-
installment note, with semiannual interest payments. 1) Calculate the amount of each payment using the PMT function. 2) Prepare the amortization schedule for the loan. Enter a valid Excel formula or...
-
Solve the equation: (x + 10) (3x-1) = - 7x - 118 x =
-
Write a response to the following statement. In General SCHWARTZKOPF's speech to the Cadets he talks about character and competence. As a supervisor of police, how would you portray those traits and...
-
9.Consider the reaction 3NO2(g)+H2O=2HNO3(aq)+NO(g) where Delta H=-137 kJ.How many kilojoules are released when 92.3g of NO2 reacts?
-
Consider the SDN Open Flow network shown in Figure 4.30. Suppose that the desired forwarding behavior for data-grams arriving at s2 is as follows: Any datgrams arriving on input port 1 from hosts h5...
-
What is an essential different between RR and WFQ packet scheduling? Is there a case (Consider the WFQ weights) where RR and WFQ will behave exactly the same?
-
Consider the network setup in Figure 4.25. Suppose that the ISP instead assigns the router the address 24.34.112.235 and that the network address of the home network is 192.168.1/24. a. Assign...
-
Vous avez r cemment t embauch par Scheuer Media Inc. pour estimer le co t de ses actions ordinaires. Vous avez obtenu les donn es suivantes : D _ 1 = 1 , 7 5 $ ; P _ 0 = 4 2 , 5 0 $ ; et g = 7 , 0 0...
-
In maximizing shareholder value international banks tend to operate differently in different countries. Evaluate international bank s risk management procedures when considering foreign direct...
-
amount? 12. Here is an interesting scenario. At age 24, how much do you need to save per month to have a nest egg of $1,000,000 at the age of 50 years old if your rate of return is 6% on the...
Study smarter with the SolutionInn App