Unformatted text preview:

CS 113 MIDTERM EXAM 2 There are 13 questions on this test The value of each question is 1 10 multiple choice 11 12 coding problems You may get partial credit for questions 11 12 If you finish early use the extra time to double check your work You may not use notes books or electronic devices of any sort All cell phones and other mobile devices must be turned off during the exam Good luck Name Section Student ID Answers for Questions 1 to 10 Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 Q9 Q10 EXAM SCORES Q1 Q10 Q11 Q12 Q13 TOTAL Question 1 In the following array what is the value of numbers length double numbers 3 00 3 50 4 00 5 00 6 35 7 35 8 35 9 00 Question 2 What will the value of x be after the switch statement executes a 1 b 2 c 4 d 8 e None of the above int x 10 switch x 6 a 14 b 11 c 6 d 12 e None of the above case 0 x 1 break case 1 x 4 break case 2 x 3 break case 3 x break case 4 x 2 break case 5 x 2 break case 6 x break a equals String b toUpperCase String c nextInt Random d sqrt Math e None of the above Question 4 What is true about arrays Question 5 Two overloaded methods must a return the same data b have the same number of parameters c have same parameter lists but different names d have different number of or type of parameters e None of the above Question 3 Which of the following methods is a static method The class in which the method is defined is given in parentheses following the method name a Arrays are primitive data types b Arrays can only store store objects c Arrays can store integers if they have 2 dimensions d Arrays are primitive data if the type stored in the array is a primitive data type and objects otherwise e None of the above Question 7 What does the following code do Assume list is an array of int values temp is some previously initialized int value and c is an int initialized to 0 Question 6 What is the value of count after the following code is executed int count 1 for boolean done false done count if count 3 done true a 2 b 5 c 4 d 3 e None of the above for int j 0 j list length j if list j temp c a It finds the smallest value and stores it in temp b It finds the largest value and stores it in temp c It counts the number of elements equal to the smallest value in the list d It counts the number of elements in list that are less than temp e None of the above Question 8 In the following code what is the printout public class Quest8 public static void main String args int x 1 2 3 int y 3 2 1 swap x 0 y System out print x 0 x 1 x 2 y 0 y 1 y 2 public static void swap int a int b int temp a a b 1 b 1 temp a 1 2 3 3 1 1 b 2 2 3 1 2 1 c 1 2 3 3 2 1 d 3 2 3 1 1 1 e None of the above Question 9 Which of the following is a legal way to declare and instantiate an array of ten Strings Question 10 If any int array a is passed as a parameter to a method which of the following would adequately define the parameter list for the method header a String s new String 10 b String 10 s new String c String s new String 10 d String s new String e None of the above a int b int a c a d int a e None of the above Question 11 Define a class named IntegerList that contains An instance data named list an array of integers A constructor that accepts an array size and creates a list of that size A getter and setter method for every instance data A randomize method that fills the list with random integers between 1 and 100 inclusive A toString method that returns a string containing the list elements separated by spaces A method merge that merges two integer lists into one integer list and returns it where elements of the first list are followed by those of the second list Question 12 Given the class Player below import java util Scanner public class Player private String name private int goals private int games public Player Scanner scan new Scanner System in name scan nextLine goals scan nextInt games scan nextInt public double getAverage return games 0 0 goals games Write a method topPlayers that takes two parameters 1 team an array of Player objects 2 target a double The method returns the total number of players in team that have an average number of goals per game higher than target


View Full Document

NJIT CS 113 - MIDTERM EXAM 2

Download MIDTERM EXAM 2
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view MIDTERM EXAM 2 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view MIDTERM EXAM 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?