Pre-assessment 2.

4 for LO8, LO9, LO10, LO11, LO12, and LO13
Part 1. Directions: Read each statement carefully. Write the letter of the correct answer on the space provided before the number (5 points). 1. It is a location in a computer memory that is used to store values such as numbers and text and usually change as the program execute. a. Variable b. Primitive Date Types 2. These are predefined by Java Language and usually named by a keyword. a. Variable b. Primitive Date Types 3. It is a symbol used to denote concatenating a string. a. Plus sign (+) b. Dollar sign ($) 4. A data type that represents two states: true or false. a. Char b. Boolean 5. A data type that represents a single Unicode character. It must have its literal enclosed in single quotes (‘ ‘). a. String b. character (char)

Part 2. Directions: What data type (int, double, or string) is appropriate for storing each of the following values? Write your answer on the space before the number (10 points) 1. A product number 2. The amount of interest on a loan, such as 10% 3. The price of a CD 4. The name of your best friend 5. The number of books you own 6. The address of your school 7. The area of a circle 8. The title of a book 9. Your grade in Math 10. The number of your subjects

Self-check 2.4
Part 1. Directions: Read each statement carefully. Write the letter of the correct answer on the space provided before the number (5 points). 1. It is a location in a computer memory that is used to store values such as numbers and text and usually change as the program execute. b. Variable b. Primitive Date Types 2. These are predefined by Java Language and usually named by a keyword. b. Variable b. Primitive Date Types 3. It is a symbol used to denote concatenating a string. b. Plus sign (+) b. Dollar sign ($) 4. A data type that represents two states: true or false. b. Char b. Boolean 5. A data type that represents a single Unicode character. It must have its literal enclosed in single quotes (‘ ‘). b. String b. character (char)

Part 2. Directions: What data type (int, double, or string) is appropriate for storing each of the following values? Write your answer on the space before the number (10 points) 1. A product number 2. The amount of interest on a loan, such as 10% 3. The price of a CD 4. The name of your best friend 5. The number of books you own 6. The address of your school 7. The area of a circle 8. The title of a book 9. Your grade in Math 10. The number of your subject

Part 3. Directions: Given the table below, declare the following variables with the corresponding data types and initialization values. Output to the screen the variable names together with the values. Variable name number letter result str integer character boolean String Data type Initial value 10 A True Hello

The following should be the expected screen output, 1. 2. 3. 4. Number = 10; letter = ‘a’; result = True; String = (“Hello”);

Part 4. Trace the output of the following statements: 1. Program 1: System.out.print(“Java”); System.out.print(“Programming”); Output: Java Programming 2. Program 2: System.out.println(“Java”); System.out.println(“Programming”); Output: Java Programming

Pre-assessment 2.5 for LO14, LO15, LO16, LO17, LO18, and LO19
Part 1. Directions: Answer the following: 1. The order in which the operations should be performed. a. Data Types b. Operator Precedence 2. Use to perform calculations with values in your programs. a. Arithmetic Operators b. Logical Operators 3. This arithmetic operator is used to add values. a. + b. – 4. This arithmetic operator that computes the remainder by dividing the dividend from the divisor. a. / b. % 5. A value used on either side of an operator is called ________ a. operant b. operand 6. Increment and decrement operators increase and decrease a value stored in a number variable by _______. a. 0 b. 1 7. It is a pre-increment operator a. ++i b. i++ Part 2. Given the following expressions, re-write them by writing some parenthesis based on the sequence on how they will be evaluated. average = score1 + score2 + score3 / 3 Answer: int average = (score1 + score2 + score3 / 3); result = 3 * 10 * 2 / 15 – 2 + 4 Answer: int result = (3 * 10 * 2 / 15 – 2 = 4); Part 3. Simulate the result. Write your answer on the space provided. Condition 3 * 6 *4 12 + 10 + 20 44 - 23 55 % 555 63 / 8 Result 72 42 21 5 7

