1. Which of the following statements is FALSE?
a. A transformer operation changes the object (e.g. list.add(element) changes the list by adding an element)
b. An observer operation may also modify the object (e.g. list.isFull( ) may increase the size of the list if no more elements can be added)
c. An observer operation returns information about an object (e.g. list.size() returns the number of elements in the list)
d. A transformer operation may or may not return a value.
2. Which of the following statements is FALSE?
a. A checked exception should be used when the programmer (user of the ADT) can (most likely) fix the problem.
b. An exception breaks the normal flow of execution.
c. public void testMe( ) throws FileNotFoundException indicates that the method testMe must handle the FileNotFoundException (if one occurs).
d. A try block may have more than one catch block.
3. Which of the following statements is FALSE? (StackInterface is the one from class.)
a. A class that implements an interface may include methods which are not defined in the interface.
b. StackInterface words; is a valid declaration. c. words = new StackInterface (); is a valid Java statement.
d. A class may implement more than one interface.
4. The toString method to the right is defined (with other methods not shown here) in the class WrdLst. What happens when the code below it is executed?
a) Run-time error (exception);
b) Syntax error.
c) no word is printed
d) my no word is printed e) no word + no word is printed
5. Which of the following sequences of operations essentially leaves an unbounded stack unchanged?
a) pop followed by push
b) push followed by pop
c) pop followed by top
d) push followed by top
e) top followed by push public String toString () { return "no word"; } WrdLst my = new WrdLst(); System.out.println ("my " + my);
6. For each statement determine whether it is true or false by circling the corresponding word.
a. True or False? The Queue ADT defined (in CS 221) is generic.
b. True or False? The element that has been in a queue the longest is at the "rear" of the queue.
c. True or False? It is possible to implement an unbounded queue using an array-based approach.
d. True or False? It is possible to implement a bounded stack using a linked-list approach.
7. The algorithm discussed in class for balancing parentheses and used in lab 3 for checking HTML expressions uses a stack. What is the information on the stack just prior to processing the last ) in the following parentheses expression: { [ ( ) ] ( { ) ?
a. stack bottom: { ( { stack top
b. stack bottom: { [ ( ) ] ( { stack top
c. stack bottom: { stack top
d. stack bottom: { [ ( ( { stack top
8. Assume you are using the array-based queue using a floating-front approach and have just instantiated a queue with capacity 6. You enqueue 6 elements, dequeue 3 elements, and then enqueue 2 more elements. What are the values of front, rear, and numOfElements?
front: _________
rear: ______
numOfElemen
Answer 1:
b. An observer operation may also modify the object (e.g.
list.isFull( ) may increase the size of the list if no more
elements can be added)
Here isList will just return the value will not increase
Answer 2:
c. public void testMe( ) throws FileNotFoundException indicates
that the method testMe must handle the FileNotFoundException (if
one occurs).
testMe() will not handle the exception the method which uses testMe() needs to handle the eception
Answer 3:
b. StackInterface words; is a valid declaration. c. words = new StackInterface (); is a valid Java statement.
for interface we can't create the objects
Answer 5:
push followed by pop
as it adds removes element from stack
as it follows Last In First Out Principle
I have answered 1,2,3,5. Please post the other questions in different post
Note : Please comment below if you have concerns. I am here to help you
Get Answers For Free
Most questions answered within 1 hours.