Skip to main content

Introduction to Programming Final Test Solutions - 981 Verified Questions

Page 1


Introduction to Programming Final

Test Solutions

Course Introduction

Introduction to Programming is designed to provide students with a foundational understanding of computer programming concepts and practices. The course covers the basics of writing, testing, and debugging simple programs using a high-level programming language. Key topics include variables, data types, control structures, functions, and basic data structures such as arrays and lists. Emphasis is placed on developing problem-solving skills and logical thinking through hands-on exercises and projects, preparing students for more advanced studies in computer science and related fields.

Recommended Textbook

Starting Out with Java From Control Structures through Data Structures 2nd Edition by Tony

Available Study Resources on Quizplus

22 Chapters

981 Verified Questions

981 Flashcards

Source URL: https://quizplus.com/study-set/3640 Page 2

Chapter 1: Introduction to Computers and Java

Available Study Resources on Quizplus for this Chatper

42 Verified Questions

42 Flashcards

Source URL: https://quizplus.com/quiz/72352

Sample Questions

Q1) Encapsulation refers t the combining of data and code into a single object.

A)True

B)False Answer: True

Q2) Application software refers to programs that make the computer useful to the user.

A)True

B)False Answer: True

Q3) In the programming process which of the following is not involved in defining what the program is to do:

A) Process

B) Compile code

C) Input

D) Output

E) Purpose

Answer: B

To view all questions and flashcards with answers, click on the resource link above.

Page 3

Chapter 2: Java Fundamentals

Available Study Resources on Quizplus for this Chatper

53 Verified Questions

53 Flashcards

Source URL: https://quizplus.com/quiz/72353

Sample Questions

Q1) What will be displayed as a result of executing the following code? public class test { Public static void main(String[] args)

{

Int value1 = 9; System.out.println(value1);

Int value2 = 45; System.out.println(value2); System.out.println(value3);

Value = 16;

94516

C) 9 45 16

D) Nothing,this is an error

Answer: D

To view all questions and flashcards with answers, click on the resource link above. Page 4

Chapter 3: Decision Structures

Available Study Resources on Quizplus for this Chatper

52 Verified Questions

52 Flashcards

Source URL: https://quizplus.com/quiz/72354

Sample Questions

Q1) What would be the value of discountRate after the following statements are executed? double discountRate = 0.0;

Int purchase = 100; If (purchase > 1000)

DiscountRate = .05; Else if (purchase > 750)

DiscountRate = .03; Else if (purchase > 500)

DiscountRate = .01;

A) .05

B) .03

C) .01

D) 0.0

Answer: D

Q2) In a switch statement,if two different values for the CaseExpression would result in the same code being executed,you must have two copies of the code,one after each CaseExpression.

A)True

B)False

Answer: False

To view all questions and flashcards with answers, click on the resource link above.

Page 5

Chapter 4: Loops and Files

Available Study Resources on Quizplus for this Chatper

48 Verified Questions

48 Flashcards

Source URL: https://quizplus.com/quiz/72355

Sample Questions

Q1) Which of the following will open a file named MyFile.txt and allow you to read data from it?

A) File file = new File("MyFile.txt");

B) Scanner inputFile = new Scanner("MyFile.txt");

C) File file = new File("MyFile.txt");

Scanner inputFile = new Scanner(file);

D) PrintWriter inputFile = new PrintWriter("MyFile.txt");

Q2) This type of loop is ideal in situations where you always want the loop to iterate at least once.

A) while loop

B) do-while loop

C) for loop

D) if statement

Q3) This is an item that separates other items.

A) Controller

B) Partition

C) Doorway

D) Delimiter

To view all questions and flashcards with answers, click on the resource link above.

Chapter 5: Methods

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/72356

Sample Questions

Q1) The lifetime of a method's local variable is

A) the duration of the program

B) the duration of the class to which the method belongs

C) the duration of the method that called the local variable's method

D) only while the method is executing

Q2) Which of the following would be a valid method call for the following method? public static void showProduct (int num1,double num2)

{

Int product;

Product = num1 * (int)num2; System.out.println("The product is " + product);

}

A) showProduct(5.5,4.0);

B) showProduct(10.0,4);

C) showProduct(10,4.5);

D) showProduct(33.0,55.0);

Q3) A value-returning method can return a reference to a non-primitive type. A)True B)False

To view all questions and flashcards with answers, click on the resource link above.

Chapter 6: A First Look at Classes

Available Study Resources on Quizplus for this Chatper

49 Verified Questions

49 Flashcards

Source URL: https://quizplus.com/quiz/72357

Sample Questions

Q1) For the following code,which statement is not true? public class Circle { Private double radius; Public double x; Private double y; }

