EBK STARTING OUT W/JAVA:...DATA...
4th Edition
ISBN: 9780134757179
Author: GADDIS
Publisher: PEARSON CO
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 19, Problem 2PC
Program Plan Intro
Linked List Sorting and Reversing
Program Plan:
For filename: Modified “LinkedList1.java”
- In this class, additionally need to add two methods “sort()” and “reverse()”.
- Define the method “sort()” which is used to sort the elements in the list by alphabetical order.
- Create two variables “current_node” and “index_value” using “Node” class and this variable set to “null”.
- Declare a string variable “temp_value”.
- Check whether list is empty. If the list is empty, then returns nothing.
- Otherwise,
- Check condition using “for” loop. That is the current node will point to first.
- Check the condition using “for” loop that is for index value will point to next node of current node.
- If data in the “current_node” is greater than the data in “index_value”, then swap the data of “current_node” and “index_index”.
- Check the condition using “for” loop that is for index value will point to next node of current node.
- Check condition using “for” loop. That is the current node will point to first.
- Define the method “reverse()” which is used to reverse the elements in the list.
- Create a list “rev_list” and set it to “null”.
- Performs “while” loop. This loop will perform up to the first node equals to “null”.
- Set a reference “ref” to first node.
- Set “first” to next first node.
- Set next node to “rev_list”.
- Set the “rev_list” to reference “ref”.
- Make the list “rev_list” as the new list.
For filename: “LinkedList1Demo.java”:
- Import required package.
- Define “LinkedList1Demo” class.
- Create an instance for “LinkedList1” class, text area, command text field, and result text field.
- Define constructor for “LinkedList1Demo()” class.
- Create instance.
- Create a panel for “Command Result” text field.
- Create a label for command result.
- Place the text area in center of the frame.
- Create a panel and label for “Command” text field.
- Set up the frame.
- Define private class “commandTextListener” that reply to the user entered command.
- Define “actionPerformed” class.
- Read the command from the command text field.
- Create an object for “Scanner” class.
- Read command from user.
- Check the user entered command using “switch” statement.
- If the user entered command is “sort”, then,
-
- Sort the linked list “new_list” by calling the method “sort()”.
- Displays lists in alphabetical order.
- Assign a status message for the “sort” command was finished.
- Displays status message to “Command Result” text field.
- If the user entered command is “reverse”, then
-
- Reverse the linked list “new_list” by calling the method “reverse()”.
- Prints the reversed list.
- Assign a status message for the “reverse” command was finished.
- Displays status message to “Command Result” text field.
- If the user entered command is “add”, then
-
- Check condition. If it is true, then
- Read index and string element from user.
- Add that index and its element to linked list “new_list” by calling the method “add”.
- Otherwise,
- Read string element from user.
- Add string element to the list “new_list” by calling the method “add”.
- Display the added string elements.
- Check condition. If it is true, then
- If the user entered command is “remove”, then
-
- Check condition. If it is true, then
- Read an index from user.
- Remove an element at given index.
- Display the removed element at given index to “Command Result” text field.
- Otherwise,
- Read an element from the list.
- Obtain the Boolean result.
- Convert the Boolean into string.
- Display the Boolean result to “Command Result” text field.
- Displays string elements in the list
- Check condition. If it is true, then
- If the user entered command is “isEmpty”, then
-
- Check the given list is empty or not by calling the method “isEmpty” and store the result in “result_text3”.
- Display the result to “Command Result” text field.
- If the user entered command is “size”, then
-
- Compute the size of list “new_list” by calling the method “size()” and store the result in “result_text4”.
- Display the result to “Command Result” text field.
- Define “actionPerformed” class.
- Define main function.
- The instance of “LinkedList1Demo” class displays its window.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Problem Statement
You are working as a Devops Administrator.
Y
ou’ve been
t
asked to deploy a multi
-
tier application on Kubernetes Cluster. The application is a NodeJS application
available on Docker Hub with the following name:
d
evopsedu/emp
loyee
This Node
JS application works with a mongo database. MongoDB
image
is available
on
D
ockerHub with the following name:
m
ongo
You are required to deploy this application on Kubernetes:
•
NodeJS is available on port 8888 in the container
and will be reaching out to por
t
27017 for mongo database connection
•
MongoDB will be accepting connections on
port 27017
You must deploy this application using the CL
I
.
Once your application is up and running, ensure you can add an employee from the
NodeJS application and verify by
going to Get Employee page and retrieving your input.
Hint:
Name the Mongo DB Service and deployment, specifically as “mongo”.
I need help in server client project. It is around 1200 lines of code in both . I want to meet with the expert online because it is complicated. I want the server send a menu to the client and the client enters his choice and keep on this until the client chooses to exit . the problem is not in the connection itself as far as I know.I tried while loops but did not work. please help its emergent
I need help in my server client in C language
Chapter 19 Solutions
EBK STARTING OUT W/JAVA:...DATA...
Ch. 19.1 - Prob. 19.1CPCh. 19.1 - Prob. 19.2CPCh. 19.3 - Prob. 19.4CPCh. 19 - A list is a collection that _____. a. associates...Ch. 19 - Prob. 2MCCh. 19 - Prob. 3MCCh. 19 - Prob. 4MCCh. 19 - Prob. 5MCCh. 19 - Prob. 6MCCh. 19 - Prob. 7MC
Ch. 19 - Prob. 11TFCh. 19 - Prob. 12TFCh. 19 - Prob. 13TFCh. 19 - Prob. 14TFCh. 19 - Prob. 15TFCh. 19 - Prob. 16TFCh. 19 - Prob. 17TFCh. 19 - Prob. 18TFCh. 19 - Prob. 19TFCh. 19 - Prob. 20TFCh. 19 - Prob. 1FTECh. 19 - Prob. 2FTECh. 19 - Prob. 3FTECh. 19 - Prob. 4FTECh. 19 - Prob. 5FTECh. 19 - Prob. 1AWCh. 19 - Prob. 2AWCh. 19 - Prob. 3AWCh. 19 - Prob. 4AWCh. 19 - Prob. 3SACh. 19 - Prob. 4SACh. 19 - Prob. 5SACh. 19 - Consult the online Java documentation and...Ch. 19 - Prob. 1PCCh. 19 - Prob. 2PC
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
- Exercise docID document text docID document text 1 hot chocolate cocoa beans 7 sweet sugar 2345 9 cocoa ghana africa 8 sugar cane brazil beans harvest ghana 9 sweet sugar beet cocoa butter butter truffles sweet chocolate 10 sweet cake icing 11 cake black forest Clustering by k-means, with preprocessing tokenization, term weighting TFIDF. Manhattan Distance. Number of cluster is 2. Centroid docID 2 and docID 9.arrow_forwardChange the following code so that there is always at least one way to get from the left corner to the top right, but the labyrinth is still randomized. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. Take care that the player and the dragon cannot start off on walls. Also the dragon starts off from a randomly chosen position public class Labyrinth { private final int size; private final Cell[][] grid; public Labyrinth(int size) { this.size = size; this.grid = new Cell[size][size]; generateLabyrinth(); } private void generateLabyrinth() { Random rand = new Random(); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { // Randomly create walls and paths grid[i][j] = new Cell(rand.nextBoolean()); } } // Ensure start and end are…arrow_forwardChange the following code so that it checks the following 3 conditions: 1. there is no space between each cells (imgs) 2. even if it is resized, the components wouldn't disappear 3. The GameGUI JPanel takes all the JFrame space, so that there shouldn't be extra space appearing in the frame other than the game. Main(): Labyrinth labyrinth = new Labyrinth(10); Player player = new Player(9, 0); Dragon dragon = new Dragon(9, 9); JFrame frame = new JFrame("Labyrinth Game"); GameGUI gui = new GameGUI(labyrinth, player, dragon); frame.add(gui); frame.setSize(600, 600); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); public class GameGUI extends JPanel { private final Labyrinth labyrinth; private final Player player; private final Dragon dragon; //labyrinth, player, dragon are just public classes private final ImageIcon playerIcon = new ImageIcon("data/images/player.png");…arrow_forward
- Make the following game user friendly with GUI, with some simple graphics. The GUI should be in another seperate class, with some ImageIcon, and Game class should be added into the pane. The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units. Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return…arrow_forwardDiscuss the negative and positive impacts or information technology in the context of your society. Provide two references along with with your answerarrow_forwardA cylinder of diameter 10 cm rotates concentrically inside another hollow cylinder of inner diameter 10.1 cm. Both cylinders are 20 cm long and stand with their axis vertical. The annular space is filled with oil. If a torque of 100 kg cm is required to rotate the inner cylinder at 100 rpm, determine the viscosity of oil. Ans. μ= 29.82poisearrow_forward
- Make the following game user friendly with GUI, with some simple graphics The following code works as this: The objective of the player is to escape from this labyrinth. The player starts at the bottom left corner of the labyrinth. He has to get to the top right corner of the labyrinth as fast he can, avoiding a meeting with the evil dragon. The player can move only in four directions: left, right, up or down. There are several escape paths in all labyrinths. The player’s character should be able to moved with the well known WASD keyboard buttons. If the dragon gets to a neighboring field of the player, then the player dies. Because it is dark in the labyrinth, the player can see only the neighboring fields at a distance of 3 units. Cell Class: public class Cell { private boolean isWall; public Cell(boolean isWall) { this.isWall = isWall; } public boolean isWall() { return isWall; } public void setWall(boolean isWall) { this.isWall = isWall; } @Override public String toString() {…arrow_forwardPlease original work What are four of the goals of information lifecycle management think they are most important to data warehousing, Why do you feel this way, how dashboards can be used in the process, and provide a real life example for each. Please cite in text references and add weblinksarrow_forwardThe following is code for a disc golf program written in C++: // player.h #ifndef PLAYER_H #define PLAYER_H #include <string> #include <iostream> class Player { private: std::string courses[20]; // Array of course names int scores[20]; // Array of scores int gameCount; // Number of games played public: Player(); // Constructor void CheckGame(int playerId, const std::string& courseName, int gameScore); void ReportPlayer(int playerId) const; }; #endif // PLAYER_H // player.cpp #include "player.h" #include <iomanip> Player::Player() : gameCount(0) {} void Player::CheckGame(int playerId, const std::string& courseName, int gameScore) { for (int i = 0; i < gameCount; ++i) { if (courses[i] == courseName) { // If course has been played, then check for minimum score if (gameScore < scores[i]) { scores[i] = gameScore; // Update to new minimum…arrow_forward
- In this assignment, you will implement a multi-threaded program (using C/C++) that will check for Prime Numbers and Palindrome Numbers in a range of numbers. Palindrome numbers are numbers that their decimal representation can be read from left to right and from right to left (e.g. 12321, 5995, 1234321). The program will create T worker threads to check for prime and palindrome numbers in the given range (T will be passed to the program with the Linux command line). Each of the threads works on a part of the numbers within the range. Your program should have some global shared variables: • numOfPrimes: which will track the total number of prime numbers found by all threads. numOfPalindroms: which will track the total number of palindrome numbers found by all threads. numOfPalindromic Primes: which will count the numbers that are BOTH prime and palindrome found by all threads. TotalNums: which will count all the processed numbers in the range. In addition, you need to have arrays…arrow_forwardHow do you distinguish between hardware and a software problem? Discuss theprocedure for troubleshooting any hardware or software problem. give one reference with your answer.arrow_forwardYou are asked to explain what a computer virus is and if it can affect computer’shardware or software. How do you protect your computer against virus? give one reference with your answer.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning