U2E

pdf

School

Rowan College, Burlington County *

*We aren’t endorsed by this school

Course

111

Subject

Computer Science

Date

Dec 6, 2023

Type

pdf

Pages

10

Uploaded by MagistrateDiscoveryKangaroo81

Report
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 1/10 Unit 2 Exam Started: Oct 12 at 11:41am Quiz Instructions 1 pts Question 1 thing is an object of the Widget class type thing is a primitive value of the Widget type Widget is an object of the thing class type Widget is a primitive value of the thing type Widget and thing are both classes Consider the following declaration Widget thing = new Widget(); Which of the following best describes the situation? 1 pts Question 2 \\ \n \t \' \" Which of the following is used to indicate a new line?
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 2/10 1 pts Question 3 An error occurs, because when progress1 is stored to progress2, progress1 no longer exists so changeLevel() can no longer be used on progress1. The level of progress1 is changed to 2 by the changeLevel() method, but since it is not simultaneously changed for progress2, the level is not updated completely. Therefore the level of progress1 and progress2 are both 1. The value of the level stored in progress1 is now 2 and the the value stored in progress2 is 1. An error occurs because progress2 is not properly created. You cannot set one object equal to another object. progress1 and progress2 point to the same object, so the level of progress1 and progress2 are both now 2. Look at the following code - assume that Game is a class that creates an object that represents the progress of a player within a video game. By default, the value stored is 1. Also assume that changeLevel() is a void method that will update the progress by adding 1 to the current value stored. Game progress1 = new Game(); Game progress2 = progress1; progress1.changeLevel(); What is true about progress1 and progress2? 1 pts Question 4 Answer: 15 None of the above Answer: 105 What is output? int x = 10; System.out.println("Answer: " + x + 5);
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 3/10 Answer: x10 Answer: x5 1 pts Question 5 System.out.println(str.substring(1, 2)); System.out.println(str.substring(0, 1)); System.out.println(str.substring(1, 1)); System.out.println(str.substring(0)); System.out.println(str.substring(0, 0)); Consider the following code: String str = "Computer Science"; Which of the following statements correctly prints the first character in the String str ? 1 pts Question 6 turnOn(loungeLamp); loungeLamp.turnOn(Lightbulb); Lightbulb.turnOn(); The class Lightbulb contains a non-static void method with no parameters named turnOn. Suppose a Lightbulb object loungeLamp has been declared as follows: Lightbulb loungeLamp = new Lightbulb(); Which of the following correctly calls the method turnOn?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 4/10 Lightbulb.turnOn(loungeLamp); loungeLamp.turnOn(); 1 pts Question 7 CustomClass(int num); newCustomClass(); All options could be signatures for constructors for this class constructor(double x, double y); CustomClassConstructor(); Which of the following could be the signature of a constructor from a class named CustomClass ? 1 pts Question 8 5.09901951359278 Error: possible loss of precision 6 5 5.0 What is stored in the variable s after the following code is executed? int s = Math.sqrt(26);
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 5/10 1 pts Question 9 Nothing is printed. An error is caused because toUpperCase is a void method. YARNyarn yarnyarn yarnYARN YARNYARN What is printed by the following code? String a = "yarn"; String b = a; a = b.toUpperCase(); System.out.println(a + b); 1 pts Question 10 string1.length() Integer.MAX_VALUE new Double() Math.random() a.intValue() Which of the following is a call to a static method? 1 pts Question 11 What is printed by the following code segment?
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 6/10 0 60 01 6 Nothing is printed, an error occurs. int x = 24601; System.out.println(x.substring(3, 4)); 1 pts Question 12 -98 -97.6 -96 97.6 98 Consider the following code: double x = -97.6; System.out.println(Math.abs(x)); What is output? 1 pts Question 13 Suppose a method has a return type of String , the name myMethod and a parameter list of String s, int i (in that order). Which of the following methods described below has the same signature as this method?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 7/10 return type: String , name: otherMethod , parameter list: String s, int i return type: double , name: myMethod , parameter list: String s, int i return type: String , name: myMethod , parameter list: double d, int i return type: String , name: myMethod , parameter list: int i, String s return type: String , name: myMethod , parameter list: String s 1 pts Question 14 true 1 0 false -1 What is output by the following code segment? Integer a = new Integer(12); Integer b = new Integer(22); System.out.println(a.compareTo(b)); 1 pts Question 15 Return type: String. Parameters: none Return type: String. Parameters: one String parameter Return type: void. Parameters: one String parameter Which of the following describes the return type and parameters of the Scanner method nextLine?
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 8/10 Return type: int. Parameters: multiple String and int parameters Return type: void. Parameters: none 1 pts Question 16 int n = (int) (Math.random() * 10) - 20; int n = (int) (Math.random() * 10) - 21; int n = (int) (Math.random() * 20) - 10; int n = (int) (Math.random() * 21) - 10; int n = (int) (Math.random() * 11) - 20; Which of the following correctly gives random numbers between -10 and 10 inclusive? 1 pts Question 17 Shoe B = new Shoe(8); The image below shows the Javadoc for all constructors of a class named Shoe. Which of the following constructor calls will NOT compile correctly?
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 9/10 Shoe D = new Shoe(13 / 2, true); Shoe E = new Shoe(7, "Left"); Shoe C = new Shoe(11, false); Shoe A = new Shoe(); 1 pts Question 18 w o 3 2 1 Consider the following code: String q = "power"; String r = "brown"; System.out.println(q.indexOf(r.substring(3, 4))); What is output? 1 pts Question 19 The answer is: 8 The answer is: 6.0 What is output? System.out.println("The answer is: " + Math.pow(2, 3));
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
10/12/21, 11:41 AM Quiz: Unit 2 Exam https://courses.projectstem.org/courses/10083/quizzes/220976/take 10/10 Not saved The answer is: 6 The answer is: 8.0 The answer is: 1 1 pts Question 20 13 5 8 1 85 58 Consider the following code: int x = 5; int y = 8; System.out.println(x + y); What is output when this code is executed? Submit Quiz