Programming in Java Exam Solutions - 820 Verified Questions

Page 1


Programming in Java Exam Solutions

Course Introduction

Programming in Java is an introductory course that explores the foundational concepts of computer programming using the Java language. Students will learn core programming principles such as variables, data types, control structures, object-oriented programming, and exception handling. The course emphasizes problem-solving techniques and practical application through coding assignments and projects. By the end of the course, students will have the skills to design, implement, and debug Java programs, preparing them for more advanced topics in software development.

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) Volatility is a property of

A) RAM

B) ROM

C) disk

D) software

E) computer networks

Answer: A

Q2) Which of the following is not syntactically legal in Java?

A) public class Foo

B) System.out.println("Hi");

C) { }

D) s t a t i c main(String[ ] args)

E) only B is legally valid, all of the rest are illegal

Answer: D

Q3) Objects are defined by a class that describes the characteristics common to all instances of the class.

A)True

B)False

Answer: True

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) Write the paint method for an applet so that it contains 4 concentric circles (each circle is inside the previous circle), where the largest circle is bounded by a 400x400 box and the smallest is bounded by a 100x100 box. Each circle is centered on an applet that is 400x400. Make each circle a different color of your choice. Answer: public void paint(Graphics page) { page.setColor(Color.white); page.fillOval(0, 0, 400, 400); page.setColor(Color.yellow); page.fillOval(50, 50, 300, 300); page.setColor(Color.orange); page.fillOval(100, 100, 200, 200); page.setColor(Color.red); page.fillOval(150, 150, 100, 100); }

Q2) Java is able to represent 255 * 255 * 255 = 16,581,375 distinct colors. A)True B)False

Answer: False

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) You may use the String replace( ) method to remove characters from a String.

A)True

B)False

Answer: False

Q2) Say you write a program that makes use of the Random class, but you fail to include an import statement for java.util.Random (or java.util.*). What will happen when you attempt to compile and run your program.

A) The program won't run, but it will compile with a warning about the missing class.

B) The program won't compile-you'll receive a syntax error about the missing class.

C) The program will compile, but you'll receive a warning about the missing class.

D) The program will encounter a runtime error when it attempts to access any member of the Random class

E) none of the above

Answer: B

Q3) Write a statement using a Scanner method to get the first name interactively. Answer: firstName = scan.nextLine( );

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) The relationship between a class and an object is best described as A) classes are instances of objects

B) objects are instances of classes

C) objects and classes are the same thing

D) classes are programs while objects are variables

E) objects are the instance data of classes

Q2) A method defined in a class can access the class' instance data without needing to pass them as parameters or declare them as local variables.

A)True

B)False

Q3) Regarding the software failure described at the Denver International Airport, it is critical to factor in errors and inefficiencies that always occur in a complex system.

A)True

B)False

Q4) The interface of a class is based on those data instances and methods that are declared public.

A)True

B)False

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

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 (!done && x <= y) is True.

A)True

B)False

Q2) Assume that x and y are int variables with x = 5, y = 3, and a and d are char variables with a = 'a' and d = 'A', and examine the following conditions: Condition 1: (x < y && x > 0)

Condition 2: (a != d || x != 5)

Condition 3: !(True && false)

Condition 4: (x > y || a == 'A' || d != 'A')

A) All 4 Conditions are True

B) Only Condition 2 is True

C) Condition 2 and Condition 4 are True only

D) Conditions 2, 3 and 4 are all True, Condition 1 is not

E) All 4 Conditions are false

Q3) Rewrite the following set of if statements using a nested if-else structure. if (score >= 90) grade = 'A'; if (score >= 80 && score < 90) grade = 'B'; if (score >= 70 && score < 80) grade = 'C'; if (score >= 60 && score < 70) grade = 'D'; if (score < 60) grade = 'F';

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) Write a "query-controlled" loop that will continue to input int values from the user, adding each to the int value sum, and then ask if the user has another value to input, until the user says that there are no more values. Assume that cs1.Keyboard has been imported.

Q2) 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.

Q3) The following code has a syntax error immediately before the word else. What is the error and why does it arise?

Fix the code so that this statement is a legal if-else statement. if (x < 0) ; x++; else x--;

Q4) The statement if (x < 0) y = x; else y = 0; can be rewritten using a conditional operator as

A) y = (x < 0) ? x : 0;

B) x = (x < 0) ? y : 0;

C) (x < 0) ? y = x : y = 0;

D) y = (x < 0);

E) y = if (x < 0) x : 0;

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) What is wrong with the following message to create a BoxLayout for the JPanel jp?

Jp)setLayout(new BoxLayout(BoxLayout.X_AXIS));

A) X_AXIS is not a valid constant for BoxLayout, it should instead be HORIZONTAL

B) Aside from X_AXIS, the constructor also requires a Dimension to determine the size of the Box

C) Aside from X_AXIS, the constructor also needs a command regarding horizontal glue as in createHorizontalGlue( )

D) The BoxLayout constructor is lacking a reference to the container that the BoxLayout manager will govern

E) There is nothing wrong with it at all

Q2) The idea of having programmers and developers meet in order to critique a software design or implementation is known as A) an interview

B) a walkthrough

C) prototyping

D) aggregation

E) evolutionary development

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

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) In a two-dimensional array, both dimensions must have the same number of elements, as in[10][10].

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) The statement System.out.println(values[7]); will

A) output 7

B) output 18

C) output nothing

D) cause an ArrayOutOfBoundsException to be thrown

E) cause a syntax error

Q4) Explain how to alter the Selection Sort algorithm so that it sorts in descending order instead of ascending order.

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) The assignment statement d = p; is legal even though d is not a Poodle.

A)True

B)False

Q2) Using the reserved word, super, one can

A) access a parent class'constructor(s)

B) access a parent class'methods and instance data

C) access a child class'constructor(s)

D) access a child class'methods and instance data

E) none of the above

Q3) What is the advantage of extending an adapter class rather than implementing a listener interface?

Q4) What methods inherited from Car should SportsCar override?

Q5) A motorcycle inherits properties from both a bicycle and a car. Java does not permit multiple inheritance. Assume that Bicycle and Car have both been declared. Explain how you might go about implementing a Motorcycle as a derived class.

Q6) You may use the super reserved word to access a parent class'private members.

A)True

B)False

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

Page 11

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

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) Which of the following GUI components would you use to display a list of options so that the user could select between the entries in the list?

A) JComboBox

B) JList

C) JSlider

D) JScrollPane

E) JOptionPane

Q2) Binary search can be used on unsorted data it will just perform more slowly.

A)True

B)False

Q3) The GUI should react whenever the JButton is clicked, so the JFrame will need an ActionListener. Write the actionPerformed method to implement the ActionListener so that the GUI will compute the cost of the movie when the JButton is clicked. This method will have to obtain the values specified in the JComboBox and the JSlider and output the computed cost in the JLabel. Assume that a Matinee costs $5.00 per ticket, a Rush Hour show $3.50 per ticket and Normal show costs $7.50 per ticket.

Q4) Explain how to alter the Selection Sort algorithm so that it sorts in descending order instead of ascending order.

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

Page 12

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) Write a save method that will save a given student to the String filename passed as a parameter.

Q2) The following defines a new Exception called AnewException. public Exception ANewException { public ANewException(String message) { super(message); }

A)True

B)False

Q3) Assume infile is a BufferedReader for a textfile and that the textfile is empty. What is returned from the message infile.readLine( ); ?

A) 0

B) null

C) a special character known as the End-of-file marker (EOF)

D) none of the above, the message causes a NullPointerException to be thrown

E) none of the above, the message causes a EndOfFileException to be thrown

Q4) 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) 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

Q2) What is returned if factorial(3) is called?

A) 0

B) 1

C) 3

D) 6

E) 9

Q3) It always is possible to replace a recursion by an iteration and vice versa.

A)True

B)False

Q4) Describe how to solve the Towers of Hanoi problem using 4 disks (that is, write down move for move how to solve the problem).

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) An array is a List Abstract Data Type.

A)True

B)False

Q2) The Abstract Data Type (ADT) is thought of as abstract because the operations that are to be implemented are separated from the actual implementation, that is, an ADT can be implemented in more than one way and that implementation is separate from how we might use the ADT.

A)True

B)False

Q3) A linked list that contains 6 Nodes will have 6 reference pointers.

A)True

B)False

Q4) A linear data structure

A) always has more than one link per node

B) is sometimes represented as a tree or a graph

C) can have but a single link per node

D) almost always is kept in sorted order either ascending or descending

E) none of the above

Q5) What common Exception(s) might arise when using an array? What common Exception(s) might arise when using a linked list?

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
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.