Ch 11 Queue Implementation, JAVA ALL QUESTIONS SET 2, Chapter 10 - Queues, Deques, and Priority Queues, Final Exam, samm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

An array potentially wastes more space than a chain.

True

Each node in an ordinary linked chain references only the next node.

True

Entries of a bag can belong to classes related by inheritance.

True

In a circular array-based implementation of a queue, the available locations are not contiguous.

True

In a circular array-based implementation of a queue, you cannot use only frontIndex to determine when a queue is full.

True

The Java Class Library ADT PriorityQueue uses the compareTo method to determine how to order entries.

True

The Java Class Library interface for Queue has no operation to modify the contents of the front entry

True

The Java Class Library interface for Queue has no operation to modify the contents of the front entry.

True

If we use a chain of linked nodes with only a head reference to implement a queue which statement is true?

You must traverse the entire chain to access the last node. Accessing the last node is very inefficient.

If a bag is empty before the remove method executes, it a. returns null b. throw an exception c. returns an error message d. all of the above

a

to accommodate entries of any class, the bag methods use ______. a. a generic type b. an inherited type c. a sub class d. all of the above

a

Which of the following is a value that is written into the code of a program? *********

a literal

What does the following UML diagram entry mean? + setHeight(h : double) : void

a public method with a parameter of data type double that does not return a value

RAM is usually

a volatile type of memory, used for temporary storage.

A static field is created by placing the key word static

after the access specifier and before the field's data type.

A call to the remove method with no arguments a. removes the first node b. removes the last node c. removes a random node d. asks the user which node to remove

A

A common alias for the queue method getFront is a. peek b. get c. put d. all of the above

A

The ____ ADT organizes its entries according to the order in which they were added. a. queue b. stack c. list d. priority queue

A

Which of the following is(are) used as delimiters if the StringTokenizer class's constructor is called and a reference to a String object is passed as the only argument?

All of these

When removing a node from a two-part circular linked chain implementation of a queue a. the entry at the front of the queue is returned b. the node is moved to the part of the chain that is available for the enqueue method c. the queueNode is advanced d. all of the above

D

(T/F) You should never suppress compiler warnings.

False

A chain requires less memory than an array of the same length.

False

In a linked chain implementation of a queue, the enqueue operation could potentially be dependent on the other entries and will require a search.

False

In a linked chain implementation of a queue, the enqueue operation requires a traversal to the end of the chain to insert a new entry onto the queue.

False

Unlike a stack, a queue does not restrict access to its entries.

False

When defining the bag class write methods that have simple implementation first to get them out of the way.

False

Which of the following is not a rule that must be followed when naming identifiers?

Identifiers can contain spaces.

Which of the following statements is not true about the following code? StringBuilder strb = new StringBuilder("Total numbers of parts: "); strb.insert(23, 32);

The ending position for the insert is 32

The sequential search algorithm

uses a loop to sequentially step through an array, starting with the first element.

What object behaves like a high-level array? a. vector b. linked-chain c. array-chain d. all of the above

vector

When would you choose a two-part circular chain over a circular chain?

when you frequently add an entry after removing one

A collection is not necessarily an abstract data type. a. true b. false

b

Entries of a bag may belong to different classes because items are unordered. a. true b. false

b

You should never suppress compiler warnings. a. true b. false

b

A loop that repeats a specific number of times is known as a(n)

count-controlled

A language-independent specification for a group of values and operations on those values is called a/an: - data structure - none of provided options is applicable as an answer - primitive - abstract data type

data structure

Which of the following is the operator used to determine whether an object is an instance of a particular class?

instanceOf

Which behaviors do not change the contents of a bag? - clear() - add(...) - remove() - none of these

none of these

Which behavior is not specified in the bag ADT? - contains(...) - sort() - clear() - remove()

sort()

In a JavaFX CSS style definition, if a selector name starts with a period, that selector corresponds to a

specific JavaFX node.

A call to the remove method with no arguments on an empty LinkedBag - throws a ListEmptyException - returns false - returns null - throws an IllegalOperationException

throws a ListEmptyException

In a circular array-based implementation of a queue, you cannot use only frontIndexto determine when a queue is full.

true

In a linked chain implementation of a queue, when both the firstNode and lastNode entries are null, the chain is empty.

true

When a circular linked chain has one node, the node references itself.

true

You need two external references for a circular doubly linked chain, one for the firstNode and one forthe lastNode.

true

A top-level class a. is not nested b. is nested in an enclosing class c. is always static d. is defined entirely within another class definition

A

The Java Class Library interface Queue method that retrieves the entry at the front of a queue but returns null if the queue was empty is a. peek b. empty c. poke d. look

A

The Java Class Library interface Queue method that retrieves the entry at the front of a queue but throws a NoSuchElementException if the queue was empty is a. empty b. peek c. poke d. look

A

The Java Class Library interface Queue method to put an entry on the back of a queue that returns false if the method fails is a. offer b. add c. put d. poll

A

The _____ ADT that has operations to add, remove, or retrieve entries at both the front and back of a queue is called a a. deque b. reversible queue c. reversible stack d. all of the above

A

(T/F) When testing a method, you only need to check for arguments that lie within the legal range of their corresponding parameter.

False

(T/F) When using a linked implementation, a bag can never become full.

False

(T/F) You cannot determine the exact number of times a particular item appears in a bag because it is unordered.

False

You need two external references for a circular doubly linked chain, one for the firstNode and one for the lastNode.

False

You should implement all methods of an ADT implementation before testing to make testing easier.

False

What is fail-safe programming?

It is the practice of checking for anticipated errors in your program.

After the method clear, the programmer does not need to worry about deallocating the nodes that were in the chain.

True

A language-independent specification for a group of values and operations on those values is called a/an: a. abstract data type b. data structure c. collection d. primitive

a

A set is a special kind of bag. a. true b. false

a

which method removes one occurrence of a particular entry from a bag if possible? a. remove(anItem) b. clear(anItem) c. delete(anItem) d. empty(anItem)

a

Which behaviors leave the contents of a bag unaltered? - clear() - remove() - contains(...) - add(...)

contains(...)

In a node object, the next field contains a. a reference to another node b. the data portion of the node c. a reference to the beginning of the list d. none of the above

A

In a two-part circular linked chain implementation of a queue, what is the performance when the dequeue operation ? a. O(1) b. O(log n) c. O(n) d. O(n^2)

A

The ADT priority queue organizes objects a. according to priority of the objects b. alphabetically c. from front to back d. from back to front

A

The Java Class Library interface Queue method that retrieves and removes the entry at the front of a queue and returns null if the queue was empty is a. poll b. remove c. retrieve d. get

A

The Java Class Library interface Queue method that retrieves and removes the entry at the front of a queue and throws a NoSuchElementException if the queue was empty is a. remove b. poll c. retrieve d. get

A

The Java Class Library interface Queue method to put an entry on the back of a queue that throws an exception of the method fails is a. add b. offer c. put d. poll

A

The Java Class Library method to resize an array is called a. Arrays.copyOf b. Arrays.resize c. Arrays.copy d. Arrays.double

A

The method for adding a new item to the back of a queue is called a. enqueue b. dequeue c. getFront d. none of the above

A

The method for removing an item from the front of a queue is called a. dequeue b. enqueue c. getFront d. none of the above

A

What item is at the front of the list after these statements are executed? DequeInterface<String> waitingLine = new LinkedDeque<>(); waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getBack(); a. Rudy b. Jack c. Larry d. Sam

A

Where is a new node added to a linked list? a. at the beginning b. at the end c. in the middle d. in a random place

A

Where will you find the item added earliest to a queue? a. at the front b. at the back c. in the middle d. randomly

A

Which bag behavior is not useful or relevant for a set? a. getFrequencyOf() b. add() c. remove() d. contains()

A

Which bag behaviors would need modified when implementing a set? a. add() b. clear() c. contains() d. toArray()

A

Which behavior is not represented in a bag? a. reorder the bag b. report the number of items in the bag c. report if the bag is empty d. add an item to the bag

A

Which behavior is not specified in the bag ADT? a. sort() b. contains() c. clear() d. remove()

A

Which behavior(s) change the contents of a bag? a. add() b. getFrequencyOf() c. contains() d. toArray()

A

Which behavior(s)change the contents of a bag? a. remove() b. getCurrentSize() c. isEmpty() d. getFrequencyOf()

A

Which behaviors leave the contents of a bag unaltered? a. contains() b. remove() c. clear() d. add()

A

Which instruction suppresses an unchecked-cast warning from the compiler? a. @SuppressWarnings("unchecked") b. @SuppressUnchecked() c. @SuppressUncheckedWarnings() d. @Warning("suppress unchecked")

A

Which method can be used to retrieve all of the elements of a bag? a. toArray() b. printBag() c. displayBag() d. getAllItems()

A

Which method removes all entries of a bag? a. clear() b. remove() c. delete() d. empty()

A

Which method removes one occurrence of a particular entry from a bag if possible? a. remove(anItem) b. clear(anItem) c. delete(anItem) d. empty(anItem)

A

Which method removes one unspecified entry from a bag if possible? a. remove() b. clear () c. delete() d. empty()

A

Which method returns a count of the current number of items in a bag? a. getCurrentSize() b. getSize() c. size() d. currentSize()

A

Which of the following are good reasons to write Java statements that use your bag ADT before the implementation is done? a. it helps confirm the design b. it helps check the suitability of the specification c. it helps check your understanding of the specification d. all of the above

A

Which of the following is a disadvantage of using an array to implement the ADT bag? a. increasing the size of the array requires time to copy its entries b. adding an entry to a bag is fast c. removing an unspecified entry from the array is fast d. all of the above

A

Which of the following is a special kind of bag that does not allow duplicate entries? a. set b. collection c. extended bag d. super bag

A

Which of the following is an advantage of using an array to implement the ADT bag? a. adding an entry to a bag is fast b. removing a particular entry requires time to locate the entry c. increasing the size of the array requires time to copy its entries d. the client has control over the size of the bag

A

Why is it a good security practice to declare the ArrayBag to be a final class?

A programmer cannot use inheritance to change its behavior.

Which of the following are properties of a set? a. duplicates are permitted b. elements are stored in order c. elements may not be removed d. none of the above

D

Which of the following methods is a good candidate for a core method: a. add() b. toArray() c. isArrayFull() d. all of the above

D

Which of the following real-world events could be simulated using a queue? a. bank line b. a shared network printer c. restaurant reservation list d. all of the above

D

Which of the following would be suitable items to store in a bag? a. marbles b. coins c. student roster d. all of the above

D

You wish to keep track of the distribution of words in a document, for example, how many times the word "apple" appears. You store each word in the document in a bag. Why is a bag a potentially good solution? a. the order of the words is unimportant b. the words in thedocument are not unique c. getFrequencyOf() is a useful behavior for determining the word distribution d. all of the above

D

(T/F) Code written with respect to an interface makes it difficult to replace one implementation of a bag with another.

False

(T/F) Entries of a bag may belong to different classes (unrelated by inheritance) because items are unordered.

False

(T/F) The outer LinkedBag class can access the data fields of the inner Node class directly without using set and get methods.

False

Code written with respect to an interface makes it difficult to replace one implementation of a bag with another.

False

In a circular array-based implementation of a queue, frontIndex is equal to one less than backIndex when the queue is full.

False

In a circular array-based implementation of a queue, frontIndex is equal to one more than backIndex when the queue is empty.

False

In a circular array-based implementation of a queue, the available locations are not contiguous.

False

In a vector-based implementation of the Stack ADT, the most efficient place to maintain the top entry of a stack is in the vector's first element.

False

In an array-based implementation of the Stack ADT, it is more efficient to have the first array location reference the top of the stack.

False

In an array-based implementation of the Stack ADT, spreading the cost of the push operation when the stack is full yields a performance of O(n).

False

The ArrayDeque class implements the Stack interface.

False

The Queue interface extends the Deque interface.

False

When defining the bag class, you should implement the isArrayFull and removeoperations first.

False

When testing a method, you only need to check for arguments that lie within the legal range of their corresponding parameter.

False

You cannot determine the exact number of times a particular item appears in a bag because it is unordered.

False

Draw the contents of the queue after the following statements execute. Clearly label the front and back of the queue. QueueInterface<String> bankLine = new LinkedQueue<>(); bankLine .enqueue("John"); bankLine .enqueue("Matthew"); String next = bankLine .dequeue(); bankLine .enqueue("Drew"); bankLine .enqueue("Heather"); bankLine .enqueue("David"); next = bankLine .dequeue();

Front<-Drew, Heather, David-> (David being the back of the queue)

In a circular array-based implementation of a queue, what is the performance when the enqueue operation does not resize the array?

O(1)

In a circular array-based implementation of a queue, what is the performance when the enqueue operation if you amortize the cost of resizing the array over all additions to the queue?

O(1)

In a circular array-based implementation of a queue, what is the performance when the enqueueoperation does not resize the array?

O(1)

In a doubly linked chain implementation of a queue, what is the performance when the dequeue operation ?

O(1)

In a linked chain implementation of a queue, the performance of the getFront operation is

O(1)

In a linked-chain implementation of a Stack ADT, the performance of looking at the first entry on the stack without removing it is a. O(1) b. O(2) c. O(n) d. O(n2 )

O(1)

In a linked-chain implementation of a Stack ADT, the performance of pushing an entry onto the stack is a. O(1) b. O(2) c. O(n) d. O(n2 )

O(1)

In a linked-chain implementation of a Stack ADT, the performance ofpopping an entry from the stack is a. O(1) b. O(2) c. O(n) d. O(n2 )

O(1)

In a two-part circular linked chain implementation of a queue, what is the performance when the dequeue operation ?

O(1)

In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is not full? a. O(1) b. O(n) c. O(n log n) d. O(n2 )

O(1)

In a circular array-based implementation of a queue, what is the performance when the enqueueoperation if you amortize the cost of resizing the array over all additions to the queue?

O(log n)

In a circular array-based implementation of a queue, what is the performance when the enqueue operation must resize the array?

O(n)

In a circular array-based implementation of a queue, what is the performance when the enqueueoperation must resize the array?

O(n)

The original name for Java was

Oak

The type of control normally used when you want the user to only be allowed to select one option from several possible options is the

RadioButton.

When would amortizing the cost of doubling an array size over all the additions to the stack work not out to be negligible?

Resizing multiple times

Why doesn't the contains method return the index of a located entry?

Returning the index implies an explicit position in the array. A client should be shielded from this level of detail.

Draw the contents of the deque after the following statements execute. Clearly label the front and back of the deque. DequeInterface<String> waitingLine = new LinkedDeque<>(); waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getFront();

Rudy

What is the design rationale for providing a toArray method instead of a displayBag method?

The user/client is free to display any or all of the items in anyway desired.

(T/F) It is a good programming practice to only access a class's data fields only through accessor and mutator methods.

True

(T/F) When comparing objects in a bag, we assume that the class to which the objects belong defines its own version of equals.

True

A class should not return a reference to an array that is a private data field.

True

A node does not reference the data in another node.

True

A priority queue cannot have null entries

True

A vector is manipulated with methods.

True

A vector will grow in size as needed.

True

A vector's entries are indexed beginning with 0.

True

All entries of a bag must have the same data type or a subtype of that data type.

True

Any method that adds an entry to a collection is typically considered to be a core method.

True

Any methods that a core method might call are part of the core group.

True

In a circular array-based implementation of a queue, frontIndex is equal to one more than backIndex when the queue is empty.

True

In a linked chain implementation of a queue, when both the firstNode and lastNode entries are null, the chain is empty.

True

In a linked-chain implementation of the Stack ADT, the first node references the stack's top entry.

True

In an array-based implementation of a queue, inserting and deleting entries is accomplished using modulo arithmetic.

True

In an array-based implementation of a queue, keeping the front entry of the queue at queue[0] is inefficient.

True

In an array-based implementation of the Stack ADT, the cost of doubling the array size is amortized over all additions to the stack.

True

It is a good programming practice to only access a class's data fields only through accessor and mutator methods.

True

Queues are used in operating systems.

True

Security checks are essential to maintain the integrity of the LinkedBag objects.

True

The Queue interface extends the Deque interface.

True

The item most recently added to a queue is at the back of the queue.

True

The null value can be used to signal failure to remove or retrieve an entry from a priority queue when it is empty.

True

The outer LinkedBag class can access the data fields of the inner Node class directly without using set and get methods.

True

When a circular linked chain has one node, the node references itself.

True

You need two external references for a circular doubly linked chain, one for the firstNode and one for the lastNode.

True

In an array based implementation of a Stack ADT, explain why it is a bad idea to use the first location of the array to reference the top of a stack.

We would have to make all entries first = top

In a vector implementation of a Stack ADT, you add an entry to the top of a stack using which vector method? a. add b. push c. put d. none of the above

add

The Java Class Library interface Queue method to put an entry on the back of a queue that throws an exception if the method fails is a. add b. offer c. put d. poll

add

When adding a node to a two-part circular linked chain implementation of a queue we insert the new node into the chain

after the node that freeNode reference

A fixed size array - prevents extension when the bag becomes full - all of these - has a limited capacity - can waste memory

all of these

When a linked chain contain nodes that reference both the next node and the previous node, it is called a(n)

doubly linked list

In an array-based implementation of a queue, a possible solution to dealing with the full condition is to

leave one array location unused

In an array-based implementation of a queue, a possible solution to dealing with the full condition is to

maintain a count of queue items

In a class hierarchy

the more general classes are toward the top of the tree and the more specialized classes are toward the bottom.

In the linked chain implementation of a queue, the chain's tail last node contains

the queue's back entry

Java provides a mechanism known as a ________ which makes it possible to write a method that takes a variable number of arguments.

variable-length argument list

Assume that inputFile references a Scanner object that was used to open a file. Which of the following while loops is the correct way to read data from the file until the end of the file is reached?

while (inputFile.hasNext())

When you make a copy of the aggregate object and of the objects that it references,

you are performing a deep copy.

When adding a node to a two-part circular linked chain implementation of a queue we insert the new node into the chain

after the node that freeNode references

A two-part circular linked chain implementation of a queue

all of the above

