Programming FB Project
Programming FB Project
Programming FB Project
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
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. \
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
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)
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)
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
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.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