A) x is available to code that is written outside the Circle class.

B) radius is not available to code written outside the Circle class.

C) radius,x,and y are called members of the Circle class.

D) y is available to code that is written outside the Circle class.

Q2) A class's responsibilities include

A) the things a class is responsible for doing

B) the things a class is responsible for knowing

C) both A and B

D) neither A or B

Q3) Methods that operate on an object's fields are called

A) instance variables

B) instance methods

C) public methods

D) private methods

To view all questions and flashcards with answers, click on the resource link above. Page 8

Chapter 7: A First Look at Gui Applications

Available Study Resources on Quizplus for this Chatper

49 Verified Questions

49 Flashcards

Source URL: https://quizplus.com/quiz/72358

Sample Questions

Q1) What will be the result of executing the following statement? panel.setBorder(BorderFactory.createTitleBorder("Title"));

A) The JPanel referenced by panel will have an etched border with the title "Title" displayed on it.

B) The JPanel referenced by panel will have an empty border with the title "Title" displayed on it.

C) The JPanel referenced by panel will have a line border with the title "Title" displayed on it.

D) The JPanel referenced by panel will have a compound border with the title "Title" displayed on it.

Q2) In Java,the ability to display splash screens was introduced in Java 6. A)True

B)False

Q3) Check boxes may be grouped in a ButtonGroup like radio buttons are.

A)True

B)False

Q4) The System.exit method will end the application.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above. Page 9

Chapter 8: Arrays and the Arraylist Class

Available Study Resources on Quizplus for this Chatper

52 Verified Questions

52 Flashcards

Source URL: https://quizplus.com/quiz/72359

Sample Questions

Q1) What would be the results of the following code? final int SIZE = 25;

Int[] array1 = new int[SIZE];

// Code that will put values in array1

Int value = 0;

For (int a = 0;a < = array1.length;a++)

{ Value += array1[a];

}

A) value contains the highest value in array1

B) value contains the lowest value in array1

C) value contains the sum of all the values in array1

D) This would cause the program to crash

Q2) How many rows and how many columns are in the points array,declared here: int [][] points = new int[10][20];

A) 9 rows and 19 columns

B) 10 rows and 20 columns

C) 0 rows and 0 columns

D) The rows and columns are not specified.

To view all questions and flashcards with answers, click on the resource link above.

10

Chapter 9: A Second Look at Classes and Objects

Available Study Resources on Quizplus for this Chatper

40 Verified Questions

40 Flashcards

Source URL: https://quizplus.com/quiz/72360

Sample Questions

Q1) Enum constants have a toString method.

A)True

B)False

Q2) When the this variable is used to call a constructor,

A) it must be the first statement in the constructor making the call

B) it must be the last statement in the constructor making the call

C) it can be anywhere in the constructor making the call

D) You cannot use the this variable in a constructor call.

Q3) The key word this is the name of a reference variable that an object can use to refer to itself.

A)True

B)False

Q4) When a method's return type is a class,what is actually returned to the calling program?

A) An object of that class

B) A reference to an object of that class

C) Only the values in the object that the method accessed

D) Nothing,the return type is strictly for documentation in this situation

To view all questions and flashcards with answers, click on the resource link above.

11

Chapter 10: Text Processing and More About Wrapper Classes

Available Study Resources on Quizplus for this Chatper

49 Verified Questions

49 Flashcards

Source URL: https://quizplus.com/quiz/72361

Sample Questions

Q1) What will be the value of str after the following statements are executed? StringBuilder str = New StringBuilder("We have lived in Chicago," + "Trenton,and Atlanta."); Str)replace(17,24,"Tampa");

A) We have lived in Tampa,Trenton,and Atlanta.

B) We have lived in Chicago,Tampa,and Atlanta.

C) We have lived in Tampa Trenton,and Tampa.

D) We have lived in Tampalanta.

Q2) Look at the following code. Integer myNumber = new Integer(5); Int var = myNumber; Which of the following is true about the second statement?

A) It results in an error because you cannot assign a wrapper class object to a primitive variable.

B) The statement performs autoboxing.

C) The statement performs unboxing.

D) The statement performs unwrapping.

Q3) You cannot assign a value to a wrapper class object. A)True B)False

Page 12

To view all questions and flashcards with answers, click on the resource link above.

Chapter 11: Inheritance

Available Study Resources on Quizplus for this Chatper

49 Verified Questions

49 Flashcards

Source URL: https://quizplus.com/quiz/72362

Sample Questions

Q1) When one object is a specialized version of another object,there is this type of relationship between them.

A) "has a"

B) "is a"

C) direct

D) "contains a"

Q2) Look at the following code and determine what the call to super will do. public class ClassB extends ClassA

