Skip to main content

Computer Science I Exam Solutions - 820 Verified Questions

Page 1


Computer Science I Exam Solutions

Course Introduction

Computer Science I is an introductory course that covers the fundamental concepts of computer science, including problem-solving, algorithm development, and basic programming principles. Students will learn the syntax and semantics of a high-level programming language, design and implement simple programs, and develop critical thinking skills necessary for debugging and optimizing code. Through hands-on assignments and projects, the course provides a solid foundation for further study in computer science and related fields, emphasizing logical reasoning, structured programming techniques, and effective use of computational tools.

Recommended Textbook

Java Software Solutions Foundations of Program Design 7th Edition by John Lewis

Available Study Resources on Quizplus

13 Chapters

820 Verified Questions

820 Flashcards

Source URL: https://quizplus.com/study-set/1550

Page 2

Chapter 1: Introduction

Available Study Resources on Quizplus for this Chatper

65 Verified Questions

65 Flashcards

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

Sample Questions

Q1) There are a number of reserved words in Java that have no current meaning (denoted with an * in figure 1.18). Why?

Answer: Java language designers anticipate introducing these statements in future versions, but have not yet implemented them because they are lower priority, or it has not been decided how they will be implemented or precisely what they will mean.

Q2) Volatility is a property of

A) RAM

B) ROM

C) disk

D) software

E) computer networks

Answer: A

Q3) Which memory capacity is the largest?

A) 1,500,000,000,000 bytes

B) 100 gigabytes

C) 3,500,000 kilobytes

D) 10 terabyte

E) 12,000,000 megabytes

Answer: E

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

Page 3

Chapter 2: Data and Expressions

Available Study Resources on Quizplus for this Chatper

77 Verified Questions

77 Flashcards

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

Sample Questions

Q1) The String "A nice box" is drawn

A) above the box

B) to the left of the box

C) to the right of the box

D) below the box

E) inside the box

Answer: D

Q2) Which library package would you import to use the class Random?

A) java.beans

B) java.io

C) java.lang

D) java.text

E) java.util

Answer: E

Q3) In Java, 'a' and 'A' are considered to be different values.

A)True

B)False

Answer: True

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

Chapter 3: Using Classes and Objects

Available Study Resources on Quizplus for this Chatper

58 Verified Questions

58 Flashcards

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

Sample Questions

Q1) The Random class' setSeed( ) method allows you to restart the pseudo-random number sequence.

A)True

B)False

Answer: True

Q2) When comparing any primitive type of variable, == should always be used to test to see if two values are equal.

A)True

B)False

Answer: False

Q3) The String class' compareTo method

A) compares two string in a case-independent manner

B) yields True or false

C) yields 0 if the two strings are identical

D) returns 1 if the first string comes lexically before the second string

E) none of the above

Answer: C

Q4) Write a statement using a method to guarantee that the initial will be a capital letter. Answer: firstInitial = firstInitial.toUpperCase( );

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

Chapter 4: Writing Classes

Available Study Resources on Quizplus for this Chatper

56 Verified Questions

56 Flashcards

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

Sample Questions

Q1) When reasoning about a car, we use such information as its make and model, year, color, cost (or worth), number of miles, gas mileage, insurance cost, and so forth. Consider a program that will attempt to determine how practical a car might be on a road trip. Which of these types of information might you use in your program as instance data?

Provide a justification for your selection.

Q2) A constructor may contain a return statement so long as no value (or expression) is returned.

A)True

B)False

Q3) Add a constructor to class Box for a cube, which has only 1 parameter, side.

Q4) All Java classes must contain a main method which is the first method executed when the Java class is called upon. A)True

B)False

Q5) An Employee will have a name, social security number, position, and hourly wages. Define the instance data for this class.

Q6) Write the constructor, which is passed the player's name and position.

Q7) Write the constructor for this class.

Page 6

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

Chapter 5: Conditionals and Loops

Available Study Resources on Quizplus for this Chatper

37 Verified Questions

37 Flashcards

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

Sample Questions

Q1) The expression (s.concat(t).length( ) < y) is True.

A)True

B)False

Q2) A truth table shows, for the various True or false values of boolean variables, what the result of a boolean condition is. Fill in the following truth table. Assume that a, b and c are boolean variables.

a b c a && (!b | | c)

false false false

false false True

false True false

false True True

True false false

True false True

True True false

True True True

Q3) Regarding the Software Failure: The operators were warned that, although the Therac-25 had many safety precautions, it might be possible to accidentally overdose a patient.

A)True

B)False

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

Chapter 6: More Conditionals and Loops

Available Study Resources on Quizplus for this Chatper

36 Verified Questions

36 Flashcards

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

Sample Questions

Q1) The size of each rectangle (bar)

A) increases in height while staying the same width

B) increases in width while staying the same height

C) increases in both width and height

D) stays the same size

E) decreases in height while staying the same width

Q2) Describe a situation where you should use a do loop and a situation where you should use a while loop.

Q3) A continue statement

A) may be used within a while or a do-while loop, but not a for loop

B) is identical to a break statement within Java loops

C) may be used within any Java loop statement

D) may be used within a for loop, but not within a while or a do-while loop

E) none of the above

Q4) Write some code that inputs a set of int values and computes its average. Ask the user first how many int values will be input. Make sure that your code cannot produce a division by zero error. Assume that cs1.Keyboard has been imported.

Q5) Rewrite the following if-else statement using a conditional operator. if (x > y) z = x; else z = y;

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

Chapter 7: Object-Oriented Design

Available Study Resources on Quizplus for this Chatper

76 Verified Questions

76 Flashcards

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

Sample Questions

Q1) Static methods cannot

A) reference instance data

B) reference non-static instance data

C) reference other objects

D) invoke other static methods

E) invoke non-static methods

Q2) Explain the difference between implementing an interface and a derived class.

Q3) Abstract methods are used when defining

A) interface classes

B) derived classes

C) classes that have no constructor

D) arrays

E) classes that have no methods

Q4) Which of the following would not be considered an algorithm?

A) a recipe

B) a computer program

C) pseudocode

D) a shopping list

E) travel directions

Q5) Provide a reason why a method would be declared static.

Page 9

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

Chapter 8: Arrays

Available Study Resources on Quizplus for this Chatper

70 Verified Questions

70 Flashcards

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

Sample Questions

Q1) The Key Events include

A) keyPressed, keyReleased

B) keyPressed, keyReleased, keyTyped

C) keyPressed, keyReleased, keyTyped, keyDown, keyUp

D) keyDown, keyUp, keyTyped

E) none of the above

Q2) A Polygon object in Java is

A) a shape defined as a collection of x, y points

B) a shape defined as a collection of lines

C) a shape defined as a collection of polylines

D) an array of shapes

E) 2 lines connected by 1 common point

Q3) Which of the following loops would adequately add 1 to each element stored in values?

A) for (j=1; j&lt;values.length; j++) values[j]++;

B) for (j=0; j&lt;values.length; j++) values[j]++;

C) for (j=0; j&lt;=values.length; j++) values[j]++;

D) for (j=0; j&lt;values.length-1; j++) values[j]++;

E) for (j=1; j&lt;values.length-1; j++) values[j]++;

Q4) Write code fragment to swap the two Strings stored by variables a and b.

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

Chapter 9: Inheritance

Available Study Resources on Quizplus for this Chatper

71 Verified Questions

71 Flashcards

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

Sample Questions

Q1) Which of the following lists of instance data are accessible in class A2?

A) x, y, z, a, b

B) x, y, z, a

C) x, z, a, b

D) z, a, b

E) a, b

Q2) Assume the class Student implements the Speaker interface from the textbook. Recall that this interface includes two abstract methods, speak( ) and announce(String str). A Student contains one instance data, String classRank. Write the Student class so that it implements Speaker as follows. The speak method will output "I am a newbie here" if the Student is a "Freshman", "I hate school" if the Student is either a "Sophomore" or a "Junior", or "I can not wait to graduate" if the student is a "Senior". The announce method will output "I am a Student, here is what I have to say" followed by the String parameter on a separate line. Finally, the classRank is initialized in the constructor. Only implement the constructor and the methods to implement the Speaker interface.