Self-check 2.5
Part 1. Directions: Answer the following: 1. The order in which the operations should be performed. b. Data Types b. Operator Precedence 2. Use to perform calculations with values in your programs. b. Arithmetic Operators b. Logical Operators 3. This arithmetic operator is used to add values. b. + b. – 4. This arithmetic operator that computes the remainder by dividing the dividend from the divisor. b. / b. % 5. A value used on either side of an operator is called ________ b. operant b. operand 6. Increment and decrement operators increase and decrease a value stored in a number variable by _______. b. 0 b. 1 7. It is a pre-increment operator b. ++i b. i++ Part 2. Evaluate the following expressions. Show the solution and display the result on the space provided. (5 items) 1. 4 + 6 – 2 * 2 Answer: 6 2. 90 / 9 * 2 + 4 – 2 Answer: 22 3. ((3 / 3) * 9) – 6 + (4 + (2 * 2)) Answer: 11 4. (5 * 5 – 20) % 25 – 2 + 3 * 5 Answer: 3 5. 2 % 4 * 2 – 2 + 6 / 3 Answer: 4

Pre-assessment 2.6 for LO20 and LO21
Directions: Answer the following. Write the letter of the correct answer on the space provided. Escape sequence that: 1. moves the cursor to the beginning of the next line. a. \n b. \r 2. moves the cursor to the beginning of the current line. a. \n b. \r 3. Moves the cursor to the next tab stop a. \t b. \s 4. Prints a back slash character a. // b. \ 5. Prints a double quotation mark a. \’ b. \”

Self-check 2.6
Directions: Answer the following. Write the letter of the correct answer on the space provided. Escape sequence that: 1. moves the cursor to the beginning of the next line. b. \n b. \r 2. moves the cursor to the beginning of the current line. b. \n b. \r 3. Moves the cursor to the next tab stop b. \t b. \s 4. Prints a back slash character b. // b. \ 5. Prints a double quotation mark b. \’ b. \”

Pre-assessment 2.7 for LO22 and LO23
Directions: Read the statement carefully. Write the letter of your choice in the space provided before the number. 1. A class that makes it easy to pop up a standard dialog box that prompts users for a value or inform them of something. a. JOptionPane b. JOptionPaneWindow 2. It is package where JOptionPane can be imported. a. Javax.swing b. javax.exe 3. It is a method used to convert a string to an integer value a. parseDouble b. parseInt 4. It is a method used to convert a string to double value. a. parseDouble b. parseInt 5. The JOptionPane.showInputDialog will display a dialog with a message, a textfield and ________. a. OK button b. Cancel button

Self-check 2.7
Directions: Read the statement carefully. Write the letter of your choice in the space provided before the number. 1. A class that makes it easy to pop up a standard dialog box that prompts users for a value or inform them of something. b. JOptionPane b. JOptionPaneWindow 2. It is package where JOptionPane can be imported. b. Javax.swing b. javax.exe 3. It is a method used to convert a string to an integer value b. parseDouble b. parseInt 4. It is a method used to convert a string to double value. b. parseDouble b. parseInt 5. The JOptionPane.showInputDialog will display a dialog with a message, a textfield and ________. b. OK button b. Cancel button

Pre-assessment 3.1 for LO1 and LO2
Part 1. Directions. Read each statement carefully, select the letter of the correct answer and write your answer on the space provided. (7 items) 1. It is a code structure where the statements are executed in sequence, without branching off in another direction. a. Sequence structure b. Sequence number c. Decision Structure 2. A control structure that allows different parts of a program to execute depending on the exact situation. a. Sequence structure b. Sequence number c. Decision Structure 3. It is a “less than” operator. a. > b. < 4. This operator sets one value equal to another a. = b. == 5. The operator “<=” means a. less than or equal to b. greater than or equal to 6. The operator “!=” means a. and equal to b. not equal to 7. The expression String Str = “Java” is exactly the same with String str = “Java” a. Yes b. No c. I don’t know 8. Evaluate the expression: 25 < 5 * 5 a. True b. False c. Unpredictable 9. Evaluate the expression: (8 + 1) >= (2 * 3) a. True b. False c. Unpredictable 10. Evaluate the expression: 10.0 + 10.0/1.0 < 10.1 a. True b. False c. Unpredictable Part 2. Directions: Evaluate the following expression. Write T if the expression is TRUE, write F if the expression is FALSE. Write your answer on the space provided before the number (10 points) Where: 1. 2. 3. 4. 5. a>b a<b a=b (b + c) > a c != (a – b) a = 50 b = 25 c = 15 6. b <= c 7. a >= b 8. (b + c) == a 9. c == c 10. b >= (a – c)

