Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
11th Edition
ISBN: 9780134694511
Author: Liang, Y. Daniel
Publisher: Pearson Education Canada
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 28, Problem 28.4PE
Program Plan Intro
Find connected components
Program Plan:
Exercise.java:
- Import the required packages.
- Create a class “Exercise”:
- Define the main method
- Define and declare the vertices.
- Define and declare the edges.
- New graph gets created.
- Perform depth first search on the list.
- Display the connected components of the graph.
- Define the main method
- Define and create the class “MyGraph”
- Create a new constructor.
- New graph gets using the constructor.
- Method to find “getConnectedComponents()” gets created.
- New list gets created.
- Loop that iterates to add the vertices into the list.
- Loop that iterates to add the neighbor vertices into the list.
- Loop that iterates to perform a depth first search.
- Add the values to the list.
- Remove all the values from the list.
- Finally return the list.
UnweightedGraph.java:
- Import the required packages.
- Create a class “UnweightedGraph”:
- New list for the vertices gets created.
- New list for the neighbor node gets created.
- Create an empty constructor.
- Method to create new graph gets created and adjacency list gets created.
- Method to create an adjacency list gets created.
- Method to return the size of the vertices.
- Method to return the index of the vertices gets defined.
- Method to gets the neighbor node gets defined.
- Method to return the degree of the vertices gets created.
- Method to print the Edges gets created.
- New to clear the graph gets created.
- Method to add vertex gets created.
- Method to add edge gets created.
- Method to perform the depth first search gets defined.
- Method to perform breadth first search gets defined.
- Search tree gets returned.
- Create a class “SearchTree”
- Define the method to return the root.
- Method to return the parent of the vertices
- Method to return the search order gets defined.
- Method to return the number of vertices found gets defined.
- Method to get the path of the vertices gets defined.
- Loop to validate the path gets defined.
- Path gets returned.
- Method to print the path gets defined.
- Method to print the tree gets defined.
- Display the edge.
- Display the root.
- Condition to validate the parent node to display the vertices gets created.
Edge.java
- Create a class “Edge”
- Define and declare the required variables.
- Constructor gets defined.
- Method that defines Boolean objects gets defined.
- Return the value after validating the vertices.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Tape for a Turing Machine (Doubly-linked List)”.(I USE ECLIPSE & RUN CHECK ONLINE CONSOLE)A class named Tape to represent Turing machine tapes. The class should have an instance variable of type Cell that points to the current cell with the method:
public Cell getCurrentCell() -- returns the pointer that points to the current cell.
public char getContent() -- returns the char from the current cell.
public void setContent(char ch) -- changes the char in the current cell to the specified value. Don't forget the Javadoc comments. IT WOULD HAVE A PUBLIC CLASS
public void moveLeft() -- moves the current cell one position to the left along the tape. Note that if the current cell is the leftmost cell that exists, then a new cell must be created and added to the tape at the left of the current cell, and then the current cell pointer can be moved to point to the new cell. The content of the new cell should be a blank space. (Remember that the Turing machine's tape is conceptually…
Complete the Kennel class by implementing the following methods:
addDog(Dog dog)
findYoungestDog() method, which returns the Dog object with the lowest age in the kennel.
Assume that no two dogs have the same age.
Given classes:
Class LabProgram contains the main method for testing the program.
Class Kennel represents a kennel, which contains an array of Dog objects as a dog list. (Type your code in here.)
Class Dog represents a dog, which has three fields: name, breed, and age. (Hint: getAge() returns a dog's age.)
For testing purposes, different dog values will be used.
Ex. For the following dogs:
Rex Labrador 3.5 Fido Healer 2.0 Snoopy Beagle 3.2 Benji Spaniel 3.9
the output is:
Youngest Dog: Fido (Healer) (Age: 2.0)
Observer pattern
The PhoneModel class stores a phone number as a list of digits, and the Keypad class has this method:
public void simulateKeyPresses(int numKeyPresses)(0
that allows the user to enter digits one at a time then save each digit in the list.
The Screen wants to respond to each key being entered.
Make the model notify the observers whenever a new digit is entered for the phone number.
The first observer prints the newest digit out to the screen
The second observer prints "Now dialing 12345678901.." out to the screen (where the number is the
number the model has).
Only the Screen class can print to the screen
The model must be decoupled from the Other classes.
Chapter 28 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version Plus MyProgrammingLab with Pearson EText -- Access Card Package
Ch. 28.2 - What is the famous Seven Bridges of Knigsberg...Ch. 28.2 - Prob. 28.2.2CPCh. 28.2 - Prob. 28.2.3CPCh. 28.2 - Prob. 28.2.4CPCh. 28.3 - Prob. 28.3.1CPCh. 28.3 - Prob. 28.3.2CPCh. 28.4 - Prob. 28.4.1CPCh. 28.4 - Prob. 28.4.2CPCh. 28.4 - Show the output of the following code: public...Ch. 28.4 - Prob. 28.4.4CP
Ch. 28.5 - Prob. 28.5.2CPCh. 28.6 - Prob. 28.6.1CPCh. 28.6 - Prob. 28.6.2CPCh. 28.7 - Prob. 28.7.1CPCh. 28.7 - Prob. 28.7.2CPCh. 28.7 - Prob. 28.7.3CPCh. 28.7 - Prob. 28.7.4CPCh. 28.7 - Prob. 28.7.5CPCh. 28.8 - Prob. 28.8.1CPCh. 28.8 - When you click the mouse inside a circle, does the...Ch. 28.8 - Prob. 28.8.3CPCh. 28.9 - Prob. 28.9.1CPCh. 28.9 - Prob. 28.9.2CPCh. 28.9 - Prob. 28.9.3CPCh. 28.9 - Prob. 28.9.4CPCh. 28.10 - Prob. 28.10.1CPCh. 28.10 - Prob. 28.10.2CPCh. 28.10 - Prob. 28.10.3CPCh. 28.10 - If lines 26 and 27 are swapped in Listing 28.13,...Ch. 28 - Prob. 28.1PECh. 28 - (Create a file for a graph) Modify Listing 28.2,...Ch. 28 - Prob. 28.3PECh. 28 - Prob. 28.4PECh. 28 - (Detect cycles) Define a new class named...Ch. 28 - Prob. 28.7PECh. 28 - Prob. 28.8PECh. 28 - Prob. 28.9PECh. 28 - Prob. 28.10PECh. 28 - (Revise Listing 28.14, NineTail.java) The program...Ch. 28 - (Variation of the nine tails problem) In the nine...Ch. 28 - (4 4 16 tails problem) Listing 28.14,...Ch. 28 - (4 4 16 tails analysis) The nine tails problem in...Ch. 28 - (4 4 16 tails GUI) Rewrite Programming Exercise...Ch. 28 - Prob. 28.16PECh. 28 - Prob. 28.17PECh. 28 - Prob. 28.19PECh. 28 - (Display a graph) Write a program that reads a...Ch. 28 - Prob. 28.21PECh. 28 - Prob. 28.22PECh. 28 - (Connected rectangles) Listing 28.10,...Ch. 28 - Prob. 28.24PECh. 28 - (Implement remove(V v)) Modify Listing 28.4,...Ch. 28 - (Implement remove(int u, int v)) Modify Listing...
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- 1- Create a struct to store the node label and its cost:struct Node{char label;int cost;};SCS214: Data StructuresAssignment-42- Implement a class MinHeap that has the following declaration:3- Create a class WeightedGraph, which stores a graph using an adjacency matrixwith the following declaration:class WeightedGraph{ int** g; int nVertices;public:int getNVertices();//returns the number of vertices int getWeight(char,char);//returns weight of the edge connecting the givenvertices int* returnNeighbors(int v);// returns the indices of the neighbors of the vertexv as an int array int numNeighbors(int v);//returns the number of neighbors of the vertex v void loadGraphFromFile(ifstream&);//allocates the adjacency matrix & initializesedge weights from the specified file void dijkstra(char startVertex, char* prev, Node distances[] );//find the shortestpath from the start vertex to all other vertices, by filling the prev array and thedistances array};class MinHeap{ Node* heap; //an…arrow_forwardInterface : - Question : Make the AECar class implement the Comparable Java interface. Write a driver program that sorts a list of 4 AECars according to price.arrow_forward2) Consider a class for a node of a doubly linked list: class node{ String name; String city; node llink, rlink; } Use the above class and create a class for doubly linked list which consists of methods that performs the following: i. Insert a node at the beginning ii. Insert a node at the end ii. Display all the names in doubly linked list where city name is common iv. Delete a node from the end v. Search and delete specific node. Write and execute a java program to create an object of this class. Use the object of this class to read required data from user and demonstrate the working of methods with appropriate messages and proper comments.arrow_forward
- public class Product { private String name; private double cost; public Product(String n, double c) { name=n; cost=c; } public String getName() { return name; On the left is code for a class called Product. Fill in the blanks in the code on the right in order to create three appropriate Product instances and add them to the cart ArrayList. Use the output of the code, shown below the code, to guide you. } public double getCost() { return cost; } public String toString() { return (name + "$" + cost); } public static void addProducts (ArrayList c) { add(new Product("Shampoo", 13.89)); add(new Product("Bread",4.99)); add(new Product("Cereal", 7.49)); } public static void main(String[] args) { ArrayList cart = new ArrayList(); ddProducts (cart); for (Product p : cart) { System.out.println(p); } } Output: Shampoo $13.89 Bread $4.99 Cereal $7.49arrow_forwardJava (ArrayList) - Plant Informationarrow_forwardJava (derived classes) - Pet Informationarrow_forward
- Q#: Create a class Book that has the following data members: Name ISBN Author Edition Create a constructor to initialize all data members. Write a method PrintInfo to print information containing the fields of class. Write another class called Library that must contain a Main method. Inside Main, make at least 10 instances of Book, stored in an array (or list) of type Book. Call the method printInfo() for each instance. (Hint: use of foreach loop will be beneficial).arrow_forwarda. What does the function begin of the class linkedListType do?b. What does the function end of the class linkedListType do?arrow_forward1. ArrayListsCreate a class called OurArrayList and implement the following methods. Do NOT create any auxiliary memory.Include a main method and test all your methods with appropriate examples.Assume the following classes have been defined:a. Write a method called scaleByK() that takes an ArrayList of integers as a parameter and replaces every integer of value K with K copies of itself. For example, if the list stores the values (4, 1 , 2, 0 ,3) before the method is called, it should store the values (4, 4, 4, 4, 1, 2, 2, 3, 3, 3) after the method finishes executing. Zeroes and negative numbers should be removed from the list by this method.b. Write a method markLength4() that takes an ArrayList of Strings as a parameter and that places a String of four asterisks ("****") in front of every String of length 4. For example, suppose that an ArrayList called "list" contains the following values:(this, is, lots, of, fun, for, every, Java, programmer)And you make the following…arrow_forward
- data structure-JAVAarrow_forwardExercise: Exercises Write a class named Octagon that extends GeometricObject and implements the Comparable and Cloneable interfaces. Assume all eight sides of the octagon are of equal length. The area can be computed using the following formula: The Octagon class has a private double data field named side with its getter and setter methods. The class has a no-arg constructor that creates an Octagon with side 0, and a constructor to create an Octagon with a specified side. Write a test program that creates an Octagon object with side value 5 and displays its area and perimeter. Create a new object using the clone method, and compare the two objects using the compareTo method. As far as classes go, the abstract GeometricObject class contains the abstract doubles getArea() and getPerimeter(). The programming language used in this exercise is Java, and it covers the Interfaces topic. I did get how most of the program should look like, but I'm facing trouble understanding a few…arrow_forwardComputer Science QuestionConsider the adjacency list (list of neighbors) data structure for representing a graph. struct node{int data; node * next;};class Graph { …………private:node neighborList[30];int last;};Write a method to print the neighbors of a given node n, void Graph::print(int n){??????}arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education