Quiz 2 1. During the Design phase of software development, the programmer implements features gathered during the Requirement phase. a. False 2. If the requirement step of the Spiral Model of development is forgotten, which of the following could occur?bo a. Required software features are missing from the program 3. You’d like to see a movie with a few friends. You write an email to confirm plans Hi Friends, There’s a new movie “Attack of the Duke!” premiering this Friday at Oracle Cinema at 4:30 PM. The cinema is at the corner of South Street and Walnut Ave. Subway would be the best way to get there. Would any of you be interested in going? Which of the following are requirements for this plan? a. Watch “Attack of the Duke!” on Friday at Oracle Cinema at 4:30pm 4. During the Testing phase of software development, which of the following are the tasks undertaken by the programmer? a. Fixing the bugs b. Finding the buds 5. What is the purpose of adding comments in the code? a. Provide an explanation about the code to the programmer 6. Code within curly braces is called a “Block of code”. a. True 7. A Java program can be written in the single line. a. True 8. Which of the following are considered Whitespace? a. Space between words b. Indentation before the code c. Blank lines in the code ** Space between the [ ] braces is not Whitespace!! ** Space in the print statement is not Whitespace!! 9. Which of the following 2 statements are true about whitespace? a. Whitespace helps to keep your code organized b. Whitespace makes your code more readable 10. Which of the following three statements are true about breakpoint? a. They can be used to check the current state of the program b. They pause code execution c. They help with debugging 11. An object may interact with another object by invoking methods. a. True 12. Which of the following language is called a procedural language? a. C 13. In the code example below, identify any methods: public class Employee { public String name = " Duke"; public int empId = 12105; public float salary; public void displaySalary(){ System.out.println("Employee Salary: "+salary); } } a. displaySalary() 14. In object oriented programming, an object comprises of properties and behaviors where properties represented as fields of the object and behavior is represented as method. a. True 15. In object oriented programming, there is an emphasis on which of the following two: a. Object interaction without a prescribed order b. Modelling objects Quiz 3 – (L1 – L2) 1. Which of the following data types is the largest? a. Long 2. Which two are recommended practices for naming final variables? a. Capitalize every letter b. Separate words with an underscore 3. This declaration represents a long data type. long a = 123L; a. True 4. Which keyword makes a variable’s value unchangeable? a. Final 5. Assuming x is an int, which of the following are ways to increment the value of x by 1? a. x = x + 1; b. x++ ; c. x+=1 ; 6. What is the range of the byte data type? a. -27 to 27-1 7. Which data type is most commonly used to represent numeric data? a. Int 8. What is the output? public class Person { public static void main(String args[]) { int age = 20; System.out.println("Value of age: " +age); age = 5 + 3; System.out.println("Value of age: " +age); age = age + 1; age++; System.out.println("Value of age: " +age); } } a. Value of age: 20 Value of age: 8 Value of age: 10 9. Identify the names of two variables used in the given code. public class Variables { public static void main(String args[]) { String strVal = "Hello"; int intVal = 0; System.out.println("Integer: " +intVal) } } a. strVal b. intVal 10. Which two are valid assignments of a? a. Int a; a=10; b. Int a = 10; 11. Assigning a value to the variable is called "initialization". a. True 12. Which of the following two statements are true about variables? a. They make code more flexible b. They allow code to be edited more efficiently 13. Which two data types are appropriate for their variable? a. Double checkingAmount = 1500; b. String firstName = “Alex”; 14. Java is a strongly typed language; therefore you must declare a data type for all variables. a. True 15. What is the output? public class Welcome { public static void main(String args[]) { System.out.println("This is my first program"); int a = 2; System.out.println("a is " + a); } } a. This is my first program a is 2 Quiz 3 ( L3 – L5) 1. A String can be created by combining multiple String Literals. a. True 2. Which is the correct declaration for a char data type? a. char size = ‘M’; 3. Which two statements compile? a. String name = “J”; b. String name = “Java”; 4. Double quotes may be used with char literal values. a. False 5. What is the output? public static void main(String args[]) { String greet1 = "Hello"; String greet2 = "World"; String message2 = greet1 +" " +greet2 +" " +2016 +"!"; System.out.println(message2); } a. Hello World 2016 ! 6. In Java, char is a primitive data type, while String is an object data type. a. True 7. System.in readies Scanner to collect input from the console. a. True 8. The Scanner class accepts input in which form? a. Tokens 9. Which two statements are true about the Scanner class? a. A Scanner object opens a stream for collecting input b. A Scanner’s delimiter can be changed 10. What is parsing? a. Converting text to numeric data 11. Automatic promotion from smaller data type to a larger data type is not allowed in Java. a. False 12. Which two statements are correct about the usage of an underscore? a. Underscores help make large numbers more readable b. Underscores do not affect the value of the variable 13. Which exception occurs because a String cannot be parsed as an int? a. NumberFormatException 14. Which is a valid way to parse a String as an int? a. int intVar1 = Integer.parseInt(“100”); 15. A double with the value of 20.5 is cast to an int. What is the value of the int? a. 20 Quiz 4 ( L1 ~ L2) 1. The import statement consists of two parts. import package.className; One is the package name and the other is the classname. a. True 2. Which two are valid import statements of the Scanner class? a. Import java.util.Scanner; b. Import java.util.*; 3. Which of the following wild card character is used to import all the classes in a particular package? a. * 4. Given the import statement: import java.awt.font.TextLayout; which is the package name? a. Java.awt.font 5. The classes of the Java class library are organized into packages. a. True 6. Which is a risk of using fully qualified class names when importing? a. Code readability is reduced 7. Import statements are placed above the class definition. a. True 8. Which of the following scenarios would be ideal for writing a method? a. When you don’t want to repeat similar lines of code to describe an object’s behaviour 9. An argument is a value that's passed during a method call a. True 10. Once an object is instantiated, how might its fields and methods be accessed in Java? a. Using the dot (.) operator 11. You’re designing banking software and need to store 10000 customer accounts with information on the accountholder’s name, balance, and interest rate. The best approach is store 30000 separate variables in the main method. a. False 12. Which of the following two operations are appropriate for the main method? a. Creating instances of objects b. Calling an instance object’s field and methods 13. Object instantiation is done using what keyword? a. new 14. Which is a valid way of calling the testMethod in the TestClass? Assume a testInstance has been created. public void testMethod(int x, double y){ System.out.println(x/y); } a. testInstance.testMethod(10,3.5); 15. In Java, methods usually hold the properties of an object. a. False Quiz 4 (L3 – L5) 1. Which class is used to generate random numbers? a. Random 2. You need to generate random integer values in the range 2 through 10. This code fragment will produce the desired result. Random r = new Random(); r.nextInt(9) + 2; a. True 3. You need to generate random integer values between 0 and 80 (inclusive). Which statement should you use? a. nextInt(81); 4. Which values are returned by the method nextBoolean(); a. Either a true or false 5. What is the output? public static void main(String args[]) { String greeting = "Java World!"; String w = greeting.replace("a", "A"); System.out.println(w); } a. JAvA World! 6. What is the output of the following code? public static void main(String args[]) { String firstString = "Java"; firstString = firstString.concat("World"); System.out.println(firstString); } a. JavaWorld 7. What is the output? public static void main(String args[]) { String greeting = "Java World!"; String w = greeting.substring(7, 11); System.out.println(w); } a. rld! 8. The replaceFirst() method replaces only the first occurrence of matching character pattern in a string. a. True 9. The String class must be imported using java.lang.String; a. False 10. The indexOf() method returns the index value of a character in the string. a. True 11. String objects are immutable. a. True 12. What is the approximate value of PI? a. 3.141 13. All the methods in the Math class are static methods. a. True 14. Every method of the Math class returns a numerical result. a. True 15. The Math class methods can be called without creating an instance of a Math object. a. True Quiz 5 1. An employee is eligible for a bonus based on certain criteria. Under what conditions does "Eligible for a bonus" print? int rating; int experience; if (rating > 1 && experience == 5) { System.out.println ("Eligible for a bonus"); } a. 5 experience and 2 or more rating 2. What is the result? public static void main(String[] args) { int point = 10; String s = (point == 1 ? "point" : "points"); System.out.println("I scored " +point +" " +s ); } a. I scored 10 points 3. Which two are not logical operators? a. + b. % 4. In Java, an if statement can be nested inside another if statement. a. True 5. Which two statements are true about the default statement? a. The default statement is optional in switch statement b. When the input does not match any of the cases, the default statement is executed 6. A break statement causes control to transfer to the end of the switch statement. a. True 7. What is the output? public static void main(String args[]) { char grade ='E'; if (grade == 'A') { System.out.println("Excellent performer"); }else if (grade == 'B') { System.out.println("Good Performer"); }else if (grade == 'C') { System.out.println("Average Performer"); }else { System.out.println("Below Average Performer"); } } a. Below Average Performer 8. What is the output? public static void main(String args[]) { char ch ='c'; switch(ch) { case 'a': case 'e': case 'i': case 'o': case 'u': System.out.println("Vowels"); break; default: System.out.println("Consonants"); } } a. Consonants 9. A String comparison with == compares the Strings’ locations in memory and not the content of the String. a. True 10. Which three are conditional statements? a. If statement b. If/else statement c. Switch statement 11. What is the output? public static void main(String[] args) { String name = "Java"; String language = "Programming"; String fullName = name + language; boolean test = fullName.equals(name + language); System.out.println(test); } a. True 12. How should Strings be compared? a. The equals() method 13. An if/else statement is used when you need to choose between two alternatives. a. True 14. Which are used in a boolean expression? a. Operators b. Variables 15. What is the output? public static void main(String[] args) { int age = 43; if (age == 43){ System.out.print("Bob is 43 "); } if (age == 50){ System.out.print("Bob is 50 "); } } a. Bob is 43