Unformatted text preview:

Question 1 In the following array what is the value of fees length double fees 3 00 3 50 6 35 7 35 9 00 5 00 Question 2 Having multiple class methods of the same name where each method has a different number of or type of parameters is known as a 1 b 2 c 4 d 6 e None of the above a method overriding b method overloading c d encapsulation e None of the above information hiding Question 3 Why is the following method one which has infinite recursion public int infiniteRecursion int n if n 0 return infiniteRecursion n 1 else return 0 A because there is no base case B because the base case will never be true C because the recursive call does not move the parameter closer to the base case D because the recursive call moves the problem further away from the base case E None of the above Question 4 Given the following recursive method public int question1 2 int x int y if x y return 0 else return question1 2 x 1 y 1 If the method is called as question1 2 8 3 what is returned a 11 b 8 c 5 d 3 e None of the above Question 5 In Java arrays are a primitive data types b primitive data types if the type stored in the array is a primitive data type and objects otherwise c objects d e None of the above interfaces Question 6 Assume an int array candy stores the number of candy bars sold by a group of children where candy j is the number of candy bars sold by child j Assume there are 12 children in all What does the following method do public int question6 int value1 0 int value2 0 for int j 0 j 12 j if candy j value1 value1 candy j value2 j return value2 It returns the total number of children who sold 0 candy bars It returns the index of the child who sold the most candy bars It returns the number of candy bars sold by the child who sold the most candy bars It returns the total number of children who sold more than 0 candy bars a b c d e None of the above Question 7 Static methods can invoke other static methods reference any instance data reference non static instance data invoke non static methods a b c d e None of the above a c area b c i getArea c c area d c i area e None of the above Question 8 The Container class has one integer attribute named area that is set to a default value of 3 There is one accessor method named getArea that returns the area Choose the code to fill in that will display the following on the screen 333 Container c new Container new Container new Container for int i 0 i c length i System out print code to fill in Question 9 In the following code what is the printout public class Test public static void main String args int list1 1 0 1 int list2 0 1 0 list2 list1 list1 0 0 list1 1 1 list2 2 2 for int i 0 i list1 length i System out print list1 i a 1 2 1 b 0 1 2 c 0 1 1 d 1 0 1 e None of the above Question 10 To initialize a String array names to store the three Strings Huey Duey and Louie you would do a String names Huey Duey Louie b String names new String Huey Duey Louie c String names 3 Huey Duey Louie d String names names 0 Huey names 1 Duey names 2 Louie 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 - Exam

Download Exam
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 Exam 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 Exam 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?