When defining the bag class, you should implement the isArrayFull and remove operations first. a. true b. false

b

When testing a method, you only need to check for arguments that lie within the legal range of their corresponding parameter. a. true b. false

b

In a linked chain implementation of a queue, when the queue is empty

both & b

How can we tell if a two-part circular linked chain queue is empty?

both the queueNode and freeNode reference the same Node

How can we tell if a two-part circular linked chain queue is empty?

both the queueNode and freeNode reference the same node

In a ______ the last node references the first node.

circular linked chain

Which of the following methods is a good candidate for a core method: a. add() b. toArray() c. isArrayFull() d. all of the above

d

for which of the following would a bag implementation be suitable? a. a shopping cart b. a vending machine c. a postage stamp collection d. all of the above

d

which behavior(s) leave the contents of a bag unaltered? a. toArray() b. getFrequencyOf() c. isEmpty() d. all of the above

d

which behaviors do not change the contents of a bag? a. add() b. clear() c. remove() d. none of the above

d

which of the following are good reasons to write Java statements that use your bag ADT before the implementation is done? a. it helps confirm the design b. it helps check the suitability of the specification c. it helps check your understanding of the specification d. all of the above

d

A(n) ________ is an object that is generated in memory as the result of an error or an unexpected event.

exception

Byte code instructions are

read and interpreted by the JVM

Given the following chain, what does the resultant chain look like after removing the node with the entry "L" in it? "J", "X", "F", "K", "L", null - None of these. - "X", "F", "K", "J", null - "J", "X", "F", "K", null - You cannot remove the last node.

"J", "X", "F", "K", null

In an array-based chain implementation of a Stack ADT, what value at the top of the stack indicated that it is empty? a. -1 b. 0 c. 1 d. null

-1

In the Java Class Library, the default constructor Vector creates an empty vector with an initial capacity of a. 10 b. 0 c. 100 d. user-defined

10

What will be displayed after the following code is executed? String str = "abc456"; for (int i = 0; i < str.length(); i++) { char chr = str.charAt(i); if (!Character.isLetter(chr)) System.out.print(Character.toUpperCase(chr)); }

456

What is the value of z after the following code is executed? int x = 5, y = 28; float z; z = (float) (y / x);

5.0

An inner class is a. a nested class b. not static c. both a and b d. none of the above

A

Where does a queue add new items? a. at the back b. at the front c. in the middle d. randomly

A

Which of the following is not a way a user can interact with a computer?

All of these are ways a user can interact with a computer.

A common alias for the queue method dequeue is a. get b. remove c. delete d. all of the above

B

A common alias for the queue method enqueue is a. put b. add c. insert d. all of the above

B

An object of type Node that contains a data type of Node is a a. circular reference b. improper reference c. forward reference d. logic error

B

In a circular array-based implementation of a queue, what is the performance when the enqueue operation must resize the array? a. O(n^2) b. O(n) c. O(log n) d. O(1)

B

What item is at the front of the list after these statements are executed? DequeInterface<String> waitingLine = new LinkedDeque<>(); waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getFront(); a. Jack b. Rudy c. Larry d. Sam

B

What is an advantage of using a chain for a Bag ADT? a. It avoids moving data when adding or removing bag entries. b. It has a fixed size which is easier to manage. c. It can be resized to provide as much space as needed. d. All of the above

C

All of the exceptions that you will handle are instances of classes that extend the ________ class.

Exception

(T/F) A nested class is defined partially within another class definition.

False

(T/F) Any methods that a core method might call are part of the core group.

False

A final class is more secure than one that is not final.

False

A method can change the state of an object passed to it as an argument.

False

A nested class is defined partially within another class definition.

False

A vector is analogous to a resizable linked-chain.

False

An abstract data type is not necessarily a collection.

False

By declaring a data type to be a BagInterface, we can replace the bag class with another class that implements the BagInterface.

False

Entries of a bag may belong to different classes because items are unordered.

False

What will be the result after the following code is executed? final int ARRAY_SIZE = 5; float[] x= float[ARRAY_SIZE]; for (i=1; i<ARRAY_SIZE; i++) { x[i]=10.0; }

The code contains a syntax error and will not compile.

What will be displayed after the following code is executed? StringBuilder strb = new StringBuilder(12); strb.append("The cow "); strb.append("jumped over the "); strb.append("moon."); System.out.println(strb);

The cow jumped over the moon.

What will be the result of the following statements? FileInputStream fstream = new FileInputStream("Input.dat"); DataInputStream inFile = new DataInputStream(fstream);

The inFile variable will reference an object that is able to read binary data from the Input.dat file

What would be the result after the following code is executed? int [ ] numbers = {40, 3, 5, 7, 12, 10}; int value = numbers[0]; for (int i = 1; i < numbers.length; i++) { if (numbers[i] < value) value = numbers [i]; }

The value variable will contain the lowest value in the numbers array.

Assuming three ImageView objects named puppy, kitten, and bunny have been created, what does the following statement do? HBox hbox = new HBox(5, puppy, kitten, bunny);

There will be five pixels of space between the controls horizontally in the container.

A collection is not necessarily an abstract data type.

True

Using a resizable array to implement the stack ADT avoids the condition where a stack is too full to accept another entry.

True

When a circular linked chain is used to represent a queue, it is not necessary to maintain a firstNode data field.

True

When comparing objects in a bag, we assume that the class to which the objects belong defines its own version of equals.

True

When using a linked implementation, a bag can never become full.

True

Write stubs early in the implementation of an ADT so you can begin testing early.

True

You can push, pop and get items at either end of the ADT deque.

True

It is a good practice to identify a group of a core methods to implement and test before continuing with the rest of the class definition. What type of methods should you begin with?

You should begin with methods that add to the collection or methods that have complex implementations.

A final class is more secure that one that is not final. a. true b. false

a

Which method removes one unspecified entry from a bag if possible? a. remove() b. clear() c. delete() d. empty()

a

which bag behaviors would to be modified when implementing a set? a. add() b. clear() c. contains() d. toArray()

a

which behavior is not represented in a bag? a. reorder the bag b. report the number of items in the bag c. report if the bag is empty d. add an item to the bag

a

which behavior is not specified in the bag ADT? a. sort() b. contains() c. clear() d. remove()

a

which behavior(s) change the contents of a bag? a. add() b. getFrquencyOf() c. contains() d. toArray()

a

which behavior(s) change the contents of bag? a. remove() b. getCurrentSize() c. isEmpty() d. getFrequencyOf()

a

which behaviors leave the contents of a bag unaltered? a. contains() b. remove() c. clear() d. add()

a

which method can be used to retrieve all of the elements of a bag? a. toArray() b. printBag() c. displayBag() d. getAllItems()

a

A Java program must have at least one of the following:

a class definition

The ADT priority queue organizes objects a. according to priority of the objects b. alphabetically c. from front to back d. from back to front

according to priority of the objects

How does a queue organize it items? a. according to the order in which they were added b. by priority c. alphabetically d. randomly

according to the order in which they were added

You cannot determine the exact number of times a particular item appears in a bag because it is unordered. a. true b. false

b

You should implement all methods of an ADT implementation before testing to make testing easier. a. true b. false

b

In an array-based implementation of a queue, if waitingListis the name of the array, and the index to the last entry in the queue is called backIndex, write a single assignment statement to update backIndexto add an entry to the queue.

backIndex = (backIndex + 1) % waitingList.legnth;

A stub should a. report that is was invoked by displaying a message b. include a return statement that returns a dummy value c. by written early for testing programs d. all of the above

d

you wish keep track of the distribution of words in a document, for example, how many times the word "apple" appears. You store each word in the document in a bag. Why is a bag a potentially good solution? a. the order of the words is unimportant b. the words in the document are not unique c. getFrequencyOf() is a useful behavior for determining the word distribution d. all of the above

d

The method for removing an item from the front of a queue is called a. dequeue b. enqueue c. getFront d. none of the above

dequeue

Given the following statement, which statement will write the string "Calvin" to the file DiskFile.txt? PrintWriter diskOut = new PrintWriter("DiskFile.txt");

diskOut.println("Calvin");

The ________ loop is ideal in situations where you always want the loop to iterate at least once.

do-while

The Java Class Library interface Queue method that retrieves the entry at the front of a queue but throws a NoSuchElementException if the queue was empty is a. element b. peek c. poke d. look

element

The method for adding a new item to the back of a queue is called a. enqueue e. dequeue f. getFront g. none of the above

enqueue

A(n) ________ is a section of code that gracefully responds to exceptions when they are thrown.

exception handler

Describe what happens when the following code is executed. QueueInterface<String> bankLine = new LinkedQueue<>(); bankLine .enqueue("John"); bankLine .enqueue("Matthew"); String next = bankLine .dequeue(); bankLine .enqueue("Heather"); next = bankLine .dequeue(); next = bankLine .dequeue(); bankLine .enqueue("Nancy"); next = bankLine .dequeue(); next = bankLine .dequeue();

exception thrown attempted to dequeue from empty list

In a circular array-based implementation of a queue, frontIndexis equal to one less than backIndexwhen the queue is full.

false

In a circular array-based implementation of a queue, frontIndexis equal to one more than backIndexwhen the queue is empty.

false

In a linked chain implementation of a queue, the enqueue operation could potentially be dependent on the other entries and will require a search.

false

In a linked chain implementation of a queue, the enqueue operation requires a traversal to the end of the chain to insert a new entry onto the queue.

false

In an array-based implementation of a queue, inserting and deleting entries is accomplished using modulo arithmetic.

false

In an array-based implementation of a queue, keeping the front entry of the queue at queue[0] is inefficient.

false

When a circular linked chain is used to represent a queue, it is not necessary to maintain a firstNodedata field.

false

When adding a node to a two-part circular linked chain implementation of a queue

first check if a node is already available in the chain.

What type of behavior defines a queue? a. first-in first-out b. first-in last-out c. last-in first-out d. none of the above

first-in, first-out

A ________ is a boolean variable that signals when some condition exists in the program.

flag

Draw the contents of the queue after the following statements execute. Clearly label the front and back of the queue. QueueInterface<String> bankLine = new LinkedQueue<>(); bankLine .enqueue("John"); bankLine .enqueue("Matthew"); String next = bankLine .dequeue(); next = bankLine .dequeue(); bankLine .enqueue("Drew"); bankLine .enqueue("Heather"); next = bankLine .dequeue(); bankLine .enqueue("David"); next = bankLine .dequeue();

front<-David->back

In an array-based implementation of a queue, if waitingList is the name of the array, and the index to the last entry in the queue is called frontIndex, write a single assignment statement to update frontIndex to remove an entry to the queue.

frontIndex = (frontIndex - 1) % waitingList.length;

The method for retrieving the queue's front entry without altering the queue is called a. getFront b. enqueue c. dequeue d. none of the above

getFront

To replace a ListView control's existing items with a new list of items, use the ________ method

getItems().setAll()

To retrieve text that a user has typed into a TextField control, you call the ________ method.

getText

A constructor

has the same name as the class

You should not define a class that is dependent on the values of other class fields

in order to avoid having stale data.

When the need to expand the size of a bag occurs, the common practice is to - increase the size of the array by one to accommodate the new entry - double (or 1.5) the size of the array - use the Fibonacci sequence to determine the incremental size of the new array - prompt the user for how much larger the bag will need to be

increase the size of the array by one to accommodate the new entry

placing the Node class inside the LinkedBag class makes it an...

inner class

Methods that operate on an object's fields are called

instance methods.

Another term for an object of a class is a(n)

instance.

In a vector implementation of a Stack ADT, you check for an empty stack using which vector method? a. isEmpty b. empty c. stackEmpty d. none of the above

isEmpty

Explain why writing a test program before implementing a class is a good idea.

it helps you understand the specifications before committing to your design and implementation.

In a circular linked chain, when a node is removed from the queue

it is deallocated

When the this variable is used to call a constructor

it must be the first statement in the constructor making the call.

After the following statements execute, what item is at the back of the queue? QueueInterface zooDelivery = new LinkedQueue<>(); zooDelivery .enqueue("lion"); zooDelivery .enqueue("tiger"); zooDelivery .enqueue("cheetah"); String next = zooDelivery .dequeue(); next = zooDelivery .dequeue(); zooDelivery .enqueue("jaguar"); a. "jaguar" b. "cheetah" c. "tiger" d. "lion"

jaguar

In a vector implementation of a Stack ADT, you retrieve the top entry without removing it using which vector method? a. lastElement b. peek c. look d. none of the above

lastElement

Which method accesses the last entry of a vector? a. lastElement b. last c. endOfVector d. you can't access the last entry directly

lastElement

A linked chain whose last node is null is sometimes called a(n)

linear linked chain

To return an array of long values from a method, which return type should be used for the method?

long[]

What will be displayed after the following code is executed? boolean matches; String str1 = "The cow jumped over the moon."; String str2 = "moon"; matches = str1.endsWith(str1); System.out.println(matches);

moon

Which of the following statements will allow a user to type input into a field of a ComboBox named myComboBox?

myComboBox.setEditable(true);

Which of the following expressions will generate a random number in the range of 1 through 10?

myNumber = randomNumbers.nextInt(10) + 1;

In order to leave 15 pixels of space in an HBox container, use which of the following statements?

myhbox.setPadding(new Insets(15));

The Java Class Library interface Queue method to put an entry on the back of a queue that returns false if the method fails is a .offer b. add c. put d. poll

offer

In a circular array-based implementation of a queue implementation where one unused location is used to differentiate between the front and back of the queue, the frontIndexis _____ than the backIndex.

one more

In a circular array-based implementation of a queue, the initial size of the array should be

one more than the queue's initial capacity

When a field is declared static there will be

only one copy of the field in memory.

A subclass can directly access

only public and protected members of the superclass.

Enumerated types have the ________ method which returns the position of an enum constant in the declaration list.

ordinal

A common alias for the queue method getFront is a. peek b. get c. put d. all of the above

peek

The Java Class Library interface Queue method that retrieves the entry at the front of a queue but returns null if the queue was empty is a. peek b. empty c. poke d. look

peek

A(n) ________ is used to write computer programs

programming language

Software refers to

programs.

Of the following, which would be considered the no-arg constructor for the Rectangle class?

public Rectangle()

Which of the following statements correctly specifies two interfaces?

public class ClassA implements Interface1, Interface2

Which of the following statements will set a ListView control, puppyListView, to be 300 pixels high and 200 pixels wide?

puppyListView.setSize(200, 300);

The ____ ADT organizes its entries according to the order in which they were added. a. queue b. stack c. list d. priority queue

queue

A method that calls itself is a ________ method.

recursive

________ operators are used to determine whether a specific relationship exists between two values.

relational

In a vector implementation of a Stack ADT, you remove an entry from the top of a stack using which vector method? a. remove b. pop c. retrieve d. none of the above

remove

The Java Class Library interface Queue method that retrieves and removes the entry at the front of a queue and throws a NoSuchElementException if the queue was empty is a. remove b. poll c. retrieve d. get

remove

The ________ method removes an item from an ArrayList at a specific index.

remove

Which behavior(s) change the contents of a bag? - getFrequencyOf() - remove() - isEmpty() - getCurrentSize()

remove()

Which method removes one unspecified entry from a bag if possible? - clear() - remove() - delete() - empty()

remove()

Which behavior is not represented in a bag? - reorder the bag - report if the bag is empty - report the number of items in the bag - add an item to the bag

reorder the bag

The most efficient approach to dealing with a gap left in an array after removing from a bag is to - replace the entry being removed with the first entry in the array and replace the first entry with null - replace the entry being removed with the last entry in the array and replace the last entry with null - shift subsequent entries and replace the duplicate reference to the last entry with null - replace the entry being removed with null

replace the entry being removed with the first entry in the array and replace the first entry with null

In a ResizableArrayBag class, why does the add method always return true? - returning void is not a fail-safe programming practice - all of these - because the array will always double in size - to conform to the bag interface

returning void is not a fail-safe programming practice

If a bag is empty before the remove() method executes, it - returns null - throw an exception - returns an error message - all of these

returns null

A ________ is a value that signals when the end of a list of values has been reached.

sentinel

All the transition classes inherit a method named ________ which allows you to specify how the animation begins and ends.

setInterpolator

In a linked chain implementation of a queue, an external reference to the last node in the chain is called a(n)

tail reference

To efficiently remove a node at the end of a linked chain implementation of a queue requires as

tail reference

Given the following method header, what will be returned from the method? public Rectangle getRectangle()

the address of an object of the Rectangle class

When a vector needs to increase its size a. the capacity is doubled b. the capacity is increased by 10 empty entries c. the capacity is increased by 1 as needed d. the capacity increase is user-defined

the capacity is doubled

The node that is easiest to access in a linked-chain is a. the head node b. the tail node c. access time is the same for all nodes d. it cannot be determined

the head node

In an array-based chain implementation of a Stack ADT, the entry peek returns may be found at a. the last occupied location in the array b. the last location in the array c. the first location in the array d. none of the above

the last occupied location in the array

In the linked chain implementation of a queue, the chain's first node contains

the queue's front entry

When a counter enumerates simulated time units, it is called a(n) a. time-driven simulation b. clock simulation c. event-driven simulation d. all of the above

time-driven simulation

A series of words or other items of data, separated by spaces or other characters, are known as

tokens.

Each node in an ordinary linked chain references only the next node.

true

In a circular array-based implementation of a queue, the available locations are not contiguous.

true

The boolean data type may contain which of the following range of values?

true or false

A(n) ________ contains one or more statements that are executed and can potentially throw an exception.

try block

In a circular array-based implementation of a queue implementation where one unused location is used to differentiate between the front and back of the queue, the frontIndex is _____ than the backIndex.

two more

The String class's ________ method accepts a value of any primitive data type as its argument and returns a string representation of the value.

valueOf

The simplest way to use the System.out.printf method is

with only a format string and no additional arguments.

If object1 and object2 are objects of the same class, to make object2 a copy of object1

write a method for the class that will make a field by field copy of object1 data members into object2 data members.

What output will be displayed as a result of executing the following code? int x = 5, y = 20; x += 32; y /= 4; System.out.println("x = " + x + ", y = " + y);

x = 37, y = 5

In order to modify the front entry of a queue a. you need a set method defined b. you need to dequeue the front entry, modify the contents, and then use the requeue method to place it back on the front of the queue c. you cannot modify it under any circumstances d. none of the above

you need a set method defined

Which symbol indicates that a member is private a UML diagram?

-

How many times will the following do-while loop be executed? int x = 11; do { x += 20; } while (x <= 100);

5

In a circular array-based implementation of a queue, what is the performance when the dequeue operation ? a. O(1) b. O(log n) c. O(n) d. O(n2)

A

The method for retrieving the queue's front entry without altering the queue is called a. getFront b. enqueue c. dequeue d. none of the above

A

The method remove that has no parameter in the bag implementation a. removes the last entry in the array b. removes the first entry in the array c. removes a random entry in the array d. none of the above

A

Which of the following is not part of the programming process?

All of these are parts of the programming process.

Which of the following is a subclass of Node?

Both of these

A two-part circular linked chain implementation of a queue a. is initialized with no available nodes b. keeps nodes that are deallocated for future use c. allocates new nodes on demand when there are no available nodes d. all of the above

C

If we use a chain of linked nodes with only a head reference to implement a queue which statement is true? a. You must traverse the entire chain to access the last node. b. Accessing the last node is very inefficient. c. Both a & b d. None of the above

C

In a linked chain implementation of a queue, when the queue is empty a. the firstNode is null b. the lastNode is null c. both a & b d. none of the above

C

What item is at the front of the list after these statements are executed? DequeInterface<String> waitingLine = new LinkedDeque<>(); waitingLine.addToBack("Adam"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); waitingLine.addtoFront("Jack"); String name = waitingLine.getFront(); name = getFront(); a. Adam b. Rudy c. Jack d. Sam

C

When adding a node to a two-part circular linked chain implementation of a queue a. first check if a node is already available in the chain b. check to see if the linked chain needs resized c. allocate a new node and assign the reference to freeNode d. all of the above

C

Which code correctly adds the first entry to an empty bag? a. Node newNode = new Node(newEntry); firstNode = newNode; b. Node newNode = new Node(); newNode = newEntry; firstNode = newNode; c. both a & b d. none of the above

C

An array whose index of the first location follows the index its last one is call

Circular

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

ClassA

A two-part circular linked chain implementation of a queue

Conceptually has two lists. Uses a freeNode reference for the first available node that follows the queue. Has node that form the queue followed by node that are available for use in the queue

A deque ADT behaves a. like a queue b. like a stack c. both a & b d. none of the above

D

A stub is created for what purpose? a. to avoid syntax errors b. to avoid duplicate code c. to protect the integrity of the ADT d. to practice fail-safe programming

D

A stub should a. report that is was invoked by displaying a message b. include a return statement that returns a dummy value c. be written early for testing programs d. all of the above

D

For which of the following would a bag implementation be suitable? a. a shopping cart b. a vending machine c. a postage stamp collection d. all of the above

D

The dequeue method a. throws an exception if the queue is empty b. returns the item at the front of the queue c. removes the item at the front of the queue d. all of the above

D

Which behavior(s) leave the contents of a bag unaltered? a. toArray() b. getFrequencyOf() c. isEmpty() d. all of the above

D

Which behaviors change the contents of a bag? a. clear() b. remove() c. add() d. all of the above

D

Which behaviors do not change the contents of a bag? a. add() b. clear() c. remove() d. none of the above

D

To create an animation in which a node fades in or out over a period of time, use the ________ class.

FadeTransition

You should never suppress compiler warnings.

False

What is the difference between the numberOfEntries data field in the ArrayBag implementation and the DEFAULT_CAPACITY field?

If the client does not specify the size of the bag, the numberOfEntires field will be set to the DEFAULT_CAPACITY value in the constructor. Otherwise, the numberOfEntires field will be set to the size specified by the client.

What does the following statement do? Image puppy = new Image("file:C:\\images\terrier.jpg");

It loads an image file named terrier.jpg which is found in the images folder on the user's C-drive.

In a linked chain implementation of a queue, the performance of the enqueue operation is

O(1)

In an array-based chain implementation of a Stack ADT, what is the performance of the ensureCapacity method when the array is full? a. O(n) b. O(1) c. O(n log n) d. O(n2 )

O(n)

In order for an object to be serialized, the class must implement the ________ interface.

Serializable

Which of the following statements converts an int variable named number to a string and stores the value in the String object variable named str?

String str = Integer.toString(number);

To create a TextField control, you use the ________ class which is in the ________ package.

TextField, javafx.scene.control

The catch clause

The catch clause does all of these.

(T/F) By declaring a data type to be a BagInterface, we can replace the bag class with another class that implements the BagInterface.

True

(T/F) Entries of a bag can belong to classes related by inheritance.

True

A set is a special kind of bag.

True

An abstract data type is not necessarily a collection. a. True b. False

a

Entries of a bag can belong to classes related by inheritance. a. true b. false

a

The method remove that has no parameter in the bag implementation a. removes the last entry in the array b. removes the first entry in the array c. removes a random entry in the array d. none of the above

a

When comparing objects in a bag, we assume that the class to which the objects belong defines its own version of equals. a. true b. false

a

When implementing the bag ADT, which scenario could result in a security problem? a. a client attempts to create a bag whose capacity exceeds a given limit b. a SecurityException is thrown in the constructor c. an IllegalStateException is thrown in the constructor d. the delete method is implemented before the add method

a

Which instruction suppresses an unchecked-cast warning from the compiler? a. @SuppressWarnings("unchecked") b. @SuppressUnchecked() c. @SuppressUncheckedWarnings() d. @Warning("suppress unchecked")

a

________ is the term for the relationship created by object aggregation.

"Has a"

How does a queue organize it items? a. according to the order in which they were added b. by priority c. alphabetically d. randomly

A

A call to the remove method with no arguments on an empty list a. returns null b. returns false c. throws a ListEmptyException d. throws an IllegalOperationException

B

When removing a node from a two-part circular linked chain implementation of a queue

The entry at the front of the queue is returned. The node is moved to the part of the chain that is available for the enqeue method. The queueNode is advanced.

(T/F) A class should not return a reference to an array that is a private data field.

True

(T/F) A method can change the state of an object passed to it as an argument.

True

(T/F) A node does not reference the data in another node.

True

(T/F) After the method clear, the programmer does not need to worry about deallocating the nodes that were in the chain.

True

A class should not return a reference to an array that is a private data field. a. true b. false

a

In a circular array-based implementation of a queue, if waitingList is the name of the array, and the index to the last entry in the queue is called frontIndex, write a single assignment statement to update frontIndex to remove an entry to the queue.

forntIndex = (frontIndex - 2) %waitingList.length;

Which method returns a count of the current number of items in a bag? - getSize() - getCurrentSize() - size() - currentSize()

getCurrentSize()

When working with the PrintWriter class, which of the following import statements should you have near the top of your program?

import java.io.*;

UML diagrams do not contain

object names.

Which of the following creates a custom style class that will allow a Button control to appear with a blue background and yellow text?

.button-color { -fx- background-color: blue; -fx- text-fill: yellow; }

If you have two RadioButtons ( dogRadio and catRadio), how should you code them to create a mutually exclusive relationship?

//ToggleGroup radioGroup = new ToggleGroup(); //dogRadio.setToggleGroup(radioGroup); //catRadio.setToggleGroup(radioGroup):

What will be the value of discountRate after the following statements are executed? double discountRate; char custType = 'B'; switch (custType) { case 'A': discountRate = .08; break; case 'B': discountRate = .06; case 'C': discountRate = .04; default: discountRate = 0.0; }

0.0

What will be displayed after the following statements are executed? int x = 65; int y = 55; if (x>=y) { int ans = x+y; } System.out.println(ans);

120

What will be the value of position after the following code is executed? int position; String str = "The cow jumped over the moon."; position = str.indexOf("ov");

15

A language-independent specification for a group of values and operations on those values is called a/an: a. abstract data type b. data structure c. collection d. primitive

A

A linked chain whose last node is null is sometimes called a(n) a. linear linked chain b. circular linked chain c. null terminated linked chain d. all of the above

A

A reference to the first node in a linked list is called the _____ reference. a. head b. initial c. first d. default

A

A return value of -1 from the getIndex method indicates a. the entry was not present in the bag b. the entry was found at the end of the array c. the bag was empty d. the bag was full

A

A test driver for the bad add method should check for which one of the following a. an over capacity condition b. printing elements of the bag c. adding elements of the correct type d. an empty bag condition

A

Accessing all of the nodes in a chain beginning with the first one is called a(n) a. traversal b. visitation c. chaining d. link crawl

A

Adding a new entry to an empty bag a. is a simple task b. must be treated as a special case c. throws an IllegalOperationException d. causes a NullExceptionError

A

After the following statements execute, what item is at the back of the queue? QueueInterface<String> zooDelivery = new LinkedQueue<>(); zooDelivery .enqueue("lion"); zooDelivery .enqueue("tiger"); zooDelivery .enqueue("cheetah"); String next = zooDelivery .dequeue(); next = zooDelivery .dequeue(); zooDelivery .enqueue("jaguar"); a. "jaguar" b. "cheetah" c. "tiger" d. "lion"

A

After the following statements execute, what item is at the front of the queue? QueueInterface<String> zooDelivery = new LinkedQueue<>(); zooDelivery .enqueue("lion"); zooDelivery .enqueue("tiger"); zooDelivery .enqueue("cheetah"); String next = zooDelivery .dequeue(); next = zooDelivery .dequeue(); zooDelivery .enqueue("jaguar"); a. "cheetah" b. "jaguar" c. "tiger" d. "lion"

A

An array whose index of the first location follows the index its last one is call a. circular b. following c. round d. oval

A

An implementation of an ADT with a programming language is called a/an: a. data structure b. abstract data type c. collection d. primitive

A

An incomplete definition of a method is called a _____. a. stub b. core method c. fail-safe method d. security problem

A

An object that groups other objects and provides services to its clients is called a/an: a. collection b. abstract data type c. data structure d. primitive

A

An object you link in Java to form a linked list is called a(n) a. node b. address c. reference d. link

A

Decrementing the private class variable numberOfEntries in a bag a. causes the last entry to be ignored b. causes an IllegalState exception to be thrown c. destroys the integrity of the bag container d. is a security problem

A

Given the following chain, what does the resultant chain look like after adding the node with an entry "U" in it? "J", "X", "F", "K", "L", null a. "U", "J", "X", "F", "K", "L", null b. "J", "X","F", "K", "L", "U", null c. you cannot determine where the entry will go in a bag chain implementation d. none of the above

A

Given the following chain, what does the resultant chain look like after removing the node with the entry "J" in it? "J", "X", "F", "K", "L", null a. "X", "F", "K", "L", null b. null, "X", "F", "K", "L", null c. you cannot remove the first node in an non-empty chain d. none of the above

A

Given the following chain, what does the resultant chain look like after removing the node with the entry "K" in it? "J", "X", "F", "K", "L", null a. "X", "F", "J", "L", null b. "J", "X", "F", "L", null c. "J", "X", "F", "K", "L", null d. none of the above

A

Given the following chain, what does the resultant chain look like after removing the node with the entry "L" in it? "J", "X", "F", "K", "L", null a. "X", "F", "K", "J", null b. "J", "X", "F", "K", null c. you cannot remove the last node d. none of the above

A

How can we tell if a two-part circular linked chain queue is empty? a. both the queueNode and freeNode reference the same node b. the freeNode is one node behind the queueNode c. the freeNode is one node in front of the queueNode d. the empty field is set to true

A

If a bag is empty before the remove method executes, it a. returns null b. throw an exception c. returns an error message d. all of the above

A

If an array bag contains the entries "lions", "elephants", "otters", "bears", "tigers", "lemurs" and a call to the remove method with the entry "bears" is made, what does the array look like after remove? a. ""lions", "elephants", "otters", "lemurs", "tigers", null b. "lions", "elephants", "otters", null, "tigers", "lemurs" c. "lions", "elephants", "otters", "tigers", "lemurs", null d. "lions", "elephants", "otters", "tigers", "lemurs"

A

If the following nodes are added in order, what does the resultant chain look like? "L", "A", "R", "X", "J" a. "J", "X", "R", "A", "L", null b. "L", "A", "R", "X", "J", null c. null, "J", "X", "R", "A", "L" d. null, "L", "A", "R", "X", "J"

A

In a ResizableArrayBag class, why does the add method always return true? a. to conform to the bag interface b. because the array will always double in size c. returning void is not a fail-safe programming practice d. all of the above

A

In a ______ the last node references the first node. a. circular linked chain b. array based queue c. array based circular queue d. linked chain

A

In a circular array-based implementation of a queue implementation where one unused location is used to differentiate between the front and back of the queue, the frontIndex is _____ than the backIndex. a. two more b. one more c. one less d. two less

A

In a circular array-based implementation of a queue, the initial size of the array should be a. one more than the queue's initial capacity b. one less than the queue's initial capacity c. two more than the queue's initial capacity d. two less than the queue's initial capacity

A

In a circular array-based implementation of a queue, what is the performance when the enqueue operation does not resize the array? a. O(1) b. O(log n) c. O(n) d. O(n2)

A

In a circular array-based implementation of a queue, what is the performance when the enqueue operation if you amortize the cost of resizing the array over all additions to the queue? a. O(1) b. O(log n) c. O(n) d. O(n2)

A

In a circular linked chain, when a node is removed from the queue a. it is deallocated b. it is moved to a separate list c. it is ignored d. none of the above

A

In a doubly linked chain implementation of a queue, what is the performance when the dequeue operation? a. O(1) b. O(log n) c. O(n) d. O(n^2)

A

In a linked chain implementation of a queue, an external reference to the last node in the chain is called a(n) a. tail reference b. last node c. linked reference d. final node

A

In a linked chain implementation of a queue, the performance of the enqueue operation is a. O(1) b. O(log n) c. O(n) d. O(n^2)

A

In a linked chain implementation of a queue, the performance of the getFront operation is a. O(1) b. O(log n) c. O(n) d. O(n2)

A

In an array-based implementation of a queue, a possible solution to dealing with the full condition is to a. leave one array location unused b. check for frontIndex equal to backIndex c. wait for an arrayFullExcetion to be thrown d. all of the above

A

In an array-based implementation of a queue, a possible solution to dealing with the full condition is to a. maintain a count of queue items b. check for frontIndex equal to backIndex c. wait for an arrayFullExcetion to be thrown d. all of the above

A

In the linked chain implementation of a queue, the chain's first node contains a. the queue's front entry b. the queue's back entry c. both a & b d. none of the above

A

In the linked chain implementation of a queue, the chain's tail last node contains a. the queue's back entry b. the queue's front entry c. both a & b d. none of the above

A

In the remove method, setting the last entry of the array to null a. flags the removed object for garbage collection b. prevents malicious code from accessing it c. is a good security practice d. all of the above

A

Placing the Node class inside the LinkedBag class makes it a(n) a. inner class b. outer class c. dependent class d. inherited class

A

Sets that adhere to the standard interface in the Java Class library a. do not contain a pair of objects x and y such that x.equals(y) is true b. are completely compatible with the bag interface c. allow duplicate entries d. order the objects contained in the set

A

The most efficient approach to dealing with a gap left in an array after removing an entry from a bag is to a. replace the entry being removed with the last entry in the array and replace the last entry with null b. replace the entry being removed with the first entry in the array and replace the first entry with null c. shift subsequent entries and replace the duplicate reference to the last entry with null d. replace the entry being removed with null

A

The next field in a node is also referred to as the a. link portion b. node c. initial address d. data portion

A

The remove method replaces the removed entry with null because a. the entry could potentially be scheduled for garbage collection b. the client expects a null return value c. it is a fail-safe programming practice d. otherwise it could be considered a duplicate value

A

To accommodate entries of any class, the bag methods use ______ . a. a generic type b. an inherited type c. a sub class d. all of the above

A

To efficiently remove a node at the end of a linked chain implementation of a queue requires a a. tail reference b. traversal c. extra reference in the node pointing to the previous node d. none of the above

A

What happens if an OutOfMemoryError occurs while adding a new node to the chain? a. the chain will remain intact b. the chain will lose its integrity c. a faulty node will be added to the beginning of the chain d. access to the chain will be lost

A

What happens when you remove a node from a chain with only one node? a. the firstNodereference will become null b. the firstNodereference will become invalid c. an IllegalOperationException is thrown d. none of the above

A

What type of behavior defines a queue? a. first-in first-out b. first-in last-out c. last-in first-out d. none of the above

A

When a counter enumerates simulated time units, it is called a(n) a. time-driven simulation b. clock simulation c. event-driven simulation d. all of the above

A

When a linked chain contain nodes that reference both the next node and the previous node, it is called a(n) a. doubly linked chain b. ordinary chain c. multi-linked chain d. two-way linked chain

A

When adding an item to a bag, which of the following statements are true? a. You cannot specify the position of the item in the bag. b. You can specify the item will be placed as the first in the bag. c. You can specify the item will be placed as the last in the bag. d. None of the above.

A

When resizing an array to increase the bag size, if the copy exceeds the maximum memory specified for the computer, the checkCapacity method should a. throw an IllegalStateException b. throw a MaxSizeExceededException c. throw a MaxMemoryExceededException d. return false

A

When the need to expand the size of a bag occurs, the common practice is to a. double the size of the array b. increase the size of the array by one to accommodate the new entry c. use the Fibonacci sequence to determine the incremental size of the new array d. prompt the user for how much larger the bag will need to be

A

When would you choose a two-part circular chain over a circular chain? a. when you frequently add an entry after removing one b. when you rarely add entries after removing one c. when you are space constrained d. when you don't want the garbage collector running

A

Which of the following is not true with regard to bags? a. objects are in a specific order b. can contain duplicate items c. is an abstract data type d. is a kind of collection in Java

A

Which of the following methods is a good candidate for a core method: a. add() b. clear() c. contains() d. remove()

A

Which one of the following Java statements allocates an array in the bag constructor causing a compiler warning for an unchecked operation? Assume capacity is an integer. a. bag = (T[ ]) new Object[capacity]; b. bag = new T[capacity]; c. bag = new Object[capacity]; d. bag = new (T[ ]) Object[capacity];

