Question

1. Which of the following statements is FALSE? a. A transformer operation changes the object (e.g....

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

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The dequeue operation as defined for the text's Queue ADT might throw the QueueUnderflowException. Group of...
The dequeue operation as defined for the text's Queue ADT might throw the QueueUnderflowException. Group of answer choices True False Our LinkedQueue class extends the QueueInterface interface. Group of answer choices True False A dequeue is like a queue but: Group of answer choices it uses priorities. it allows enqueuing and dequeuing from both front and rear. it keeps its elements sorted. it allows peeking at front and rear elements. The text's array-based queue is being used and holds a...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None:...
Create an add method for the BST (Binary Search Tree) class. add(self, new_value: object) -> None: """This method adds new value to the tree, maintaining BST property. Duplicates must be allowed and placed in the right subtree.""" Example #1: tree = BST() print(tree) tree.add(10) tree.add(15) tree.add(5) print(tree) tree.add(15) tree.add(15) print(tree) tree.add(5) print(tree) Output: TREE in order { } TREE in order { 5, 10, 15 } TREE in order { 5, 10, 15, 15, 15 } TREE in order {...
Consider a generic Stack class implemented using linked list with the following methods: public boolean isEmpty(),...
Consider a generic Stack class implemented using linked list with the following methods: public boolean isEmpty(), which returns true if and only if the stack is empty; public T pop() throws StackUnderflowException, which removes and returns the top element of the stack (if the stack is empty, it throws StackUnderflowException); public T peek() throws StackUnderflowException, which returns the top element of the stack (but does not remove it; it throws exception if stack is empty); public void push(T element), which...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity  ...
I'm having a warning in my visual studio 2019, Can anyone please solve this warning. Severity   Code   Description   Project   File   Line   Suppression State Warning   C6385   Reading invalid data from 'DynamicStack': the readable size is '(unsigned int)*28+4' bytes, but '56' bytes may be read.   Here is the C++ code were I'm having the warning. // Sstack.cpp #include "SStack.h" // Constructor SStack::SStack(int cap) : Capacity(cap), used(0) {    DynamicStack = new string[Capacity]; } // Copy Constructor SStack::SStack(const SStack& s) : Capacity(s.Capacity), used(s.used)...
(JAVA) Why is my toString method not printing out the last node? It will not print...
(JAVA) Why is my toString method not printing out the last node? It will not print out "A" which is for Alice. Everything else is working just fine except for this. package driver; import exception.StackException; import stack.*; public class StackDriver { public static void main(String[] args) throws Exception { StackInterface<Painting> painting = new LinkedStack <Painting>(); try { System.out.println("Peeking at top of player stack.\n" + painting.peek()); }catch (StackException e) { System.out.println(e); System.out.println("Let's double check if it's empty: " + painting.isEmpty()); }...
Code in JAVA The requirements are as follows: The input will be in a text file...
Code in JAVA The requirements are as follows: The input will be in a text file whose name is given by arg[0] of main(). It will contain a fully-parenthesized infix expression containing only: "(", ")", "+", "-" and integers. Need help on the main and fixing the Queue. //Input: ( ( 1 + 2 ) - ( ( 3 - 4 ) + ( 7 - 2 ) ) ) ( ( 1 + 2 ) - ( 3 -...
I've posted this question like 3 times now and I can't seem to find someone that...
I've posted this question like 3 times now and I can't seem to find someone that is able to answer it. Please can someone help me code this? Thank you!! Programming Project #4 – Programmer Jones and the Temple of Gloom Part 1 The stack data structure plays a pivotal role in the design of computer games. Any algorithm that requires the user to retrace their steps is a perfect candidate for using a stack. In this simple game you...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):...
I NEED TASK 3 ONLY TASK 1 country.py class Country:     def __init__(self, name, pop, area, continent):         self.name = name         self.pop = pop         self.area = area         self.continent = continent     def getName(self):         return self.name     def getPopulation(self):         return self.pop     def getArea(self):         return self.area     def getContinent(self):         return self.continent     def setPopulation(self, pop):         self.pop = pop     def setArea(self, area):         self.area = area     def setContinent(self, continent):         self.continent = continent     def __repr__(self):         return (f'{self.name} (pop:{self.pop}, size: {self.area}) in {self.continent} ') TASK 2 Python Program: File: catalogue.py from Country...
QUESTION 1 Which one of the following would NOT be necessary for an offer to have...
QUESTION 1 Which one of the following would NOT be necessary for an offer to have legal standing? A. The language must reflect the intent to become a party to a contract. B. All of the conditions under which the offer would be terminated must be identified. C. All the significant terms and/or conditions must be contained in the offer. D. The offer must be effectively communicated to the other party. 3 points    QUESTION 2 Which one of the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT