Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 12, Problem 10PP
Program Plan Intro
“GroupHolder” class
Program Plan:
- Import required package.
- Define “Main” class.
- Define “GroupHolder” class
- Create an array list “items” from “GroupHolder” class.
- Method definition for “findGroupNodeFor”
- Declare variable using “GroupNode” type.
- Set node “n” to “null”.
- Set “found” to “false”.
- Check condition using “while” loop
- Compute next node.
- If “n” equal to “s”, then set “found” to “true”.
- If found, then returns the value of “n”.
- Otherwise, returns null.
- Method definition of “addItem”.
- Call “findGroupNodeFor” method and store it to a variable “n”.
- If “n” is null, then add it to “items”.
- Method definition for “getRepresentative”.
- Call “findGroupNodeFor” method and store it to a variable “n”.
- Check condition using “while” loop.
- Set node to link value at node
- Finally returns the data at node.
- Set node to link value at node
- Method definition of “getAllRepresentatives”.
- Create an array list.
- Add data to “items”.
- Finally returns the result.
- Method definition of “inSameGroup”.
- Assign representative for string “s1” and store result to “r1”.
- Assign representative for string “s2” and store result to “r2”.
- Returns result.
- Method definition of “union”
- Assign representative for string “s1” and store result to “r1”.
- Assign representative for string “s2” and store result to “r2”.
- Check condition.
- Find group node for “r1” and “r2”.
- Create “GroupNode” class.
- Declare required variables.
- Create constructor for “GroupNode” class.
- Create parameterized for “GroupNode” class.
- Define main function.
- Create object “g” from “GroupHolder” class.
- Add item to “g” by calling the method “addItem”.
- Display groups by calling the method “getAllRepresentatives”.
- Join groups by calling the method “union”.
- Display groups after performing unions operations.
- Check “a” and “e” is in same group by calling method “inSameGroup”.
- Check “a” and “f” is in same group by calling method “inSameGroup”.
- Define “GroupHolder” class
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Provide full C++ code
Building a playlist (of songs) using a linked list and making some operations such as adding songs, removing songs, shuffling them, etc. (Some parts of this lab will closely follow lab 08 - it is imperative that you complete that lab before working on this project).
A Node representing a song has the following data members (similar to struct Node of lab 08, except it doesn't have one member for storing data):
string uniqueID
string songName
string artistName
int songLength
Node* nextNodePtr
Your code must have the following three files:
Playlist.h - Class declaration for a linked list of Nodes (very similar to lab 08 but with some changes to methods, as described below) with following private data members:
private:Node* first;Node* last;int size;
Playlist.cpp - Class definition
main.cpp - main() function
Checkpoint A
For checkpoint A, you need to build a playlist (of songs) by readings data members of several songs from a file and printing them.
Implement…
Please, help me to do this in Java.
Create a program to view the waiting list. The list (5 entries) is created in the program and is an object of the LinkedList class. The list entry is a QueuePerson object that contains the queue's last name, first name, and patronymic fields (of type String), an AddressValue field for the queue's address, and queue priority (int type). In turn, the field of the AddressValue type contains three fields of the String type: the name of the city, the name of the street and the house number, as well as an int type field - the apartment number (if the apartment number is 0, the house in which the subject lives does not have apartments). Entries in the queue are sorted according to priority, and the queue is added last in the queue of its priority. Provide the possibility of receiving so that there is no repetition in the queue by the name of the person on the waiting list, for which use TreeSet.
Explain this code by putting comments in detail. Language used is c++. Topic is Linkedlist
// void deleteByData(int data) { // if(head->data == data) { // head = head->next; // } // next = head; // Node *prev = next; // while (next != NULL) { // if (next->data == data) { // prev->next = prev->next->next; // } // prev = next; // next = next->next; // } // };
};
Chapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 12.1 - Suppose aList is an object of the class...Ch. 12.1 - Prob. 2STQCh. 12.1 - Prob. 3STQCh. 12.1 - Prob. 4STQCh. 12.1 - Can you use the method add to insert an element at...Ch. 12.1 - Prob. 6STQCh. 12.1 - Prob. 7STQCh. 12.1 - If you create a list using the statement...Ch. 12.1 - Prob. 9STQCh. 12.1 - Prob. 11STQ
Ch. 12.1 - Prob. 12STQCh. 12.2 - Prob. 13STQCh. 12.2 - Prob. 14STQCh. 12.2 - Prob. 15STQCh. 12.2 - Prob. 16STQCh. 12.3 - Prob. 17STQCh. 12.3 - Prob. 18STQCh. 12.3 - Prob. 19STQCh. 12.3 - Write a definition of a method isEmpty for the...Ch. 12.3 - Prob. 21STQCh. 12.3 - Prob. 22STQCh. 12.3 - Prob. 23STQCh. 12.3 - Prob. 24STQCh. 12.3 - Redefine the method getDataAtCurrent in...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.4 - Revise the definition of the class ListNode in...Ch. 12.4 - Prob. 30STQCh. 12.5 - What is the purpose of the FXML file?Ch. 12.5 - Prob. 32STQCh. 12 - Repeat Exercise 2 in Chapter 7, but use an...Ch. 12 - Prob. 2ECh. 12 - Prob. 3ECh. 12 - Repeat Exercises 6 and 7 in Chapter 7, but use an...Ch. 12 - Write a static method removeDuplicates...Ch. 12 - Write a static method...Ch. 12 - Write a program that will read sentences from a...Ch. 12 - Repeat Exercise 12 in Chapter 7, but use an...Ch. 12 - Write a program that will read a text file that...Ch. 12 - Revise the class StringLinkedList in Listing 12.5...Ch. 12 - Prob. 12ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 14ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 17ECh. 12 - Revise the method selectionSort within the class...Ch. 12 - Repeat the previous practice program, but instead...Ch. 12 - Repeat Practice Program 1, but instead write a...Ch. 12 - Write a program that allows the user to enter an...Ch. 12 - Write a program that uses a HashMap to compute a...Ch. 12 - Write a program that creates Pet objects from data...Ch. 12 - Repeat the previous programming project, but sort...Ch. 12 - Repeat the previous programming project, but read...Ch. 12 - Prob. 9PPCh. 12 - Prob. 10PPCh. 12 - Prob. 11PPCh. 12 - Prob. 12PPCh. 12 - Prob. 13PPCh. 12 - Prob. 14PPCh. 12 - Prob. 15PP
Knowledge Booster
Similar questions
- What are the fundamental operations of a linked list and the main advantage of a linked list over an array? Test program LinkedList.java, and make sure that you understand each operation in the program. (refer to linkedListApplication.java). In this code which part I will keep main.java file and which part I will keep LinkedList.java.java file. Because I will use main.java IDE. Otherwise my program doesn't run. import java.util.*; public class LinkedList{ public Node header; public LinkedList() { header = null; } public final Node Search(int key) { Node current = header; while (current != null && current.item != key) { current = current.link; } return current; } public final void Append(int newItem) { Node newNode = new Node(newItem); newNode.link = header; header = newNode; } public final Node Remove() { Node x = header; if (header != null) {…arrow_forwardGiven the following definitions that we have used in class to represent a doubly-linked, circular List with a dummy-header node that contains data of type "struct Student". typedef struct { char *name; char *major; } Student;typedef struct node { Student *data; struct node *next; struct node *prev; } Node;typedef struct { Node *header; int size; } LinkedList;LinkedList *roster; Here is a picture of what the Linked List might look like, although you should answer the following question for a general list (ie, that does not necessarily contain 3 data items). What TYPE of data is the following: *roster Group of answer choices int int * Node Node * Student Student * char char * This is legal code, but it does not match any of the types listed above. This is illegal code, and would produce a syntax error No hand written solution and no imagearrow_forwardGiven the following definitions that we have used in class to represent a doubly-linked, circular List with a dummy-header node that contains data of type "struct Student". typedef struct { char *name; char *major; } Student; typedef struct node { Student *data; struct node *next; struct node *prev; } Node; typedef struct { Node *header; int size; } LinkedList; LinkedList *roster; Here is a picture of what the Linked List might look like, although you should answer the following question for a general list (ie, that does not necessarily contain 3 data items). What TYPE of data is the following: roster->header->data->next->next Group of answer choices int int * Node Node * Student Student * char char * This is legal code, but it does not match any of the types listed above. This is illegal code, and would produce a syntax error.arrow_forward
- Apply the methods in the ListIterator interface to write a Java program in NetBeans that creates a LinkedList of four elements of type string, namely: Java, C#, PHP and Python.The program should then print out the elements initially in the original order, and then afterwards in reverse order using the ListIterator methods. In this case, the following is the expected output: Run: original order of strings: Java C# PHP Python Reverse order of strings: Python PHP C#Java BUILD SUCCESSFULarrow_forwardA)Draw the linked node structure created by the following program and , B)List the output of program. struct node{ struct node *left; char letter; struct node *right; }; typedef struct node *NODEPTR; NODEPTR getnode(void); void displayList(NODEPTR); void main() { NODEPTR p , list , save; char one; p=getnode(); p->letter='A'; list=p; p->right=p; p->left=p; save=list; for(int i=2;i<8;i+=2) { one='A'+ i; p=getnode(); p->letter=one; p->left=save; save->right=p; save=p; printf("Letter= %c\n",p->letter); } list->left=save; save->right=list; list=p; displayList(list); } void displayList(NODEPTR head) {NODEPTR save; printf("\nLIST\n"); save=head; do {printf("%c ",save->letter); save=save->left; }while(save!=head); } NODEPTR getnode() { NODEPTR q; q = (NODEPTR) malloc(sizeof(struct node));…arrow_forwardWhat are the major differences between a list and a set in Java? How can you determine when to implement a list versus a set for an application? Provide an example code segment in Java that illustrates utilizing a list or a set.arrow_forward
- Machine Problem: Write a Java program that will display the given menu: Note: Must accept a string of word/phrase/sentence Menu 1. Add a string 2. Display list of strings 3. Display list of uppercase words 4. Display list of lowercase words 5. Delete an uppercase word 6. Delete a lowercase word 7. End program When 1 is chosen, ask the user to enter a string and add it to a list using a linked list When 2 is chosen, display the list of strings. When 3 is chosen, display all uppercase words found in the list of strings in ascending order. (create a linked list containing all uppercase words) When 4 is chosen, display all lowercase words found in the list of strings in ascending order. (create a linked list containing all lowercase words) When 5 is chosen, display the list of uppercase words then ask the user the index of the word he wants to delete. Index of the first word in the list is 0 When 6 is chosen, display the list of lowercase words then ask the user the…arrow_forwardWrite a program which will concatenate two single linked lists. The structure is defined below. Assume that head1 contains the starting address of the first list and head2 contains the starting address of the second list. You need to join them together so that all the students’ roll no and names of both the lists will be displayed together with the help of head1 pointer. struct link { int rollno; char name[20]; struct link *next; }; typedef struct link node; node *head1=NULL, *head2=NULL; //global declarationarrow_forwardA map is a container that stores a collection of ordered pairs, each pair consists of a key and a value, <key, value>. Keys must be unique. Values need not be unique, so several keys can map to the same values. The pairs in the map are sorted based on keys. Group of answer choices True Falsearrow_forward
- Test program LinkedList.java, and make sure that you understand each operation in the program. (refer to linkedListApplication.java). In this code which part I will keep main.java file and which part I will keep LinkedList.java.java file. Because I will use main.java IDE. Otherwise my program doesn't run. import java.util.*; public class LinkedList{ public Node header; public LinkedList() { header = null; } public final Node Search(int key) { Node current = header; while (current != null && current.item != key) { current = current.link; } return current; } public final void Append(int newItem) { Node newNode = new Node(newItem); newNode.link = header; header = newNode; } public final Node Remove() { Node x = header; if (header != null) { header = header.link; } return x; } public final Node searchPrevious(int…arrow_forwardIn Java, Explain when it might be preferable to use a map instead of a set.arrow_forward*in java* A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings), separated by a comma. That list is followed by a name, and your program should output the phone number associated with that name. Assume that the list will always contain less than 20 word pairs. Ex: If the input is: 3 Joe,123-5432 Linda,983-4123 Frank,867-5309 Frank the output is: 867-5309 Your program must define and call the following method. The return value of getPhoneNumber() is the phone number associated with the specific contact name.public static String getPhoneNumber(String[] nameArr, String[] phoneNumberArr, String contactName, int arraySize) Hint: Use two arrays: One for the string names, and the other for the string phone numbers.…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