Starting from:

$12

CMIS141Homework1_SheetForAnswers

CMIS141 Homework #1 Chapters 1 & 2 Total Points: 40 – 5% of the final grade Fill in the Blank Questions (1 pt each – Total 3 pts): 1. __________ should explain non-obvious aspects of a program and should not be redundant with the code. 2.When a java program with no syntax errors is compiled, the compiler generates a bytecode file. For example, if you compile the Welcome.java source code, the following file is created: _________________. 3. Computer __________, also known as software, are instructions to the computer. True/False Questions ( 1 pt each – Total 3 pts ): 1. Java is a high-level language. TRUE FALSE 2. The Java compiler translates Java programs into machine language code known as bytecode. TRUE FALSE 3. showMessageDialog is a JOptionPane method to display text in a message dialog box. TRUE FALSE Multiple-Choice Questions( 1 pt each – Total 16 pts ): 1. println is a method used with __________ a. objects of the String class b. the System.in object c. the System.out object d. the Scanner class 2. The characters // in a line a. are part of an expression that uses integer division b. are part of an expression that uses integer division c. mean that the rest of the line is a comment d. are an escape sequence 3. Words that have predefined meanings in Java and cannot be used as variable names are called a. identifiers b. comments c. operators d. reserved words 4. A program written in a high-level language is called a. compiler b. source code c. comment d.block 5. The words required at the start of every "main" method definition are: a. private static void b. public static void c. public void d. public static e. static void 6. Suppose you define a Java class as follows: public class Test { public static void main(String[] args) { System.out.println("This is a test program"); } } In order to compile this program, the source code should be stored in a file named a. Test, class b. Test.doc c. Test.txt d. Test.java e. Any name with extension Java 7. Which of the following statements is correct to display Welcome to Java on the console? a. System.out.println ('Welcome to Java1); b. System.out.println ("Welcome to Java"); c. system.println ("Welcome to Java"); d. System.out.print ('Welcome to Java'); e. system.out.print ("Welcome to Java"); 8. What is the printout of the following code: double x = 10.1; int y = 10; System.out.println("x is " + x + " and y is " + y); a. x is 10 and y is 10 b. x is 10.0 and y is 10.0 c. x is 11 and y is 11 d. x is 10.1 and y is 10 e. x is 10.1 and y is 10.0 9. To assign a value 1 to variable x, you write a. 1 = x; b. x = 1; c. x := 1; d. 1 := x; e. x == 1; 10. Which of the following is a constant, according to Java naming conventions? a. MAX_VALUE b. Test c. read d. ReadInt e. COUnt 11. What is the result of 45 / 4? a. 10 b. 11 c. 11.25 d. 12 12. 24 % 5 is _____ a. 1 b. 2 c. 3 d. 4 e. 0 13. Suppose x is 1. What is x * 2 + 1? a. 0 b. 1 c. 2 d. 3 e. 4 14. What is the printout of the following code: double x = 5.5; int y = 5; System.out.println("x is " + x + " and y is " + y); a. x is 5 and y is 6 b. x is 6.0 and y is 6.0 c. x is 6 and y is 6 d. x is 5.5 and y is 5 e. x is 5.5 and y is 5.0 15. Suppose a Scanner object is created as follows: Scanner keyboard = new Scanner(System.in); What method would you use to read an int value? a. keyboard.nextInt(); b. keyboard.nextInteger(); c. keyboard.int(); d. keyboard.integer(); 16. To declare a constant MAX_LENGTH inside the main method with value 99.98, you write a. final MAX_LENGTH = 99.98; b. final float MAX_LENGTH = 99.98; c. double MAX_LENGTH = 99.98; d. final double MAX_LENGTH = 99.98; Application Questions (Total 12 pts): 1. ( 2 pts)Write an output type statement using the JOptionPane to display “CMIS 141 Rocks!” 2. (2 pts) Write a single statement that displays to standard output(console) the message “There are 10 kinds of people.” 3. (2 pts)Fill in the statements in class Rain to display the following. Pitter-patter Goes the rain on the steps public class Rain { public static void main(String[] args) { System.out.println( ); System.out.println( ); } } 4.(2 pts)Make the necessary changes in the following program program so that it displays Hello World! instead of Welcome to Java!. public class HelloWorldApp { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } 5. (4 pts)Show the output of the following code: public class Test { public static void main(String[] args) { int x1, x2, i, j, k, y, z; float f; x1 = 1; x2 = 1; y = 5 + x1; z = 5 + x2; i = 6 % 4; j = 1; j = j + 3; k = 25 / 2; f = (2 / 5) * k; System.out.println("x1 is " + x1); System.out.println("x2 is " + x2); System.out.println("i is " + i); System.out.println("j is " + j); System.out.println("k is " + k); System.out.println("y is " + y); System.out.println("z is " + z); System.out.println("f is " + f); } } Essay Questions (6 pts): 1. (2 pts) In a java program, what is the importance of the main() method? 2. (4 pts) What is a compiler? Explain in detail the compilation process of a java program such as Welcome.java. Describe exactly what happens when you compile a syntax free java program.

More products