Self-check 3.1
Directions: Read each statement carefully, write TRUE if the statement is correct otherwise write FALSE. Write your answer on the space provided before the number. 1. The expression op1 == op2 is true if op1 is equal to op2. 2. The expression op1 <= op2 is true if op1 is less than to op2. Directions: Select the letter of the correct answer and write on the space provided before the number. 3. It is a code structure where the statements are executed in sequence, without branching off in another direction. a. Sequence structure b. Sequence number c. Decision Structure 4. A control structure that allows different parts of a program to execute depending on the exact situation. a. Sequence structure b. Sequence number c. Decision Structure 5. The relational operator ‘<’ means _____. a. Greater than b. less than c. equal to 6. Evaluate the expression: (1 + 2) == 3 a. True b. False c. Unpredictable 7. Evaluate the expression: 25 < 5 * 5 a. True b. False c. Unpredictable 8. Evaluate the expression: (8 + 1) >= (2 * 3) a. True b. False c. Unpredictable 9. Evaluate the expression: 10.0 = 0.10 < 11.0 a. True b. False c. Unpredictable 10. Evaluate the expression: 10.0 + 10.0/1.0 < 10.1 a. True b. False c. Unpredictable Part 2. Directions: Evaluate the following expression. Write your answer on the space provided before the number. Where: 1. 2. 3. 4. 5. a>b a<b a == b (b + c) > a c != (b – a) a=5 b = 10 c = 15 6. b <= c 7. a >= b 8. (b + c) == a 9. c == c 10. b >= (c – a)

Pre-assessment 3.2 for LO3 and LO4
Directions: Read each statement carefully. Select the letter of the correct answer and write on the space provided before the number. 1. These are logical operators used to combine more than one condition that may be true or false a. Short-circuit logical operator b. Logical operator c. Bitwise Logical Operator 2. It is a bitwise logical “OR” operator a. & b. | c. || 3. These are logical operators that manipulate the bits of an integer (byte, short, char, int, long) value. a. Short-circuit logical operator b. Logical operator c. Bitwise Logical Operator 4. Looks at two expressions and returns a value of “true” if both expressions are true. a. & b. && c. || 5. Looks at two expressions and returns a value of “true” if either one-but not both-of the expressions are true. a. & b. && c.||

Self-check 3.2
Part 1. Directions: Read each statement carefully, write TRUE if the statement is correct otherwise write FALSE. Write your answer on the space provided before the number. 1. Logical operator deals with connecting the Boolean values. 2. The operator used for short-circuit logical OR is &&. 3. The operator used for short-circuit logical AND is ||. Directions: Select the letter of the correct answer and write your answer on the space provided 4. Used to combine more than one condition that may be true or false. a. Short-circuit logical operator b. Logical operator c. Bitwise Logical operator 5. Manipulate the bits of an integer (byte, short, char, int, long) value. a. Short-circuit logical operator b. Logical operator c. Bitwise Logical operator Part 2. Directions: Evaluate the following expression. Write your answer on the space provided before the number. Where: a = 50 b = 25 c = 15 5. c != (a – b)

1. (a > b) && (a > b) 2. (a == b) || (b + c) < c

3. (c < b) && (b > a) 4. (a < b) || (b > a)

Pre-assessment 3.3 for LO5 and LO6
Directions: Read each statement carefully, select the letter of the correct answer and write your answer on the space provided. 1. How many choices are possible when using a single if-else statement? a. 1 b. 2 c. 3 d. 4 2. What does the following code fragment displays? Int sum = 14; If (sum < 20) System.out.print(“Under”); else { System.out.print(“Over”); System.out.println(“the limit”); } a. Under b. Over c. Under the limit d. Over the limit 3. What does the following code fragment displays? Int sum = 7; If (sum > 20) { System.out.print(“You win”); } else { System.out.println(“You lose”); } System.out.print(“the prize.”); a. You win b. You lose c. You win the prize. d. You lose the prize. 4. What does the following code fragment displays? Int sum = 21; If (sum != 20) System.out.print(“You win”); else System.out.print(“You lose”); System.out.println(“”the prize.”); a. You win b. You lose c. You win the prize. d. You lose the prize. 5. In using the switch statement, when the Boolean_expression is true, the program will ________. a. Execute a statement b. terminate the program c. hang the program

Self-check 3.3
Directions: Read each statement carefully,, select the letter of the correct answer and write your answer on the space provided. 1. What does the following code fragment displays? Int height = 10; If (height <= 12) System.out.print(“Low bridge: ”); System.out.println(“proceed with caution”); a. Nothing is written c. Low bridge: b. Proceed with caution d. Low bridge: proceed with caution 2. What does the following code fragment displays? Int height = 13; If (height <= 12) System.out.print(“Low bridge: ”); System.out.println(“proceed with caution”); a. Nothing is written c. Low bridge: b. Proceed with caution d. Low bridge: proceed with caution 3. What does the following code fragment displays? Int depth = 8; If (depth >= 9) { System.out.print(“Danger: “); System.out.print(“deep water. “); } System.out.println(“No swimming allowed.”); a. Danger: c. Danger: deep water. No swimming allowed b. Danger: deep water. d. deep water. No swimming allowed 4. Fill the blank so people under 21 years are offered Grape Soda. If (age ___ 21) System.out.println(“How about a Brew?”); else System.out.println(“Care for some Grape Soda?”); a. < b. == c. != d. >= 5. Fill-in the blank, so student with grade greater than or equal to 75 will pass the course. If (grade ____ ) System.out.println(“You passed”); else System.out.println(“Sorry, you failed”); a. < b. == c. != d. >=

Part 2. Directions: Write the syntax/form of the following items. 1. If-statement 3. If-else-if statement

2. If-else statement

Pre-assessment 3.4 for LO7 and LO8
Directions: Fill-in the missing syntax of the switch structure flowchart

Switch Statement Flowchart

or

8. It is an alternative to the use of the series of nested if statements. a. If statement b. switch statement c. for statement 9. In the format of the switch statement, the (switch_expression) should be a/an ______expression. a. Double or String expression c. character expression only b. Integer or character expression d. String expression only 10. In the switch statements, if none of the cases are satisfied, this block is executed. a. Default block b. break block c. case block

Self-check 3.3
Input the letter of your choice from: S-Small; M-Medium; L-Large; X-Extra-large and display the value for each choice. For example. Choice: S The size is Small Algorithm Int size = 35; Switch (size / 5 ) { case 9: case 10: System.out.println(“S”); System.out.println(“The size is Small”); Break; case 8: case 7: System.out.println(“M”); System.out.println(“The size is Medium”); Break; case 5: case 6: System.out.println(“L”); System.out.println(“The size is Large”); Break; case 3: case 4: System.out.println(“X”) System.out.println(“The size is Extra-large”); Break; }

Lab 2.7
Based on the algorithm presented, write a Java program to calculate the area of a circle. Assign an integer values to the variable radius – for example int radius = 2. Save the class as Circle.java. Algorithm: 1. Read in the radius 2. Compute the area using the following formula: Area = radius x radius x 3.142 3. Display the area Write your source codes. public class Circle { public static void main(String[] args) { int radius = 2; double area = 3.142; area = radius * radius * area; System.out.println(“The area of the circle is “+ area); } } What is the output of the program? The area of the circle is 12.568