Q3) The protected visibility modifier provides the best possible encapsulation that permits inheritance.

A)True

B)False

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

Page 11

Chapter 10: Polymorphism

Available Study Resources on Quizplus for this Chatper

70 Verified Questions

70 Flashcards

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

Sample Questions

Q1) Java allows one to create polymorphic references using inheritance and using interfaces.

A)True

B)False

Q2) Which of the following lists of numbers would accurately show the array after the second pass of the Selection Sort algorithm?

A) 9, 4, 12, 2, 6, 8, 18

B) 2, 4, 9, 6, 12, 8, 18

C) 2, 4, 12, 9, 6, 8, 18

D) 2, 4, 6, 8, 9, 12, 18

E) 2, 4, 12, 6, 8, 9, 18

Q3) What are the main programming mechanisms that constitute object-oriented programming?

A) encapsulation, inheritance, polymorphism

B) encapsulation, abstraction, inheritance

C) inheritance, polymorphism, recursion

D) polymorphism, recursion, abstraction

E) none of the above

Q4) Is it possible to use both overloading and overriding in the same method?

Q5) Why would you not need to implement a ChangeListener for the JSlider?

Page 12

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

Chapter 11: Exceptions

Available Study Resources on Quizplus for this Chatper

68 Verified Questions

68 Flashcards

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

Sample Questions

Q1) The difference between a checked and an unchecked exception is

A) checked exceptions need not be listed in a throws clause

B) unchecked exceptions must be listed in a throws clause

C) neither kind of exception follows the rules of exception propagation

D) an unchecked exception requires no throws clause

E) a checked exception always must be caught by a try block; an unchecked exception does not

Q2) If an ArithmeticException arises in the try statement in m3

A) it is caught in main

B) it is caught in m1

C) it is caught in m2

D) it is caught in m3

E) it is not caught leading to the program terminating

Q3) Write code to display the contents of the String array stuff to a JTextArea where each element of the array is placed on individual lines. Assume that no String is more than 25 characters long.

Q4) Write a set of code that will allow a user to select a file through a JFileChooser, read each item of the file, outputting each item to the screen, and close the file at the end.

Q5) Explain how you would use a Timer to create animation in a JLabel.

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

Chapter 12: Recursion

Available Study Resources on Quizplus for this Chatper

68 Verified Questions

68 Flashcards

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

Sample Questions

Q1) Recursion is a popular programming tool but beginning programmers tend to shy away from it. Why do you suppose this is True?

Q2) If there are 6 disks to move from one Tower to another, how many disk movements would it take to solve the problem using the recursive solution?

A) 6

B) 13

C) 31

D) 63

E) 127

Q3) Aside from writing recursive methods, another way that recursion is often used is to define

A) words in English

B) mathematical functions

C) rules and laws

D) child classes of a parent class in object-oriented programming

E) recursion is used in all of the above

Q4) Provide a definition for the terms as they relate to programming: recursion, indirect recursion and infinite recursion.

Q5) Explain what a "base case" is in a recursive method.

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

Chapter 13: Collections

Available Study Resources on Quizplus for this Chatper

68 Verified Questions

68 Flashcards

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

Sample Questions

Q1) One operation that we might want to implement on a Stack and a Queue is full, which determines if the data structure has room for another item to be added. This operation would be useful

A) only if the Queue or Stack is implemented using an array

B) only if the Queue or Stack is implemented using a linked list

C) only for a Queue

D) only for a Stack

E) none of the above, a full operation is not useful at all

Q2) It is possible to restrict the type of object which is stored within a Java collection by using a generic type when the collection is declared.

A)True

B)False

Q3) Assume that DoubleNode temp references the node with the value 3. Provide code to delete this DoubleNode without disconnecting the rest of the list.

Q4) Assume that head references a linked list that stores the values 3, 6 and 2. Show the instructions needed to delete the Node with 3 from the list so that head would reference the list of 6 and 2.

Q5) Draw this structure.

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

Turn static files into dynamic content formats.

Create a flipbook
Computer Science I Exam Solutions - 820 Verified Questions by Quizplus - Issuu