New Semester
Started
Get
50% OFF
Study Help!
--h --m --s
Claim Now
Question Answers
Textbooks
Find textbooks, questions and answers
Oops, something went wrong!
Change your search query and then try again
S
Books
FREE
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
Tutors
Online Tutors
Find a Tutor
Hire a Tutor
Become a Tutor
AI Tutor
AI Study Planner
NEW
Sell Books
Search
Search
Sign In
Register
study help
computer science
data structures and other objects using java
Data Structures And Other Objects Using Java 4th Edition Michael Main - Solutions
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 on. The levels argument determines how many levels the section numbers have. For example, if levels is
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 capable of continuing to any specified level.This was written by call number 2.This was written by call
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 vector) of queues to simulate the lines. Assume that there are five cashier lines at the grocery
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 air. A plane will crash unless it lands within the time assigned to it. Your simulation will keep
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 runway at a time, so there can be only one takeoff or one landing in progress at any one time.
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. These customers should have their cars washed one after another, but no new customers should be
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. Specify, design, and implement a class for a double-ended queue. Include operations to check if it is
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). A circular linked list is similar to a regular linked list, except that the link field in the
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 array of queues might be impractical. In this case, you might think of several alternatives. One
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 Specification and Implementation of the Array Version of the Generic Queue Class Generic Class ArrayQueue
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 as long as this maximum, any customer who arrives will leave without entering the queue (because the
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 of letters. In this exercise, you are to write a program that runs a similar check using lines
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 one in which we look at words rather than letters. A word-by-word palindrome is a string of words
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 following:1. The bottom of the first stack is the beginning of the sequence.2. The elements of 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 items should be reversed.
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 whether or not it is a palindrome.
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 to the calling program.
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 we implement the stacks as arrays, there is a chance that one array (and hence one stack) will
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 queens are in the same column, and no two queens are on the same diagonal? For example, a solution with
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 number appears, push it onto the numbers stack. Any parenthesis or operator should be treated as
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 postfix notation. After that, it will evaluate the postfix expression. Pseudocode for both of these
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. Assume that the input may contain numbers, variables, and arithmetic operations (+, –, *, and /), as
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 (but no variables) as well as the arithmetic operations +, –, *, and /. Your program should allow
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 operations, the input expressions for this program will use the operations && (the “and”
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 another expression and is allowed to choose between evaluating another expression and quitting the
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 first ... last of characters. The following is an outline for an algorithm to do this using a stack.
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// item that is n from the top (with the top at// n = 0, the next at n = 1, and so on). The// stack is
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 an enter button that reads the number from the text field and pushes this number onto the stack.
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 method is activated, the iterator, it, is already in some collection. The method searches the
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 all uppercase letters are converted to the corresponding lowercase letter.
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 reference to the original item into the bag). Because you don’t know whether the type of items in
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 elements are now references to objects; both the original and the copy contain references to the same
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 completed by the student. The courses taken by a student are stored as a linked list in which each node
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 for a list of 10 nouns.2. Asks the user for a list of 10 verbs.3. Prints some random sentences using
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 chores; (2) Ask how many chores are in the list; (3) Print the list of chores to the
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 Iterable interface.
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 is called the count, and the second integer is called the data. As an example, if a node has a
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 while playing the game). Each player should be an object from a player class that you write
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 the tail pointer points back to the first node. In this project, an extra reference variable is used
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 function that moves the cursor backward to the previous element. Also, use a dummy head and a dummy
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. Rather than a head reference, you should have an instance variable that keeps track of the node that
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 change the removal method so that the node that activates the method removes itself from the list.
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 exponents are stored in a linked list. This linked list should contain no more than one node for any
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, DoubleArraySortedSeq. In the new class, the add method always puts the new element so that all the elements
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 interactive testing of the sequence class from the previous project.Appendix IIt’s useful to have a
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 an ADT for unbounded whole numbers in which a number is implemented as a linked list of integers.
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 to remove the element at the front of the sequence; (3) A method to add a new element at the
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 has two copies of the number 3. Then, after activating x.subtract(y), the bag x will have five
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 head of the list. Your method should preserve repetitions of integers. If the original list had any
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 two linked lists: one containing all the nodes that contain an element less than the splitting
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. The method should create a new linked list that contains all the elements on both lists, and the new
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 method returns a head reference for the new list.
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 System.out containing all integers in the list that are between the first occurrence of x and the first
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 original list but with all repetitions removed. The method’s return value is a head reference for the new
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. A small text field3. A large text areaEach time the button is clicked, the applet should read an
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 this bag is to have a private instance variable that is an array of integers called count with indexes
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, for this project, you might find it easier to store the digits backward, that is, place 4 in a[0],
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 movies that the actor has appeared in. The program reads the initial information for these arrays
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 of chores; (2) ask how many chores are in the list; (3) use the iterator to print the list of chores
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 duplicate entry, print a message that says how many times that entry occurred in the multiset.
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 clone method that creates a new string and a new Date object for the newly cloned Person. It should
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 is stored in a separate instance variable, which is +1 for a positive number and –1 for a
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 to the keyed bag must have a unique key; two items cannot have the same key. For this project,
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 removed is different. Each time a string is added to a bag with receipts, the insert method returns
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 should include a method to put a double number into the “array” at a specified index. For example,
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 it’s easier to keep track of all the input numbers using a single array (called frequency) with indexes
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 half of the numbers and is also less than or equal to at least half of the numbers.Because of the
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 string and put the copy into the clone rather than the original. Also, when you are comparing two
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 digits can be stored in an array of int, and the sign of the number can be stored in a separate
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 of rings that stack on the pegs. The rings are different sizes. The initial configuration for a
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 rings, with each ring having its own diameter. Also, there is a rule that requires each ring to be
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 poker hands. For two hands x and y, the relation x.beats(y) means that x is a better hand than y. If
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). There should be a method to ask the object to make its next move and a method that tells the object
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. There is no addBefore or addAfter method. All the other methods are the same as in the original
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, which can contain only a single copy of any given element. Write a new collection class called
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 test class methods. Such a program can be written as a Java applet, which is a Java program written
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 remove the element at the front of the sequence; (3) A method to add a new element at the end of
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 = IntArrayBag.union(b2, b3).Appendix IIt’s useful to have a small interactive test program to help
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 variables are inside an opaque black box where they cannot be seen, so all testing must occur only through
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 bag that activates the method have exactly the same number of every element. Otherwise, the method
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 that the vehicle has traveled. You may choose whatever units you like (for example, fuel could be
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 the number. The class should have two instance variables to represent the real and imaginary numbers;
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 salary and increase the salary by a certain percentage. Add additional members to store the paycheck
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 date in both number and word format.
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 represents a satellite in orbit around the Earth’s equator. Each object has four instance
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 should also implement a no-arguments constructor that sets both the balance and the interest rate to
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 have a numerator of 5 and a denominator of 6. Include a constructor with two arguments that can be used
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). Also include these extra methods:1. Two accessor methods that return the maximum temperature that the
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 babies can use random numbers for the birth weights of the newborns. But these birth weights should
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). Divide this range into 10 intervals and call the method one million times, producing a table such as
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 number divided by the modulus. (You will have to cast the modulus to a double number before carrying
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 congruence method, explained below. The linear congruence method starts with a number called the seed. In
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 lander is constructed, the following items should be initialized as follows:(1). Current fuel flow rate
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 expression 2x2 + 8x + 6 has one of its real roots at x= -3 because substituting x= -3 in the formula 2x2
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 values. Specify, design, and implement a class that can store information about a quadratic expression.
Showing 400 - 500
of 507
1
2
3
4
5
6
Step by Step Answers