Lab 2.8: Using variables and data types
Write a program that converts pounds into kilograms. Assign appropriate values to the variable in pounds, converts it to kilograms, and displays the result. Save the class as Weight.java. [Note: One pound is 0.454 kilograms.] Write your source codes. public class Weight { public static void main(String[] args) { String Onepound = “0.454 kg”; System.out.println(“One pound is = “+ Onepound); } } What is the output of the program? One pound is = 0.454 kg

Lab 2.9 Using variables and data types
Write a Java program that declares variables to represent the length and width of a room. Assign appropriate values to the variables – for example, length = 20 and width = 15. Then complete and display the floor space in square feet. Display explanatory text with the value – for example, The floor space is 300 square feet. Save the class as Room.java. [Note: Floor space = length * width.] Write your source codes. public class Room { public static void main(String[] args) { int length = 30, width = 25, floorSpace = 0; floorSpace = length * width; System.out.println(“The floor space is “+ floorSpace); } } What is the output of the program? The floor space is 750

Lab 2.10 GETTING THE AVERAGE OF THREE NUMBERS
In this laboratory activity, you will create a program that outputs the average of three numbers. Let the value of the three numbers be 10, 20 and 45. Save the class as Average.java. The expected output is, number1 = 10 number2 = 20 number3 = 45 average is = 25 Write you source codes. public class Average { public static void main(String[] args) { int num1 = 10, num2 = 20, num3 = 45; int average = (10 + 20 + 45) / 3; System.out.println(“The average is “+ average); } } What is the output of the program? The average is 25

LAB 2.11. Getting the results of the different variables declared using arithmetic operators. 1. Open NetBeans IDE and create a new project and name it as ArithmeticOperators.java. 2. Write your source codes. public class ArithmeticOperators { public static void main(String[] args) { int i = 37, j = 42; double x = 27.475, y = 7.22; int add1 = (i + j); double add2 = (x + y); int subtract1 = (i – j); double subtract2 = (x – y); int multiply1 = (I * j); double multiply2 = (x * y); int divide1 = (i / j); double divide2 = (x / y); int remainder1 = (i % j); double remainder2 = (x % y); double mix1 = (j – y); double mix2 = (i * x); System.out.println(“ Variable values. . .”); System.out.println(“i = “+ i);

System.out.println(“j = “+ j); System.out.println(“x = “+ x); System.out.println(“y = “+ y); System.out.println(“Adding. . .”); System.out.println(“i + j = “+ add1); System.out.println(“x + y = “+ add2); System.out.println(“Subtracting. . .”); System.out.println(“i – j = “+ subtract1); System.out.println(“x – y = “+ subtract2); System.out.println(“Multiplying. . .”); System.out.println(“i * j = “+ multiply1); System.out.println(“x * y = “+ multiply2); System.out.println(“Dividing. . .”); System.out.println(“i / j = “+ divide1); System.out.println(“x / y = “+ divide2); System.out.println(“Computing the remainder. . .”); System.out.println(“i % j = “+ remainder1); System.out.println(“x % y = “+ remainder2); System.out.println(“Mixing types. . .”); System.out.println(“j – y = “+ mix1); System.out.println(“i * x = “+ mix2); } }

LAB 2.12. Getting the sum of two integers Write a Java program that reads in two integers and display the sum of the two integers. Save the class as Sum.java. Write your source codes. public class Sum { public static void main(String[] args) { int integer1 = -4, integer2 = -25; int sum = -4 + -25; System.out.println(“The sum of the two integers: “+ sum); } } What is the output of the program? The sum of the two integers: -29 Lab 2.13 Write a class that displays the following heading on one line: “First Name Last Name Student Number Phone Number”

Display your first name, last name, student number and phone number on the second line, below the appropriate column headings. Save the class as Escape.java. Write your source codes. public class Escape { public static void main(String[] args) { String FirstName = “Rick Azley”, LastName = “Martin”; Double StudentNumber = 21-9154, PhoneNumber = +63905-1752-472; System.out.println(“\”Rick Azley\tMartin\t21-9154\t+63905-1752-472\””); } } What is the output of the program? “Rick Azley Martin 21-9154 +63905-1752-472”