A

Which one of the following is considered a safe and secure programming practice? a. making no assumptions about the actions of clients and users b. using @SupressWarning ("unchecked") c. adding the comments and headers of the public methods to the class by copying them from the interface d. all of the above

A

Which one of the following is considered a safe and secure programming practice? a. validating input data and arguments to a method b. identifying a group of core methods to implement first c. using generic data types d. none of the above

A

Why would the add method return false? a. when the addition of a new item was not successful b. when there was a duplicate of the entry already in the bag c. when there was not a duplicate of the entry already in the bag d. when addition of a new item was successful

A

Explain the rationale for returning a Boolean value from the add bag operation.

A client should know what happened. A Boolean value indicates true for success or false for a failed operation.

Why is it a safer practice for the toArray method to return a copy of the array instead of a reference to the array?

A client would then have direct access to the private data and could either inadvertently or maliciously alter the data without using the public methods of the class.

What happens when the following code is executed? ComboBox<string> myComboBox = new ComboBox<>; myComboBox.getItems().addAll(5, 10, 15, 20);

A compiler error will occur.

Which of the following is a CSS named color?

All of these

When an array is passed to a method

All of these are true.

An object of type Node that contains a data type of Node is a - circular reference - forward reference - logic error - improper reference

An object of type Node that contains a data type of Node is a forward reference. A forward reference is the part of a Node which refers to another Node.

The clear method a. sets the firstNode to null b. traverses the chain and deallocating each node until it reaches the end c. returns true if it succeeds d. all of the above

B

The remove method with no arguments returns a. the first entry in the chain b. true if the method succeeds, false otherwise c. a random entry in the chain d. none of the above

B

When adding a node to a two-part circular linked chain implementation of a queue we insert the new node into the chain a. after the node that freeNode references b. before the node that freeNode references c. it has nothing to do with the location of freeNode d. none of the above

B

In order to modify the front entry of a queue a. you need a set method defined b. you need to dequeue the front entry, modify the contents, and then use the requeue method to place it back on the front of the queue c. you cannot modify it under any circumstances d. none of the above

C

In order to resize an array to accommodate a larger bag, you must a. define an alias that references the original array b. create a new array that is larger than the original array and make the alias reference it c. copy the contents of the original array reference by the alias to the new array and discard the original array d. all of the above

C

The remove method for a given entry returns a. the first entry in the chain that matches or null of it is not in the chain b. the last entry in the chain that matches or null of it is not in the chain c. true if the method succeeds, false otherwise d. none of the above

C

A fixed size array a. has a limited capacity b. can waste memory c. prevents expansion when the bag becomes full d. all of the above

D

A two-part circular linked chain implementation of a queue a. conceptually has two lists b. uses a freeNode reference for the first available node that follows the queue c. has nodes that form the queue followed by nodes that are available for use in the queue d. all of the above

D

In a two-part circular linked chain implementation of a queue a. queueNode references the front node of the queue b. freeNode references the node that follows the queue c. the queue is empty if queueNode equals freeNode d. all of the above

D

In the LinkedBag implementation, the numberOfEntriesfield a. records the number of entries in the current bag b. records the number of nodes in the chain c. is set to zero in a new chain d. all of the above

D

What are the consequences of returning a reference to the bag array in the toArray method? a. the return variable is an alias for the private instance array variable b. the client will have direct access to the private instance array variable c. the client could change the contents of the private instance array variable without using the public access methods d. all of the above

D

What happened when a bag becomes full in a linked list implementation? a. An OutofMemoryError will occur. b. The add method will return false. c. A MemoryExceededException will be thrown. d. This condition is not possible with a linked list implementation.

D

What happens when you use the new operator in the LinkedBag constructor? a. a new node is created b. the JRE allocates memory for a node object c. a new object is instantiated d. all of the above

D

