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
Q/ Write a program in C# that lets the user to define the number of rows and columns. Then, the
program reads the matrix and finds the index of the even and odd numbers and display them with their
corresponding indices. Use adequate messages during the program execution.
For any element in keysList with a value greater than 100, print the corresponding value in itemsList, followed by a space. Ex: If keysList = {42, 105, 101, 100} and itemsList = {10, 20, 30, 40}, print: 20 30
Since keysList.at(1) and keysList.at(2) have values greater than 100, the value of itemsList.at(1) and itemsList.at(2) are printed.
#include <iostream>#include <vector>using namespace std;
int main() {const int SIZE_LIST = 4;vector<int> keysList(SIZE_LIST);vector<int> itemsList(SIZE_LIST);unsigned int i;
for (i = 0; i < keysList.size(); ++i) {cin >> keysList.at(i);}
for (i = 0; i < itemsList.size(); ++i) {cin >> itemsList.at(i);}
/* Your solution goes here */
cout << endl;
return 0;}
Please help me with this problem using c++.
Please solve this question in JAVA|
Write a Java program that asks the user to enter items
until the user chooses to stop, stores them into links
(nodes), and chains the links together into a linked
list. You will need to make the following changes:
• Your linked list should store information about
Customers' Transactions that contain three
fields: customer name (string), customer number
(int), and transaction description (string).
• Instead of putting all of your code inside the
main source code file, you should create the
following functions:
1. addToStart(Item x)
2. addToEnd(Item x)
3. insertAt(Item x, int n)
4. remove(int customer_number)
5. reverse)
6. printList)
Instead of simply asking the user if they want to
add a new link, your main program should offer
the user a menu of options:
1. Add a new link to the end
2. Add a new link to the beginning
3. Insert an element at index n into the list.
4. Remove a link from the list
5. Reverse the list
6. Print out the entire list
7. Quit…
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
- In Java, Explain when it might be preferable to use a map instead of a set.arrow_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_forwardIn C++, write a program that outputs the nodes of a graph in a breadth first traversal. Data File: Please use this data file. Text to copy: 100 1 3 -9991 4 -9992 5 -9993 2 -9994 -9995 7 8 -9996 4 7 -9997 -9998 -9999 7 8 -999 Diagram: Also, please take a look at the attached figure on and calculate the weights for the following edges: 0 -> 1 -> 4 0 -> 3 -> 2 -> 5 -> 7 0 -> 3 -> 2 -> 5 -> 8 6 -> 4 6 -> 7 9 -> 7 9 -> 8 To calculates these weights, please assume the following data: 0 -> 1 = 1 0 -> 3 = 2 1 -> 4 = 3 3 -> 2 = 4 2 -> 5 = 5 5 -> 7 = 6 5 -> 8 = 7 6 -> 4 = 8 6 -> 7 = 9 9 -> 7 = 10 9 -> 8 = 11arrow_forward
- Please Explain your work and this should be in "C Language" and this is a data structure subject Thank you!arrow_forwardIn C language pleasearrow_forwardSuppose we would like to create a data structure for holding numbers that canbe accessed either in the order that they were added or in sorted order. Weneed nodes having two references. If you follow one trail of references, you getthe items in the order they were added. If you follow the other trail of references, you get the items in numeric order. Create a class DualNode that wouldsupport such a data structure. Do not write the data structure itself.arrow_forward
- write a program for a library automation which gets the isbn number, name, author and publication year of the books in the library. the status will be filled by the program as follows: if publication year before 1985 the status is reference else status is available, the information about the books should be stored inside a linked list. the program should have a menu and the user inserts, displays, and deletes the elements from the menu by write a selecting options. the following data structure should be used. struct list char isbn[ 20 ]: char namei 20 ]. char authori 20 ]: int year; char status[200j: struct list "next, jinfo, wedoad n un posn ag pinogs nuu sulnogoj l press 1. to insert a book press 2. to display the book list press 3. to delete a book from listarrow_forwardMy homework was to design and implement a simple social network program in Java. I should use an adjacency matrix data structure in my implementation. Write a social network program in Java. The default information for this network is stored in two files: index.txt and friend.txt. The file index.txt stores the names of the people in the network – you may assume that we only store the given names and these names are unique; and friend.txt stores who knows whom. The program must read these two files. The following section describes the format of these two files. The friend.txt takes the following format. The first line is the number of pairs of friends. Each subsequent line has two integer numbers. The first two numbers are the indices of the names. The following is an example of friend.txt:50 31 30 12 41 5 The index.txt stores the names of the people in the network. The first line is the number of people in the file; for example:60 Gromit1 Gwendolyn2 Le-Spiderman3 Wallace4 Batman5…arrow_forwardWrite a c++ program in which you have to Create a linklist which will take data from user for 5 students including their name, mobile#, age, and marks. After that display the data in Disp()function And check which student got the highest marks.arrow_forward
- Version 3: Cone is a three-dimensional structure having a circular base where a set of line segments, connect all of the points on the base to a common point called apex. A cone can be seen as a set of non-congruent circular discs that are stacked on one another such that ratio of the radius of adjacent discs remains constant. The area is a cone is computed as A = (s sin(x))? where, "s" is the slant and "x" is the angle in radian. Write a C++ program that computes the area A of Cone by reading its parameter from a text file "input.txt". Each line of the file represents the Cone name, the slant "s" and the angle "x" of a Cone, respectively. The program should read each line to compute the area A of each Cone. It should also display the minimum computed area. Your program should implement the following functions: Area(): This function receives the values of "s", and "x" then computes and returns the value of area A. Print(): This function receives the name of Cone and the computed area A…arrow_forwardWrite a program that animates the linear search algorithm. Create a list that consists of 20 distinct numbers from 1 to 20 in a random order. The elements are displayed in a histogram, as shown in Figure 10.17. You need to enter a search key in the text field. Clicking the Step button causes the program to perform one comparison in the algorithm and repaints the histogram with a bar indicating the search position. When the algorithm is finished, display a dialog box to inform the user. Clicking the Reset button creates a new random list for a new start.arrow_forwardIn the C(89) standard of C programming language Suppose you are given an array of integers. You want to insert a number x to the array and rearrange so that all the elements are less than or equal to x are before x, and the elements after x are greater than x. For example, suppose the list is {3, 2, 7, 0 1, 5} and x is 4, since 3, 2, 0, and 1, are less than or equal to 4, 7and 5 are greater than 4, the new array is {3, 2, 0, 1, 4, 7, 5}. The new array has the length of n+1 where n is the length of the input array. Example input/output #1: Enter the length of the array: 10 Enter the elements of the array: 3 5 14 03 92 8 11 Enter the number for insertion: 3 Output: 3 1 0 3 2 3 5 4 9 8 11 Example input/output #2: Enter the length of the array: 8 Enter the elements of the array: 5 0 1 3 4 1 7 3 5 Enter the number for insertion: 6 Output: 5 0 4 1 3 5 6 13 7 1) Name your program arrays.c 2) Include the rearrange( ) function to rearrange the array: void rearrange(int *a, int n, int…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