{ Public ClassB()

{ Super(10);

A) This cannot be determined form the code shown.

B) It will call the constructor of ClassA that receives an integer as an argument.

C) It will call the method named super and pass the value 10 to it as an argument.

D) The method super will have to be defined before we can say what will happen.

To view all questions and flashcards with answers, click on the resource link above. Page 13

Chapter 12: Exceptions and Advanced File Io

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

Source URL: https://quizplus.com/quiz/72363

Sample Questions

Q1) When you write a method that throws a checked exception,you must

A) have a throws clause in the method header.

B) override the default error method.

C) use each class only once in a method.

D) ensure that the error will occur at least once each time the program is executed.

Q2) To read data from a binary file you create objects from the following classes:

A) FileInputStream and DataInputStream

B) File and PrintWriter

C) File and Scanner

D) BinaryFileReader and BinaryDataReader

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

A) exception handler

B) exception

C) default exception handler

D) error message

Q4) The throws clause causes an exception to be thrown.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above. Page 14

Chapter 13: Advanced Gui Applications

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

Source URL: https://quizplus.com/quiz/72364

Sample Questions

Q1) A mnemonic is

A) A single key on the keyboard that you press to quickly access a component such as a button.

B) A key on the keyboard that you press in combination with the SHIFT key to quickly access a component such as a button.

C) A key on the keyboard that you press in combination with the ALT key to quickly access a component such as a button.

D) A key on the keyboard that you press in combination with the CTRL key to quickly access a component such as a button.

Q2) If a user enters a value in the text box of an editable combo box and the value is not in the list,what will the method getSelectedIndex return?

A) The index of the item that the user replaced.

B) The index of the item the user entered.

C) -1

D) 0,since the item is not in the list.

Q3) You can create a label with an image,or with both an image and text.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above.

15

Chapter 14: Applets and More

Available Study Resources on Quizplus for this Chatper

39 Verified Questions

39 Flashcards

Source URL: https://quizplus.com/quiz/72365

Sample Questions

Q1) If a frame component is 300 pixels wide and 200 pixels high,the upper,right-hand corner has (X,Y)coordinates of

A) (0,0)

B) (300,0)

C) (200,300)

D) (299,0)

Q2) Whenever you need a component of any type to be painted,call the paint method.

A)True

B)False

Q3) The play method will load and play a sound file once,then release it for garbage collection.The getAudioClip method will load the sound file and may assign the location of the sound file to a variable so it may be invoked many times.

A)True

B)False

Q4) An applet using a Swing GUI is extended from this class.

A) JFrame

B) JLabel

C) JSwing

D) JApplet

To view all questions and flashcards with answers, click on the resource link above. Page 16

Chapter 15: Recursion

Available Study Resources on Quizplus for this Chatper

34 Verified Questions

34 Flashcards

Source URL: https://quizplus.com/quiz/72366

Sample Questions

Q1) Look at the following pseudocode algorithm. algorithm Test14(int x)

If (x < 8)

Return (2 * x)

Else

Return (3 * Test14(x - 8)+ 8)

End Test14

What is the depth of Test14(7)?

A) 0

B) 1

C) 6

D) 7

Q2) The number of times that a method calls itself is known as the

A) height of recursion

B) depth of recursion

C) width of recursion

D) length of recursion

Q3) Any problem that can be solved recursively can also be solved iteratively.

A)True

B)False

To view all questions and flashcards with answers, click on the resource link above.

Page 17

Chapter 16: Sorting, Searching, and Algorithm Analysis

Available Study Resources on Quizplus for this Chatper

46 Verified Questions

46 Flashcards

Source URL: https://quizplus.com/quiz/72367

Sample Questions

Q1) The bubble sort algorithm works by

A) repeatedly comparing adjacent items and swapping them so smaller values come before larger values

B) repeatedly locating the smallest value in the unsorted portion of the array and moving it toward the lower end of the array

C) repeatedly taking the first value in the unsorted portion of the array and placing it at its proper place in the part of the array that is already sorted

D) partitioning the unsorted portion of the array into two sublists and a pivot and recursively sorting the two sublists

Q2) If an algorithm with an input size of n has a nested loop,and both loops make a complete pass over the input,then the performance of the algorithm will be

A) constant time

B) linear time

C) logarithmic time

D) quadratic time

To view all questions and flashcards with answers, click on the resource link above.

Chapter 17: Generics

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/72368

Sample Questions

Q1) The generic method

Public static < E extends Number >

Void displayArray(E[] array){

For (E element : array)System.out.println(element); } Can be passed

A) an array whose element type is Object

B) an array whose element type is E

C) an array whose element type is any superclass of Number

D) an array whose element type is Integer

Q2) Let Point< T > be a generic type.We want to write a method that takes as parameter Point objects whose type parameter is the Number class,or any subclass of Number.We can do this by declaring the type of the method parameter as A) Point< Number >

B) Point< ? super Number >

C) Point< ? extends Number >

D) Point< ? sub Number >

To view all questions and flashcards with answers, click on the resource link above.

19

Chapter 18: Collections

Available Study Resources on Quizplus for this Chatper

50 Verified Questions

50 Flashcards

Source URL: https://quizplus.com/quiz/72369

Sample Questions

Q1) If different objects can have the same hash code,then

A) some HashSet buckets may have more than one object

B) the HashSet add method will throw an IllegalStateException

C) the operation of searching a HashSet becomes more efficient

D) None of the above

Q2) Collections

A) is the interface from which all collection interfaces are derived

B) is the superclass of all abstract and concrete collection classes

C) is a class that contains static methods for working with collections

D) None of the above

Q3) The ListIterator interface

A) specializes the Iterator interface to work with lists,but adds no new methods

B) adds to Iterator the ability to move backwards in the collection

C) adds to Iterator the ability to iterate over several collections,if those collections are lists

D) None of the above

To view all questions and flashcards with answers, click on the resource link above. Page 20

Chapter 19: Array-Based Lists

Available Study Resources on Quizplus for this Chatper

20 Verified Questions

20 Flashcards

Source URL: https://quizplus.com/quiz/72370

Sample Questions

Q1) Why does the Java Collections Framework define a List as an interface rather than a class?

A) To be consistent with earlier versions of Java

B) To allow different types of concrete classes,with different performance characteristics to implement the interface

C) To allow the use of generic types

D) All of the above

Q2) What is the difference between the Iterator and Iterable interfaces? How would you use these two interfaces if you had to write a collection class?

Q3) The E get(int index)method of the List interface should throw an exception if

A) the index passed to it is negative

B) the index passed to it nonnegative

C) the index passed to it is negative or greater or equal to the size of the list

D) the index passed to is negative or greater than the size of the list

To view all questions and flashcards with answers, click on the resource link above.

Chapter 20: Linked Lists

Available Study Resources on Quizplus for this Chatper

36 Verified Questions

36 Flashcards

Source URL: https://quizplus.com/quiz/72371

Sample Questions

Q1) In a linked list,the successor of a node X

A) may not exist

B) is the node that comes after X,and it always exists

C) is the last node in the list

D) is the node whose index is one greater than the index of X

Q2) In a linked list implementation using a reference first to point to the first node of the list,a method isEmpty()can test to see if the list is empty by executing the statement(s) A) return null;

B) first = null;return first;

C) if (isEmpty(..return true;else return false;

D) return first == null;

Q3) A systematic procedure for starting at the first node in a list,and visiting all nodes in the list by going from each node to its successor is called A) a sweep

B) a traversal

C) travelling over the list

D) All of the above

To view all questions and flashcards with answers, click on the resource link above.

22

Chapter 21: Stacks and Queues

Available Study Resources on Quizplus for this Chatper

36 Verified Questions

36 Flashcards

Source URL: https://quizplus.com/quiz/72372

Sample Questions

Q1) A stack based on a linked list is based on the following code Class Node{

String element; Node next;

Node(String el,Node n){

Element = el;

Next = n; } }

Node top = null;

The code for implementing the operation void push(String x)can be written as

A) top = new Node(x,top);

B) if (top == full.

Throw new RuntimeException("Overflow".;

Else

Top = new Node(x,top.;

C) top.add(x.;

D) top = add(Node x.;

To view all questions and flashcards with answers, click on the resource link above.

Page 23

Chapter 22: Binary Trees, Avl Trees, and Priority Queues

Available Study Resources on Quizplus for this Chatper

45 Verified Questions

45 Flashcards

Source URL: https://quizplus.com/quiz/72373

Sample Questions

Q1) Let X be a node in a binary tree.Any node on the path from X to a leaf is called A) a descendant of X

B) an ancestor of X

C) a relative of X

D) a subordinate of X

Q2) Let X be a node in a binary tree.The collection of all descendants of X A) form a binary tree called the subtree rooted at X B) form the left subtre of X

C) form the right subtree of X

D) None of the above

Q3) A complete binary tree with N nodes may be stored in an array A of length N by storing the root at A[0],and then storing in successive array locations the nodes of the tree in increasing order of the level of nodes.If nodes in the same level are stored in left to right order,then the right child of the node stored at A[k] will be stored at A) A[k/2]

B) A[2k]

C) A[2k+1]

D) A[2k+2]

To view all questions and flashcards with answers, click on the resource link above.

Page 24

Turn static files into dynamic content formats.

Create a flipbook