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
data structures and other objects using java
Questions and Answers of
Data Structures and Other Objects Using Java
Write a method with two parameters, prefix (a string) and levels (a nonnegative integer). The method prints the string prefix followed by “section numbers” of the form 1.1., 1.2., 1.3., and so
Write a method that produces the output shown below. This output was written by call number 1. In the example, the recursion stopped when it reached four levels deep, but your method should be
Use a circular array or a doubly linked list to implement a deque.
Write a program that uses a priority queue to store a list of prioritized chores.
Write a simulation program of the lines at a grocery store. The program will be similar to the car wash simulation, except that there are multiple queues instead of one. You might use an array (or
Do an airplane simulation that is more complex than the previous project. In this version, planes arrive for landing with a random amount of fuel, which determines how long they can remain in the
Write a simulation program for a small airport that has only one runway. There will be a queue of planes waiting to land and a queue of planes waiting to take off. However, only one plane can use the
Make improvements to the car wash simulation program from Section 7.2. One particular improvement you should make is to handle the customers who are still in the queue at the end of the simulation.
A double-ended queue is a list that allows the addition and removal of items from either end. One end is arbitrarily called the front and the other the rear, but the two ends behave identically.
In this chapter, we gave a linked list implementation of a queue. This implementation used two references, called front and rear, to refer to the front and the rear nodes of the queue (linked list).
Give a complete implementation of a priority queue using the idea from the direct implementation.Priority Queue ADT—A Direct ImplementationIf the number of possible priorities is large, then an
Give a complete implementation of a priority queue using an array of ordinary queues. For your ordinary queue, use the version from edu.colorado.collections.ArrayQueue in Figure 7.9. FIGURE 7.9
Enhance the car wash simulation method in Figure 7.8 so that it has the following additional property. There is an additional parameter, which is a maximum length for the queue. When the queue gets
In Figure 7.3, we presented a program that checks a string to see if the letters in the string read the same forward and backward. The previous exercise performed a similar check using words in place
In Figure 7.3, we presented a program that checks a string to see if the letters in the string read the same forward and backward. These strings are called palindromes. Another kind of palindrome is
Here’s a new idea for implementing the sequence class from Section 4.5. Instead of the items being stored on a linked list, they will be stored using two stacks as private member variables with the
For any of your stack implementations, please write a new method called flip with no parameters. After a stack x activates the flip method, x should contain the same items, but the order of those
In this project, you will use stacks to recognize palindromes. Palindromes are strings that read the same backward as forward (for example, “madam”). Write a program to read a line and print
Write a method that compares two stacks for equality. The method takes two stacks as parameters and returns true if they are identical. The stacks should remain unchanged after the function returns
Choose one of your stack implementations and write a static method to display the contents of a stack from top to bottom. Then, implement a static method to display the stack bottom to top.
In our first case study on evaluating arithmetic expressions, we used two stacks that held different types of data. In some other applications, we might need two stacks with the same type of data. If
Suppose that you have n queens from a chess game, and that you also have an n-by-n chess board. Is it possible to place all n queen on the board so that no two queens are in the same row, no two
Write a program that evaluates an arithmetic expression in infix notation, without full parentheses. Use the following algorithm: There are two stacks: a numbers stack and an operators stack. When a
Redo the calculator program given in Figure 6.5 on page 330, but this time implement it in a different way. To evaluate the arithmetic expression, your program will first convert the expression to
Write a program that takes as input an infix expression and outputs the equivalent postfix expression. The basic algorithm is contained in “Translating Infix to Postfix Notation” on page 348.
Write a program that evaluates an arithmetic expression in postfix notation. The basic algorithm is contained in “Evaluating Postfix Expressions” on page 345. Assume the input contains numbers
In Figure 6.5 on page 330, we presented a program to evaluate arithmetic expressions. In this exercise, you will write a similar program to evaluate boolean expressions. Rather than arithmetic
Enhance the calculator program given in Figure 6.5 on page 330 so that it has all of the following features: After one expression is evaluated, the user is asked if he or she wants to evaluate
In this exercise, you will need the itemAt method from the previous programming project. Write a program that prints all strings with at most n letters, where the letters are chosen from a range
Choose one of the stack implementations and implement a method with this specification:Object itemAt(int n)// Precondition: 0 <= n and n < size( ).// Postcondition: The return value is the//
Write an applet that is a simple stack-based calculator. The calculator should have a text field where you can enter a double number and a text area that displays a stack of numbers. There should be
Write a group of generic static methods for examining and manipulating a collection of items via the collection’s iterator. For example, one of the methods might have this heading:When the find
Write an interactive program that uses a TreeMap to store the names and phone numbers of your friends.
Rewrite the word counting program from Section 5.7 so that the user can specify the name of the input file. Also, modify the proso that all non-letters are removed from each word as it is read, and
Modify the bag from the previous exercise so that all of the add methods attempt to make a clone of any item that is added to the bag. These clones are then put in the bag (rather than just putting a
The bag’s clone method creates a copy of an ArrayBag. As with other clone methods, adding or removing elements from the original bag will not affect the copy, nor vice versa. However, these
Write a program for keeping a course list for each student in a college. The information about each student should be kept in an object that contains the student’s name and a list of courses
For this project, you will use the bag class from Section 5.6, including the grab method that returns a randomly selected element. Use this ADT in a program that does the following:1. Asks the user
Write a program that uses a bag of strings to keep track of a list of chores you have to accomplish today. The user of the program can request several services: (1) Add an item to the list of
Implement a generic class for a sequence of Java objects. You can store the objects in an array (as in Section 3.3) or in a linked list (as in Section 4.5). The class should also implement the
Reimplement the bag class from Figure 4.17 so that the items of the bag are stored with a new technique. Here’s the idea: Each node of the noefw linked list contains two integers. The first integer
Use a circular linked list to run a simple simulation of a card game called Crazy 8s. You can use any online rules that you find. The circular linked list is to hold the players (who sit in a circle
In this project, you will implement a variation of the linked list called a circular linked list. The link field of the final node of a circular linked list is not NULL; instead, the link member of
Use a doubly linked list to implement the sequence class from Section 4.5. With a doubly linked list, there is no need to maintain a precursor. Your implementation should include a retreat member
Revise the Statistician with median (Programming Project 15 on page 172) so that it stores the input numbers on a doubly linked list using the doubly linked node class from the previous project.
Implement a node class in which each node contains a double number and each node is linked both forward and backward. Include methodms eththaot dasre similar to the node class from this chapter, but
Implement a node class in which each node contains both an integer and a double number. Use this class to reimplement the polynomial class from Section 3.4 so that the coefficients and their
Revise the sorted sequence (Project 7 on page 170) so that it stores the items on a linked list instead of in an array.Data from Project 7Rewrite the sequence class using a new class name,
Revise the set class (Programming Project 5 on page 169) so that it stores the items in a linked list instead of in an array.Data from Project 5Using Appendix I as a guide, implement an applet for
You can represent an integer with any number of digits by storing the integer as a linked list of digits. A more efficient representation will store a larger integer in each node. Design and
Implement the sequence class from Section 4.5. You may wish to provide some additional useful methods, such as: (1) A method to add a new element at the front of the sequence; (2) A method
Implement a new method for the bag class from Section 4.4. The new method allows you to subtract the contents of one bag from another. For example, suppose x has seven copies of the number 3 and y
Write a method that takes a linked list of integers and rearranges the nodes so that the integers stored are sorted into the order of smallest to largest, with the smallest integer in the node at the
Write a method that starts with a single linked list of integers and a special value called the splitting value. The elements of the list are in no particular order. The method divides the nodes into
Write a method that has two linked list head references as parameters. Assume that linked lists contain integer data, and on each list, every element is less than the next element on the same list.
Write a method with one parameter that is a head reference for a linked list of integers. The method creates a new list that has the same elements as the original list but in the reverse order. The
Write a method with three parameters. The first parameter is a head reference for a linked list of integers, and the next two parameters are integers x and y. The method should write a line to
Write a new static method for the node class. The method has one parameter, which is a head node for a linked list of integers. The method computes a new linked list, which is the same as the
For this project, you will use the bag of integers from Section 4.4. The bag includes the grab method from Figure 4.16 on page 229. Use this class in an applet that has three components:1. A button2.
Suppose that you want to implement a bag class to hold non-negative integers, and you know that the biggest number in the bag will never be more than a few thousand. One approach for implementing
An array can be used to store large integers one digit at a time. For example, the integer 1234 could be stored in the array a by setting a[0ti]ngtox1x,xa[1] to 2, a[2] to 3, and a[3] to 4. However,
Write a program that contains two arrays called actors and roles, each of size n. For each i, actors[i] is the name of an actor and rolaensd[i] is a HashSet of strings that contains the names of the
Write a program that uses a HashSet of strings to keep track of a list of chores that you have to accomplish today. The user of the program can request several services: (1) add an item to the list
Write a program that reads a list of ninedigit numbers from the keyboard. It stores the numbers in a bag, and then goes through the bagtthoedetermine whether there are any duplicate entries. For each
Create a Person class that stores a name and birthday of a person. The name can be a String and the birthday can be a Date object from Project 19 of Chapter 2. The Person class should have both a
Specify, design, and implement a class where each object keeps track of a large integer with up to 100 digits in base 10. The digits are stored in an array of 100 elements, and the sign of the number
Another way to store a collection of items is called a keyed bag. In this type of bag, whenever an item is added, the programmer using the bag also provides an integer called the key. Each item added
In this project, you will implement a new class called a bag with receipts. This new class is similar to an ordinary bag, but the data consists of strings, and the way that the strings are added and
Design, specify, and implement a collection class that is similar to an array of double numbers except that it automatically grows when wneheedned and negative indexes are also permitted.The class
Implement the previous project with the following modification: All of the input numbers to the Statistician are required to be integers in the range from 0 to 100. This modification means that
Implement the Statistician class from Project 2 on page 95, but include a new method that returns the median value of all the numbers. The median is a number that is greater than or equal to at least
Revise the bag class so that it is a bag of strings rather than integers. For the methods that add strings to the bag, you should alwaysaulwseaythse string’s clone method to make a copy of each
This project is to implement a class that is similar to Java’s Math.BigInteger class. Each object in your class keeps track of an integer iwntietghearn unlimited number of digits in base 10. The
In this project, you will design and implement a class called Towers, which is part of a program that lets a child play a game called Towers of Hanoi. The game consists of three pegs and a collection
Specify, design, and implement a class that keeps track of rings stacked on a peg, rather like phonograph records on a spindle. An example with five rings is shown here:The peg may hold up to 64
Specify, design, and implement a collection class that can hold up to five playing cards. Call the class PokerHand, and include a methodmweitthhoad boolean return value to allow you to compare two
Specify, design, and implement a class that can be one player in a game of tic-tac-toe. The constructor should specify whether the object is to be the first player (Xs) or the second player (Os).
A one-variable polynomial is an arithmetic expression of the form:a0 + a1x + a2x2 + … akxkImplement the polynomial class described in Section 3.4.
Rewrite the sequence class using a new class name, DoubleArraySortedSeq. In the new class, the add method always puts the new element so that all the elements stay in order from smallest to largest.
A bag can contain more than one copy of an element. For example, this chapter describes a bag that contains the number 4 and two copies of the number 8. This bag behavior is different from a set,
Using Appendix I as a guide, implement an applet for interactive testing of the sequence class from the previous project.Appendix IIt’s useful to have a small interactive test program to help you
Implement the sequence class from Section 3.3. You may wish to provide some additional useful methods, such as:(1) A method to add a new element at the front of the sequence; (2) A method to
Study the BagApplet from Appendix I and write an expanded version that has three bags and buttons to activate any method of any bag. Also include a button that will carry out an action such as:b1 =
A black box test of a class is a program that tests the correctness of a class without directly examining the private instance variables of the class. You can imagine that the private instance
For the IntArrayBag class, implement a new method called equals with a boolean return value and one parameter. The parameter, called b, is another IntArrayBag. The method returns true if b and the
Write a class called fueler that can keep track of the fuel and mileage of a vehicle. Include private instance variables to track the amothuent of fuel that the vehicle has consumed and the distance
Write a class for complex numbers. A complex number has the form a + bi, where a and b are real numbers and i is the square root of -1. We refer to a as the real part and b as the imaginary part of
Specify, design, and implement a class called Employee. The class has instance variables for the employee’s name, ID number, andbesralary based on an hourly wage. Methods can compute the yearly
Specify, design, and implement a class called Date. Use integers to represent a date’s month, day, and year. Write a method to incretmo ent the date to the next day.Include methods to display a
This project requires a little understanding of velocity and gravity, but don’t let that scare you away! It’s actually an easy project. The assignment is to write a class in which each object
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the baland theanacnenual interest rate to some initial values (and you
Write a class for rational numbers. Each object in the class should have two integer values that define the rational number: the numerator and the denominator. For example, the fraction 5/6 would
Implement the Thermometer class from Self-Test Exercise 16 on page 60. Make sure that the methods to alter the temperature do not allow the temperature to drop below absolute zero (–273.16°C).
This project is a continuation of the previous project. Many applications require pseudorandom number sequences that are not uniformly distributed. For example, a program that simulates the birth of
Run some experiments to determine the distribution of numbers returned by the new pseudorandom method from the previous project. Recall that this method returns a double number in the range [0..1).
Add a new method to the random number class of the previous project. The new method generates the next pseudorandom number but does not return the number directly. Instead, the method returns this
In this project, you will design and implement a class that can generate a sequence of pseudorandom integers, which is a sequence that appears random in many ways. The approach uses the linear
Specify, design, and implement a class that can be used to simulate a lunar lander, which is a small spaceship that transports astronauts from lunar orbit to the surface of the moon. When a lunar
This project is a continuation of the previous project. For a quadratic expression such as ax2 + bx + c, a real root is any double number x such that ax2 + bx + c = 0. For example, the quadratic
A one-variable quadratic expression is an arithmetic expression of the form , where ax2, bx, and c are some fixed numbers (called the coefficients) and x is a variable that can take on different
Showing 400 - 500
of 507
1
2
3
4
5
6