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: 80% (15 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...
-
A manufacturing plant makes two types of inflatable boatsa two-person boat and a four-person boat. Each two-person boat requires 0.9 labor-hour in the cutting department and 0.8 labor-hour in the...
-
Nationwide Insurance developed a program to recruit new insurance agents by offering planning, training, and start-up financing to build self-sustaining agencies. These new agents would be...
-
Bertha's Bathworks produces hair and bath products. Its biggest customer is a national retail chain that specializes in such products. Bertha Jackson, the owner of Bertha's Bathworks, would like to...
-
1. You invest $2000 in an account that pays simple interest of 7% for 10 years. The amount of money you'll have at the end of 10 years is: 2. Use the compound interest formula to determine the...
-
Use google to find out how CA RE taxes are prorated (references sources!). Suppose any tax payments are made on the due date, and the annual tax bill is $12,000. Compute who owes who (seller vs...
-
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...
-
Zinc metal can be obtained from zinc oxide, ZnO, by reaction at high temperature with carbon monoxide, CO. ZnO(s) + CO(g) Zn(s) + CO2(g) The carbon monoxide is obtained from carbon. 2C(s) + O2(g) ...
-
Choose Any portfolio (Jeff's or Betty's) and calculate: (1) The expected return on the portfolio (ii) The standard deviation of the portfolio [2 marks] [5 marks]
-
You are considering a new product launch. The project will cost $750,000, have a four-year life, and have no salvage value; depreciation is straight-line to zero. Sales are projected at 210 units per...
-
Consider that Microsoft has the following EPS projections and payout ratio expectations from 2023 to 2026 Dividend pay-out EPS 0 2023 Recall that the 2-stage DDM formula is: and that: = 10.50 a)...
-
What kind of bet does this security represent? Note that D(0)=20, D(10)=20, D(30)=0, D(50)=20, and D(60)=20. Payoff 20 20 10 0 10 20 30 40 50 60 ST
-
If f(x) is a linear function, f(-1)=1, and f(1)=-3, find an equation for f(x) f(x)= Question Help: Video Submit Question Jump to Answer
-
For the past four years, three companies have dominated the soft drink industry, holding a combined 85 percent of market share. Won Cola, Inc., ranks second nationally in soft drink sales. Its...
-
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...
-
15.5 kg is moving due east with a speed VA = 7.80 m/s, while object (B) of mass mB = 30.0 kg is moving in a direction that makes angle of 58 north of east with a speed VB = 5.20 m/s. The two objects...
-
An object is launched horizontally from the top of a cliff with an initial speed of 1 5 m / s . When the obiect has traveled a horizontal distance of 4 0 meters, how far below the launch point is the...
-
200 cubic metres of hot humid air are being cooled. The original air is at 33.5 degrees Celsius and has a relative humidity of 70%. It is cooled to 20 degrees Celsius. How much water condenses from...
Study smarter with the SolutionInn App