What item is at the front of the list after these statements are executed? DequeInterface<String> waitingLine = new LinkedDeque<>(); waitingLine.addToFront("Jack"); waitingLine.addToBack("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToFront("Sam"); String name = waitingLine.getFront(); name = getBack(); waitingLine.addtoBack("Adam"); a. Jack b. Rudy c. Adam d. Sam

D

When calling the remove method with an argument if there are multiple entries a. exactly which occurrence removed is unspecified b. only one occurrence is removed c. the first occurrence is removed d. all of the above

D

When implementing the bag ADT, which scenario could result in a security problem? a. a client attempts to create a bag whose capacity exceeds a given limit b. a SecurityException is thrown in the constructor c. an IllegalStateException is thrown in the constructor d. the delete method is implemented before the add method

D

When implementing the bag ADT, which scenario could result in a security problem? a. a constructor throw an exception or error before completing its initialization b. the programmer validates input data to a method c. generics are used to restrict data types of theentries in the collection d. a group of core methods is not defined

D

When removing a node from a chain, what case should we consider? a. the node is at the beginning of the chain b. the node is at the end of the chain c. both a and b d. none of the above

D

When removing a node from a chain, what case should we consider? a. the node is not at the beginning of the chain b. the node is at the end of the chain c. both a and b d. none of the above

D

When using abstraction as a design principle you should focus on: a. what you want to do with the data b. how the data is stored c. how the data is manipulated d. all of the above

D

A two-part circular linked chain implementation of a queue

Is initialized with no available nodes. Keeps node that are deallocated for future use. Allocates new nodes on demand when there are no available nodes.

What does the following code do? Scanner keyboard = new Scanner(System.in); String filename; System.out.print("Enter the filename: "); filename = keyboard.readString(); PrintWriter outFile = new PrintWriter(filename);

It allows the user to enter the name of the file that data will be written to.

What is the advantage of using a chain for a Bag ADT? - It can be resized to provide as much space as needed - It avoids moving data when adding or removing bag entries - It has a fixed size which is easier to manage - All of these

It avoids moving data when adding or removing bag entries

Explain why null is a potential return value for the remove operation.

It is a value that cannot be in the bag and therefore signals a problem if, for example, a client tries to remove any entry from an empty bag.

Draw the contents of the deque after the following statements execute. Clearly label the front and back of the deque. DequeInterface<String> waitingLine = new LinkedDeque<>(); waitingLine.addToBack("Adam"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); waitingLine.addtoFront("Jack"); String name = waitingLine.getFront(); name = getFront();

Jack

What item is at the front of the list after these statements are executed? DequeInterface waitingLine = new LinkedDeque<>(); waitingLine.addToBack("Adam"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); waitingLine.addtoFront("Jack"); String name = waitingLine.getFront(); name = getFront(); a. Adam b. Rudy c. Jack d. Sam

Jack

If a subclass constructor does not explicitly call a superclass constructor,

Java will automatically call the superclass's default constructor just before the code in the subclass's constructor executes.

In a vector based implementation of a Stack ADT, explain why it is not necessary to keep track of the index to the top entry of the stack.

Linked - New node at top Array- element added to end, double array vector - expands as needed

Why is it a bad programming practice for the Stack ADT clear method to simply set the topIndex to -1 in an array-based implementation?

Memory would still be allocated

What would be displayed as a result of executing the following code? final int x = 22, y = 4; y += x; System.out.println("x = " + x + ", y = " + y)

Nothing. There is an error in the code

In a circular array-based implementation of a queue, what is the performance when the dequeue operation ?

O(1)

What item is at the front of the list after these statements are executed? DequeInterface waitingLine = new LinkedDeque<>(); waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getFront(); a. Jack b. Rudy c. Larry d. Sam

Rudy

What item is at the front of the list after these statements are executed? DequeInterface waitingLine = new LinkedDeque<>(); waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getBack(); a. Rudy b. Jack c. Larry d. Sam

Rudy

What item is at the front of the list after these statements are executed? DequeInterface waitingLine = new LinkedDeque<>(); waitingLine.addToFront("Jack"); waitingLine.addToFront("Rudy"); waitingLine.addToBack("Larry"); waitingLine.addToBack("Sam"); String name = waitingLine.getBack(); a. Rudy b. Jack c. Larry d. Sam

Sam

In a vector based implementation of a Stack ADT, explain why it is not necessary to keep track of the index to the top entry of the stack.

Similar to an array we can look at vector size

To print "Hello, world" on the monitor, which of the following Java statements should be used?

System.out.println("Hello, world");

If the data.dat file does not exist, what will happen when the following statement is executed? RandomAccessFile randomFile = new RandomAccessFile("data.dat", "rw");

The file, data.dat, will be created.

In a linked chain implementation of a queue, when the queue is empty

The firstNode is null. The lastNode is null.

When adding an item to a bag, which of the following statements are true? - You cannot specify the position of the item in the bag. - None of these - You can specify the item to be placed as the second in the bag. - You can specify the item to be placed as the one before the last in the bag.

You cannot specify the position of the item in the bag OR You can specify the item will be placed as the last in the bag

Why is it better implement the add operation in a collection before implementing the remove operation?

You cannot test remove functionality until you have written and tested add functionality.

A method can change the state of an object passed to it as an argument. a. true b. false

a

A stub is created for what purpose? a. to avoid syntax errors b. to avoid duplicate code c. to protect the integrity of the ADT d. to practice fail-safe programming

a

A test driver for the bag add method should check for which one of the following a. an over capacity condition b. printing elements of the bag c. adding elements of the correct type d. an empty bag condition

a

All entries of a bag must have the same data type or a subtype of that data type.

a

An implementation of an ADT with a programming language is called a/an: a. data structure b. abstract data type c. collection d. primitive

a

An incomplete definition of a method is called a _______. a. stub b. core method c. fail-safe method d. security problem

a

An object that groups other objects and provides services to its clients is called a/an: a. collection b. abstract data type c. data structure d. primitive

a

Any methods that a core method might call are part of the core group. a. true b. false

a

By declaring a data to be a BagInterface, we can replace the bag class with another class that implements the BagInterface. a. true b. false

a

Sets that adhere to the standard interface in the Java Class library a. do not contain a pair of objects x and y such that x.equals(y) is true b. are completely compatible with the bag interface c. allow duplicate entries d. order the objects contained in the set

a

When implementing the bag ADT, which scenario could result in a security problem? a. a constructor throws an exception or error before completing its initialization b. the programmer validates input data to a method c. generics are used to restrict data types of the entries in the collection d. a group of core methods is not defined

a

Which method removes all entries of a bag? a. clear() b. remove() c. delete() d. empty()

a

Which of the following methods is a good candidate for a core method: a. add() b. clear() c. contains() d. remove()

a

Which one of the following Java statements allocates an array in the bag constructor causing a compiler warning for an unchecked operation? Assume capacity in an integer. a. bag = (T[]) new Object[capacity]; b. bag = new T[capacity]; c. bag = new Object[capacity]; d. bag = new (T[]) Object[capacity];

a

Which one of the following is considered a safe and secure programming practice? a. making no assumptions about the actions of clients and users b. using @SuppressWarning("unchecked") c. adding the comments and headers of the public methods to the class by copying them from the interface d. all of the above

a

Which one of the following is considered a safe and secure programming practice? a. validating input data and arguments to a method b. identifying a group of core methods to implement first c. using generic data types d. none of the above

a

Why would the add method return false? a. when the addition of a new item was not successful b. when there was a duplicate of the entry already in the bag c. when there was not a duplicate of the entry already in the bag d. when addition of a new item was successful

a

Write stubs early in the implementation of an ADT so you can begin testing early. a. true b. false

a

when adding an item to a bag, which of the following statements are true? a. you cannot specify the position of the item in the bag b. you can specify the item will be placed as the first in the bag c. you can specify the item will placed as the last in the bag d. none of the above

a

when using abstraction as a design principle you should focus on: a. what you want to do with the data b. how the data is stored c. how the data is manipulated d. all of the above

a

which bag behavior is not useful or relevant for a set? a. getFrequencyOf() b. add() c. remove() d. contains()

a

which method returns a count of the current number of items in a bag? a. getCurrentSize() b. getSize() c. size() d. currentSize()

a

which of the following are properties of a set? a. duplicates are permitted b. elements are stored in order c. elements may not be removed d. none of the above

a

which of the following is a special kind of bag that does not allow duplicate entries? a. set b. collection c. extended bag d. super bag

a

which of the following is not true with regard to bags? a. objects are in a specific order b. can contain duplicate items c. is an abstract data type d. is a kind of collection in Java

a

which of the following would be suitable items to store in a bag? a. marbles b. coins c. student roster d. all of the above

a and b

A ragged array is

a two-dimensional array where the rows have different numbers of columns.

In a two-part circular linked chain implementation of a queue

all of the above

In an array-based implementation of a queue, a possible solution to dealing with the full condition is to

all of the above

When adding a node to a two-part circular linked chain implementation of a queue

all of the above

When removing a node from a two-part circular linked chain implementation of a queue

all of the above

What are the consequences of returning a reference to the bag array in the toArray method? - the return variable is an alias for the private instance array variable - the client could change the contents of the private instance array variable without using the public access methods - all of these - the client will have direct access to the private instance array variable

all of these

A common alias for the queue method dequeue is a. get b. remove c. delete d. all of the above

all the above

A common alias for the queue method enqueue is a. put b. add c. insert d. all of the above

all the above

In a linked-chain implementation of a Stack ADT, when a node is popped from the stack a. the original first node will no longer be referenced b. the original first node will be deallocated c. the new first node will reference what was the second node in the chain d. all of the above

all the above

The Stack ADT may be implemented witha. a linked-chain b. an array c. a vector d. all of the above

all the above

The dequeue method a. throws an exception if the queue is empty b. returns the item at the front of the queue c. removes the item at the front of the queue d. all of the above

all the above

Which of the following real-world events could be simulated using a queue? a. bank line b. a shared network printer c. restaurant reservation list d. all of the above

all the above!

Where does a queue add new items? a. at the back b. at the front c. in the middle d. randomly

at the back

Where is a new node added to a LinkedBag? - in a random place - at the beginning - at the end - in the middle

at the end

Where will you find the item added earliest to a queue? a. at the front b. at the back c. in the middle d. randomly

at the front

Code written with respect to an interface makes it difficult to replace one implementation of a bag with another. a. true b. false

b

When defining the bag class write methods that have simple implementation first to get them out of the way. a. true b. false

b

In a circular array-based implementation of a queue, if waitingList is the name of the array, and the index to the last entry in the queue is called backIndex, write a single assignment statement to update backIndex to add an entry to the queue.

backIndex = (backIndex + 2) % waitingList.length;

In a circular array-based implementation of a queue, explain why checking for frontIndex equal to backIndex + 1 does not work.

because it is indistinguishable from an empty array condition.

Explain why the set ADT does not need a getFrequencyOf operation.

because sets do not contain duplicate items, only a 0 for absence or 1 for presence of an item would be returned. Using a contains method is a better design.

A deque ADT behaves a. like a queue b. like a stack c. both a & b d. none of the above

both a & b

If we use a chain of linked nodes with only a head reference to implement a queue which statement is true?

both a & b

Which statement is true about the VectorStack class methods? a. they invoke the methods of the Vector class b. they require slightly more execution time than the ArrayStack methods c. both a & b d. none of the above

both a & b

Decrementing the private class variable numberOfEntries in an ArrayBag - causes an IllegalState exception to be thrown - is a security problem - destroys the integrity of the bag container - causes the last entry to be ignored

causes the last entry to be ignored

After the following statements execute, what item is at the front of the queue? QueueInterface zooDelivery = new LinkedQueue<> (); zooDelivery .enqueue("lion"); zooDelivery .enqueue("tiger"); zooDelivery .enqueue("cheetah"); String next = zooDelivery .dequeue(); next = zooDelivery .dequeue(); zooDelivery .enqueue("jaguar");

cheetah

An array whose index of the first location follows the index its last one is call

circular

One or more objects may be created from a(n)

class

In a vector implementation of a Stack ADT, you clear all of the contents of a stack using which vector method? a. clear b. delete c. deleteAll d. none of the above

clear

Which method removes all entries of a bag?

clear()

A loop that executes as long as a particular condition exists is called a(n) ________ loop.

conditional

An array of String objects

consists of an array of references to String objects.

What are the consequences of returning a reference to the bag array in the toArray method? a. the return variable is an alias for the private instance array variable b. the client will have direct access to the private instance array variable c. the client could change the contents of the private instance array variable without using the public access methods d. all of the above

d

The _____ ADT that has operations to add, remove, or retrieve entries at both the front and back of a queue is called a a. deque b. reversible queue c. reversible stack d. all of the above

deque

When a linked chain contain nodes that reference both the next node and the previous node, it is called a(n)

doubly linked chain

Which of the following import statements is required in order to create a BorderPane layout container?

import javafx.scene.layout.BorderPane;

Assuming that inputFile references a Scanner object that was used to open a file, which of the following statements will read an int from the file?

int number = inputFile.nextInt();

Which of the following is not true with regard to bags? - objects are in a specific order - is a primitive type - is an abstract data type - can contain duplicate items

objects are in a specific order

he Java Class Library interface Queue method that retrieves and removes the entry at the front of a queue and returns null if the queue was empty is a. poll b. remove c. retrieve d. get

poll

In a two-part circular linked chain implementation of a queue

queueNode references the front node of the queue. freeNode references the node that follows the queue. the queue is empty if queueNode equals freeNode.

In the LinkedBag implementation, the numberOfEntries field - is set to zero in a new chain - records the number of nodes in the chain - all of these - records the number of entries in the current bag

records the number of entries in the current bag

A call to the remove method with no arguments in LinkedBag (Hint) In all answers you can assume that bag is not empty. - removes the last node - removes the random node - asks the user which node to remove - removes the first node

removes the last node

If str1 and str2 are both String objects, which of the following expressions will correctly determine whether or not they are equal?

str1.equals(str2)


Kaugnay na mga set ng pag-aaral

Chapter 8: Marriage and Cohabitation

View Set

Language arts// Bases of English

View Set

Chapter 39: Oxygenation and Perfusion

View Set

AP Human Geography Chapter 6 - Religion

View Set

Week 3: Proofreading Practice-Sentence Errors

View Set

Emissions Control Systems and Components

View Set