Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 29, Problem 29.12PE
Program Plan Intro
Display weighted graphs
Program Plan:
- Create a package “main”.
- Add a java class named “Edge” to the package which is used to get the edges from the graph.
- Add a java class named “Graph” to the package which is used to add and remove vertices, edges.
- Add a java class named “UnweightedGraph” to the package which is used to store vertices and neighbors.
- Add a java class named “WeightedGraph” to the package which is used to get the weighted edges and print the edges.
- Add a java class named “WeightedEdge” to the package which is used to compare edges.
- Add a java class name “Displayable” to the package.
- Declare the functions “get_X ()”, “get_Y ()”, “get_Name ()”.
- Add a java class named “E12” to the package.
- Declare the cities.
- Declare an integer array.
- Create an object for the weighted graph.
- Create a graphview pane.
- Declare “start ()” method that overrides the “start ()” method in the “Application” class.
- Create a scene and place it on the stage.
- Display the stage.
- Declare the class “GraphView”.
- The “Graph” class extends the interface “Displayable”.
- Give the constructor for this class.
- Set the graph and call the function “paint ()”.
- Give function definition for “paint ()”.
- Declare a list that extends Displayable.
- Loop from 0 through size.
- Get the vertices.
- Get the name of the city.
- Add the circle, text and vertices to the pane.
- Loop from 0 through graph size.
- Create a list.
- Loop from 0 through neighbor’s size.
- Get the vertices.
- Inside the “try” block,
- Add the line, text and vertices to the pane.
- Inside the “catch” block,
- Throw the exception.
- Declare a class named “Cities”.
- Declare required variables.
- Give the constructor for this class which sets the name of the city, and the vertices.
- Get and return the co-ordinate of the vertex “x”.
- Get and return the co-ordinate of the vertex “y”.
- Get and return the name of the city.
- Declare function to compare cities.
- Return the value.
- Give the “main ()” method.
- Launch the application.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
please complete the following in JAVA
Implement the graph ADT using the adjacency list structure.
thanks! also posting a similar question for adjacency matrix. have a good day!
Evaluate the following Postfix expression to find the final value. Trace the evaluation using class PostfixEvaluator. Show the operand stack each time it is modified. (Clearly show all steps)
2 3 4 * + 9 7 - /
14.12 NVCC Lab: Count number of subsets of a graph
A graph is made up of a set of nodes called vertices and a set of lines called edges that connect the nodes. Informally, a connected component of a graph is a subset in which each pair of nodes is connected with each other via a path. For example, the following graph consists of two connected components (subsets).
For this assignment, you are required to find out the number of connected components in a graph as specified below:
implement the following method:
public static int countConnectedComponents(String fileName): where fileName is the input data file representing a graph: each line in the data file contains two numbers representing a pair of vertices that are connected (an edge between these two nodes exists). For example, given the following data file:
1 2 1 3 2 3 4 5 6 8 6 7
*Code must be written in JAVA
Chapter 29 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 29.2 - Prob. 29.2.1CPCh. 29.2 - Prob. 29.2.2CPCh. 29.3 - Prob. 29.3.1CPCh. 29.3 - Prob. 29.3.2CPCh. 29.3 - Show the output of the following code: public...Ch. 29.4 - Prob. 29.4.1CPCh. 29.4 - Prob. 29.4.2CPCh. 29.4 - Prob. 29.4.3CPCh. 29.4 - Prob. 29.4.4CPCh. 29.4 - Show the output of the following code: public...
Ch. 29.5 - Prob. 29.5.2CPCh. 29.5 - Prob. 29.5.3CPCh. 29.5 - Prob. 29.5.4CPCh. 29.5 - Prob. 29.5.5CPCh. 29.5 - Prob. 29.5.6CPCh. 29.5 - Show the output of the following code: public...Ch. 29.6 - Prob. 29.6.1CPCh. 29.6 - Prob. 29.6.2CPCh. 29.6 - Prob. 29.6.3CPCh. 29 - (Modify weight in the nine tails problem) In the...Ch. 29 - (Find a minimum spanning tree) Write a program...Ch. 29 - (Create a file for a graph) Modify Listing 29.3,...Ch. 29 - Prob. 29.11PECh. 29 - Prob. 29.12PE
Knowledge Booster
Similar questions
- Using the following instruction below, write a header class for orderedLinkedList with a function of search,insert, insertFirst, insertLast and deleteNode. Use the library to write a c++ program to show an operation on an ordered linked list. - include the orderedLinkedList.h library in the codes - Create main function and include your information details - initialize a list1 and list2 as orderedLinkedList type - Declare a variable num as integer data type - Print out an instruction for user to input a numbers ending with -1 - Get a numbers from user input - Use a while loop to insert the numbers into list1 ending with -1 - Assign the list2 to list1 - Print out the current elements in List 1 and 2 - Get user input for the number to be deleted - Delete the number requested by user in list2 - Print out the elements in the list1 and list2 after delete operationarrow_forwardExplain the role of the back button as it relates to the back stack.arrow_forwardWhat are the effects, if any, of each of the following C++ statements? a. trail = temp->link;trail->link = nullptr;delete last;last = trail;b. temp->link = last;c. first->info = 58;d. q = current->link;current->link = temp;delete q;e. q = p->link->link->link;q->info = 60;f. p->link = temp;arrow_forward
- remove the first task of the to-do list remove a specific task of the to-do listarrow_forwardIdentify the difference between STACK and ARRAY.arrow_forwardplease fill in the blanks please fill in the blanks please fill in the blanks please fill in the blanks please fill in the blanks please fill in the blanks 1. For graph defined by G = (V,E), |E| If the value is less than |V |^2, these graphs are ...... called.. 2. For graph defined by G = (V,E), |E| If the value is close |V |^2, these graphs are ...... called. 3. If displayed using graph adjacency list defined by G = (V,E) …….space, if represented by adjacency matrix........... requires space. 4. When disjoint-sets are performed as a linked-list using a pointer from each node to the cluster representative (header node), the findSet operation, which finds which element belongs to which cluster, is the worst (worst case) ............ time, the worst case (worst case) is the union operation that combines the sets of two given elements ............ time requires (total number of elements is n.). 5. In the previous question, if the union operation is done according to the cluster size,…arrow_forward
- Convert the following expression from infix to postfix and show the contents of Stack and the output expression at each step ((A-((B+C)*D/E))/(F*G+H))arrow_forwardExplain the back stack and back button.arrow_forwardUsing the following instruction below, write a header class for unorderedLinkedList with a function of search, insertFirst, insertLast and deleteNode. Use the library to write a program to show an operation on an unordered linked list. write in C++ program. - Include the unorderedLinkedList.h library in the codes - Initialize a list1 and list2 as unorderedLinkedList type - Declare a variable num as integer data type - Print out an instruction for user to input a numbers ending with -99 - Get a numbers from user input - Use a while loop to insert the numbers into list1 ending with -99 - Print out the current elements in List 1 - Assign list 2 to list 1 - Print out the elements in list 2 - Print the length of list 2 - Get user input for the number to be deleted - Delete the number requested by user in list2 - Print out the elements in the list after delete operation - Print the length of list 2 - Declare the intIt variable to be linked list iterator - Print out the elements in List 1…arrow_forward
- Please convert Mutual Recursion to Java. See attached image. Thank you.arrow_forwardPython Programming:- thislist = ["apple", "banana", "melon", "cherry", "orange", "kiwi", "mango"] # Using the given list above, write a quick python script that## a. First, outputs only the FIRST 3 elements from the list# b. Second, outputs the LAST 3 elements from the list# c. Third, outputs ONLY the elements whose first letter is "m"# d. Last, outputs ONLY the last element from the listarrow_forwardRewrite Example 10.5 (Passing on Stack) using full descending stacks.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning