All Matches
Solution Library
Expert Answer
Textbooks
Search Textbook questions, tutors and Books
Oops, something went wrong!
Change your search query and then try again
Toggle navigation
FREE Trial
S
Books
FREE
Tutors
Study Help
Expert Questions
Accounting
General Management
Mathematics
Finance
Organizational Behaviour
Law
Physics
Operating System
Management Leadership
Sociology
Programming
Marketing
Database
Computer Network
Economics
Textbooks Solutions
Accounting
Managerial Accounting
Management Leadership
Cost Accounting
Statistics
Business Law
Corporate Finance
Finance
Economics
Auditing
Ask a Question
Search
Search
Sign In
Register
study help
computer science
introduction to java programming and data structure
Questions and Answers of
Introduction to Java Programming and Data Structure
Rewrite Programming Exercise 6.20 using streams.Data from Programming Exercise 6.20Write a method that counts the number of letters in a string using the following header:public static int
Rewrite Programming Exercise 6.23 using streams.Data from Programming Exercise 6.23Write a method that finds the number of occurrences of a specified character in a string using the following
Use streams to write a program that displays the distinct scores in the scores array in Section 8.8. Display the scores in increasing order, separated by exactly one space, five numbers per line.
Rewrite Programming Exercise 21.4 using streams.Data from Programming Exercise 21.4Write a program that prompts the user to enter a text file name and displays the number of vowels and consonants in
Rewrite Programming Exercise 21.8 using streams.Data from Programming Exercise 21.8Rewrite Listing 21.9 to read the text from a text file. The text file is passed as a command-line argument. Words
Suppose the file test.txt contains floating-point numbers separated by spaces. Write a program to obtain the sum, average, maximum, and minimum of the numbers.
Create a CSS style sheet that defines a class for white fill and black stroke color and an id for red stroke and green color. Write a program that displays four circles and uses the style class and
Write a program that displays a tic-tac-toe board, as shown in Figure 31.48b. A cell may be X, O, or empty. What to display at each cell is randomly decided. The X and O are images in the files x.gif
Write a program that creates two shapes: a circle and a path consisting of two cubic curves, as shown in Figure 31.49b. Exercise31 05 (b)
Write a program that displays two eyes in an oval, as shown in Figure 31.49c. Exercise31 06 (c)
Write a program that displays a rectangle with upper-left corner point at (40, 40), width 50, and height 40. Enter the values in the text fields x and y and press the Translate button to translate
Write a program that displays an ellipse. The ellipse is centered in the pane with width 60 and height 40. Enter the value in the text field Angle and press the Rotate button to rotate the ellipse,
Write a program that displays an ellipse. The ellipse is centered in the pane with width 60 and height 40. Enter the scaling factors in the text fields and press the Scale button to scale the
Write a program that plots the sine function, as shown in Figure 31.51a. Exercise31 10 YA (a)
Write a program that plots the log function, as shown in Figure 31.51a. Exercise31_10 (a)
Write a program that plots the n2 function, as shown in Figure 31.51b Еxercise31_11 (b)
Write a program that plots the log, n, nlogn, and n2 functions, as shown in Figure 31.52b. Exercise31_13 (b)
Write a program that enables the user to scale and rotate the STOP sign, as shown in Figure 31.53. The user can press the UP/DOWN arrow key to increase/decrease the size and press the RIGHT/LEFT
Write a program that displays a circle filled with a gradient color to animate a sun and display light rays coming out from the sun using dashed lines, as shown in Figure 31.54a. Evercise 1_15 (a)
Write a program that displays a cylinder, as shown in Figure 31.54b. Use dashed strokes to draw the dashed arc. I Exercise31_16 (b)
Write a program that calculates the future value of an investment at a given interest rate for a specified number of years. The formula for the calculation is as follows:futureValue =
Modify Listing 31.9, MenuDemo.java, to create a popup menu that contains the menus Operations and Exit, as shown in Figure 31.56. The popup is displayed when you click the right mouse button on the
Create a program that displays four shapes in split panes, as shown in Figure 31.57a. Exercise31 19 - (a)
Write a program using tab panes for performing integer and rational number arithmetic as shown in Figure 31.58. Exercise31_21 Exercise31,21 Integer Operations Rational Operations Integer Oparations
Revise Listing 31.14 to add a button to delete the selected row from the table, as shown in Figure 31.59.Data from Listing 31.14 Exertise31_22 Delete Selected Row Country Copital Population (million)
Rewrite Listing 32.1 to display the output in a text area, as shown in Figure 32.30.Data from Listing 32.1 Concurrent Output a ibab3b 4b 5 bebbbebbbbtbbbbbbbbbbbbbbbbbbbbbbbbbebbbbbbbbb 7
Rewrite Programming Exercise 15.29 using a thread to control car racing. Compare the program with Programming Exercise 15.29 by setting the delay time to 10 in both the programs. Which one runs the
Rewrite Programming Exercise 15.28 using a thread to control the fan animation.Data from Programming Exercise 15.28Write a program that displays a running fan, as shown in Figure 15.35c. Use the
Rewrite Programming Exercise 15.32 using a thread to control the clock animation.Data from Programming Exercise 15.32Modify Listing 14.21, ClockPane.java, to add the animation into this class and add
Rewrite Listing 32.6, ThreadCooperation.java, using the object’s wait() and notifyAll() methods.Data from Listing 32.6, 1mport java.util.concurrent.: 2 1mport java.util.concurrent. locks.: 1 3 4
Revise Listing 32.10, ParallelMergeSort.java, to define a generic parallelMergeSort method as follows:public static > voidparallelMergeSort(E[] list)Data from Listing 32.10, 1mport
Programming Exercise 8.5 describes how to perform matrix addition. Suppose you have multiple processors, so you can speed up the matrix addition. Implement the following method in parallel:public
EightQueens.java, to develop a parallel algorithm that finds all solutions for the Eight Queens problem. Launch eight subtasks, each of which places the queen in a different column in the first row.
An alternative version of the Dijkstra algorithm can be described as follows:The algorithm uses cost[v] to store the cost of a shortest path from vertex v to the source vertex s. cost[s] is 0.
Since T is implemented using a list in the getMinimumSpanningTree and getShortestPath methods in Listing 29.2, WeightedGraph.java, testing whether a vertex u is in T by invoking T.contains(u) takes
The traveling salesperson problem (TSP) is to find the shortest round-trip route that visits each city exactly once and then returns to the starting city. The problem is similar to finding a shortest
The getShortestPath method finds a u with the smallest cost[u] using a linear search, which takes O( |V| ). The search time can be reduced to O(log|V| ) using an AVL tree. Modify the method using an
Revise GraphView in Listing 28.6 to display a weighted graph. Write a program that displays the graph in Figure 29.1 as shown in Figure 29.24. (Instructors may ask students to expand this program by
Modify Listing 29.3, TestWeightedGraph.java, to create a file for representing graph1. The file format is described in Programming Exercise 29.9. Create the file from the array defined in lines
Write a program that reads a connected graph from a file and displays its minimum spanning tree. The first line in the file contains a number that indicates the number of vertices (n). The vertices
Revise Listing 29.9, WeightedNineTail.java, for the weighted 4 * 4 16 tails problem. Your program should read the model object created from the preceding exercise.Data from Listing 29.9, 1mport
The weighted nine tails problem in the text uses a 3 * 3 matrix. Assume that you have 16 coins placed in a 4 * 4 matrix. Create a new model class named WeightedTailModel16. Create an instance of the
Modify Listing 28.4, UnweightedGraph.java, to override the remove(int u, int v) method defined in the Graph interface.Data from Listing 28.4, 1mport java.util.: 3 publ1c class UnweightedGraph
Modify Listing 28.4, UnweightedGraph.java, to override the remove(V v) method defined in the Graph interface.Data from Listing 28.4, 1mport java.util.: 3 publ1c class UnweightedGraph 1mplements Graph
Listing 28.10, ConnectedCircles.java, allows the user to create circles and determine whether they are connected. Rewrite the program for rectangles. The program lets the user create a rectangle by
Write a program that reads a graph from a file and displays it. The first line in the file contains a number that indicates the number of vertices (n). The vertices are labeled 0, 1, . . . , n−1.
The Hamiltonian path algorithm is implemented in Supplement VI.E. Add the following getHamiltonianCycle method in the Graph interface and implement it in the UnweightedGraph class:/** Return a
Rewrite Programming Exercise 28.14 to enable the user to set an initial pattern of the 4 * 4 16 tails problem (see Figure 28.23a). The user can click the Solve button to display the solution, as
Listing 28.14, NineTail.java, presents a solution for the nine tails problem. Revise this program for the 4 * 4 16 tails problem. Note it is possible that a solution may not exist for a starting
The program in Listing 28.14 lets the user enter an input for the nine tails problem from the console and displays the result on the console. Write a program that lets the user set an initial state
Define a new class named UnweightedGraphFindCycle that extends UnweightedGraph with a new method for finding a cycle starting at vertex u with the following header:public List getACycle(int u);The
Define a new class named UnweightedGraphDetectCycle that extends UnweightedGraph with a new method for determining whether there is a cycle in the graph with the following header:public boolean
Define a new class named UnweightedGraphWithGetPath that extends UnweightedGraph with a new method for finding a path between two vertices with the following header:public List getPath(int u, int
The depth-first search algorithm described in Listing 28.8, Depth-First Search Algorithm, uses recursion. Design a newalgorithm without using recursion. Describe it using pseudocode. Implement it by
Modify Listing 28.2, TestGraph.java, to create a file representing graph1. The file format is described in Programming Exercise 28.1. Create the file from the array defined in lines 8–21 in Listing
Write a program that reads a graph from a file and determines whether the graph is connected. The first line in the file contains a number that indicates the number of vertices (n). The vertices are
The book uses LinkedList for buckets. Replace LinkedList with AVLTree. Assume E is Comparable. Redefine MyHashSet as follows:public class MyHashSet> implementsCollection {...}Test your program
Design a class named Point that meets the following requirements:■ Two data fields x and y for representing a point with getter methods■ A no-arg constructor that constructs a point for (0, 0)■
Design a class named Date that meets the following requirements: ■ Three data fields year, month, and day for representing a date■ A constructor that constructs a date with the specified
The implementations of the methods addAll, removeAll, retainAll, toArray(), and toArray(T[]) are omitted in the MyHashSet class. Implement these methods. Also add a new constructor MyHashSet(E[]
MyArrayList is defined in Listing 24.2. Write a program that generates 1000000 random double values between 0 and 999999 and stores them in a MyArrayList and in a MyHashSet. Generate a list of
Write a program that animates MyHashMap, as shown in Figure 27.9. You can change the initial size of the table. Assume the load-factor threshold is 0.75. O Hashing Separate Chaini x O
You can find the kth smallest element in a BST in O(n) time from an inorder iterator. For an AVL tree, you can find it in O(log n) time. To achieve this, add a new data field named size in
The MyLinkedList class used in Listing 24.5 is a one-way directional linked list that enables one-way traversal of the list.Modify the Node class to add the new data field name previous to refer to
Define a new class named MyBST that extends the BST class with the following method: // Returns true if the tree is an AVL tree public boolean isAVLTree() Use
Huffman coding animation) Write a program that enables the user to enter text and displays the Huffman coding tree based on the text, as shown in Figure 25.23a. Display the weight of the subtree
Write a program that animates the AVL tree insert, delete, and search methods, as shown in Figure 26.2. D AVL Tree Animation by Y C O liveexample.pearsoncmg.com/dsanimation/AVLTreeeBook.html Q * O
Modify Listing 25.8, BSTAnimation.java, to add three new buttons—Show Inorder, Show Preorder, and Show Postorder—to display the result in a label, as shown in Figure 25.22. You need also to
Write a program that prompts the user to enter a file name, then displays the frequency table of the characters in the file and the Huffman code for each character.
Design and write a complete test program to test if the BST class in Listing 25.4 meets all requirements.Data from Listing 25.4 1 publ1c class BST 1mplements Tree { protected TreeNode root: protected
Define a new class named BSTWithNumberOfNonLeaves that extends BST with the following methods:/** Return the number of nonleaf nodes */public int getNumberofNonLeaves()Use
Define a new class named BSTWithNumberOfLeaves that extends BST with the following methods:/** Return the number of leaf nodes */public int getNumberOfLeaves()Use
A perfect binary tree is a complete binary tree with all levels fully filled. Define a new class named BSTWithTestPerfect that extends BST with the following methods: (Hint: The number of nodes in a
Define a new class named BSTWithHeight that extends BST with the following method: /** Return the height of this binary tree */public int height()Use
Design and write a complete test program to test if the MyLinkedList class in Listing 24.5 meets all requirements.Data from Listing 24.5 1 publ1c class MyLinkedList 1mplements MyList private Node
Design and write a complete test program to test if the MyArrayList class in Listing 24.2 meets all requirements.Data from Listing 24.2 1 publ1c class MyArrayList 1mplementS MyList { publ1c stat 1c
Listing 24.8, uses a heap to implement the priority queue. Revise the implementation using a sorted array list to store the elements and name the new class PriorityQueueUsingSortedArrayList.
The implementations of the methods addAll, removeAll, retainAll, toArray(), and toArray(T[]) are omitted in the MyList interface. Implement these methods. Test your new MyList class using the code at
The implementations of the methods contains(E e), get(int index), indexOf(E e), lastIndexOf(E e), and set(int index, E e) are omitted in the MyLinkedList class. Implement these methods. Define a new
Write a program that animates the partition for a quick sort. The program creates a list that consists of 20 random numbers from 1 to 999. The list is displayed, as shown in Figure 23.22b. Clicking
Write a program that animates the merge of two sorted lists. Create two arrays, list1 and list2, each of which consists of 8 random numbers from 1 to 999. The array elements are displayed, as shown
Write a program that animates the radix-sort algorithm. Create an array that consists of 20 random numbers from 0 to 1,000. The array elements are displayed, as shown in Figure 23.21. Clicking the
Write a program that animates the selection-sort algorithm. Create an array that consists of 20 distinct numbers from 1 to 20 in a random order. The array elements are displayed in a histogram, as
Write a program that animates the bubble-sort algorithm. Create an array that consists of 20 distinct numbers from 1 to 20 in a random order. The array elements are displayed in a histogram, as shown
Implement the clone and equals method in the Heap class. Use the template at liveexample.pearsoncmg.com/test/Exercise23_11.txt for your code.
The bin packing problem is to pack the objects of various weights into containers. Assume each container can hold a maximum of 10 pounds. The program uses an algorithm that places an object with the
Write a program that finds all prime numbers up to 10,000,000,000. There are approximately 455,052,511 such prime numbers. Your program should meet the following requirements:■■ Your program
Section 22.8 introduced an algorithm for finding the closest pair of points using a divide-and-conquer approach. Implement the algorithm to meet the following requirements: ■■ Define a class
Write an O(n) time program that prompts the user to enter a sequence of integers ending with 0 and finds the longest subsequence with the same number. Here is a sample run of the program: Enter a
Revise the implementation for the Boyer-Moore algorithm in Listing 22.15 StringMatchBoyerMoore. java to test where a mismatch character is in the pattern in O(1) time using a set that consists of all
Revise Programming Exercise 21.11 to prompt the user to enter year, gender, and name and display the ranking for the name. Prompt the user to enter another inquiry or exit the program. Here is a
Write a program that prompts the user to enter a string and displays the maximum increasingly ordered subsequence of characters. Analyze the time complexity of your program. Here is a sample run:
Write a program that prompts the user to enter a string and displays the maximum consecutive increasingly ordered substring. Analyze the time complexity of your program. Here is a sample run: Enter a
Use the data files from Programming Exercise 12.31 to write a program that enables the user to select a year, gender, and enter a name to display the ranking of the name for the selected year and
Write a program that prompts the user to enter one of the filenames described in Programming Exercise 12.31 and displays the names that are used for both genders in the file. Use sets to store names
Write a program that converts a Java file into an HTML file. In the HTML file, the keywords, comments, and literals are displayed in bold navy, green, and blue, respectively. Use the command line to
Rewrite Listing 21.9 to read the text from a text file. The text file is passed as a command-line argument. Words are delimited by whitespace characters, punctuation marks (,;.:?), quotation marks
Write a program that prompts the user to enter a text file name and displays the number of vowels and consonants in the file. Use a set to store the vowels A, E, I, O, and U.
Modify Listing 20.12, EvaluateExpression.java, to add operators ^ for exponent and % for remainder. For example, 3 ^ 2 is 9 and 3 % 2 is 1. The ^ operator has the highest precedence and the %
Write the following generic method using selection sort and a comparator:public static void selectionSort(E[] list,Comparator comparator)Write a test program that prompts the user to enter six
Showing 100 - 200
of 348
1
2
3
4