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 4 pts 11 13 coding problems 20 pts You may get partial credit for questions 11 13 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 Student ID Section 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 numbers length 2 int numbers 5 4 3 2 1 a 2 b 3 c 1 5 d error incompatible types possible lossy conversion from double to int e None of the above 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 encaplsulation b method overriding c method overloading d information hiding e None of the above Question 3 Given the definition and code fragment What is the output int total 0 int i 5 j 8 for int start j start i start total start i start System out print total Question 4 What is c after the following switch statement a 6 b 4 c 3 d 2 e None of the above char c C switch c 2 case C c 1 break case D c 2 break default c 3 System out print c a D b E c F d Syntax error e None of the above Question 5 What is the number of iterations this do while loop will execute int num 10 int val 1 do System out print num num val val 2 while num 0 a 4 b 3 c 5 d This is an infinite loop e None of the above Question 6 Assume you have an int array swimRaces which stores the number of events swam by a group of swimmer where swimRaces i is the number of events swam by swimmer i Given the method below what is the output for the method call in main method Assume there are 10 swimmers in all public static int question6 int a int ev1 10 int ev2 0 for int i 0 i 10 i if a i ev1 ev1 a i ev2 i return ev2 int swimRaces 3 2 4 5 2 1 7 8 3 5 System out println question6 swimRaces a 0 b 7 c 8 d 5 e None of the above Question 7 Static methods can a invoke every other methods b reference only instance data c reference both instance and class data d reference only static data e None of the above Question 8 The Cube class has one integer attribute named side that is set to a default value of 2 The Cube class contains one method named int volume that returns the volume of the cube Choose the code to fill in that will display the following on the screen 888 Cube c new Cube new Cube new Cube for int i 0 i c length i System out print code to fill in a c volume b c i volume c c volume d c i volume e None of the above Question 9 In the following code what is the printout public class Question9 public static void modData int first int second int temp second 1 second first 1 2 first 1 temp 1 public static void main String args int arr1 1 0 1 int arr2 0 1 0 modData arr1 arr2 1 for int i 0 i arr1 length i System out print arr1 i arr2 i a 1 0 1 0 1 0 b 1 1 1 1 0 1 c 1 0 1 1 1 0 d 1 1 1 0 1 0 e None of the above Question 10 If a and b are both int arrays then a b will a create an alias b copy all elements of a into b c copy the zero element of b into the zero element of a d return true if each corresponding element of b is equal to each corresponding element of a e None of the above Question 11 20 points Influenza also known as the flu is a respiratory illness caused by influenza viruses Type A and B viruses cause the large outbreaks during the winter season To protect ourselves from the flu one measure is to get the flu vaccine The flu vaccine contains tiny amounts of the viruses strains it protects against Scientists work hard every year to establish the correct strains to be included in the vaccine Given the class VirusStrain below write a class Vaccine with the following members Two virus strains instance data included in the vaccine A constructor taking 2 virust strains parameters that initialize the instance data A getter setter for each instance data We compare two vaccines based on the total strength of the virus strains it contains i e vaccine 1 is stronger than vaccine2 if the total strength of the two virus strains in vaccine1 is bigger than the corresponding strength in vaccine2 Write a compareTo method that compares two vaccines and returns appropriate values 1 1 0 based on their total strengths A toString method returning the information for each virus strain in 2 lines one line for each strain public class VirusStrain A virus strain is represented by its name and the strength Strength is expected to be a number between 1 10 10 being the highest strength The stronger the virus the more symptoms it can cause A vaccine containing a strain with high strength can potentially protect more private String name private int strength public VirusStrain String name int strength this name name this strength strength public String getName return name public void setName String n name n public int getStrength return strength public void setStrength int s strength s public String toString return name strength strength Question 12 20 points Write an application TestVaccines that analyzes an array of Vaccine objects for their strengths The program creates an array of 10 vaccines all containing the H1N1 strain of the type A virus the Brisbane strain of the type B virus and random strengths an integer in 1 10 for each strain The program will find and print to the screen the vaccine that protects the most You must use the compareTo method for full credit If more than one such vaccine exist pick arbitrarily any of them For example if the information of the vaccines in the array is given in the table below the program should display Vaccine Number 1 2 3 4 5 6 7 8 9 10 Strain1 Strain2 H1N1 4 Brisbane 3 H1N1 1 Brisbane 3 H1N1 6 Brisbane 4 H1N1 7 Brisbane 1 H1N1 8 Brisbane 5 Brisbane 9 H1N1 4 H1N1 10 Brisbane 1 Brisbane 2 H1N1 1 Brisbane 3 H1N1 3 Brisbane 1 H1N1 …


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?