programming fb project

20
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 l ocation 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

Upload: rick-martin

Post on 18-Oct-2015

20 views

Category:

Documents


0 download

TRANSCRIPT

  • 5/28/2018 Programming Fb Project

    1/20

    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 numbersand text and usually change as the program execute.

    a. Variable b. Primitive Date Types2. These are predefined by Java Language and usually named by a keyword.

    a. Variable b. Primitive Date Types3. 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. Boolean5. 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 number2.

    The amount of interest on a loan, such as 10%

    3. The price of a CD4. The name of your best friend5. The number of books you own6. The address of your school7. The area of a circle8. The title of a book9. Your grade in Math10.The number of your subjects

  • 5/28/2018 Programming Fb Project

    2/20

    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 numbersand text and usually change as the program execute.

    b. Variable b. Primitive Date Types2. These are predefined by Java Language and usually named by a keyword.

    b. Variable b. Primitive Date Types3. 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. Boolean5. 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 number2.

    The amount of interest on a loan, such as 10%

    3. The price of a CD4. The name of your best friend5. The number of books you own6. The address of your school7. The area of a circle8. The title of a book9. Your grade in Math10.The number of your subject

  • 5/28/2018 Programming Fb Project

    3/20

    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 Data type Initial value

    number integer 10letter character A

    result boolean True

    str String Hello

    The following should be the expected screen output,

    1. Number = 10;2. letter = a;3. result = True;4. 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

  • 5/28/2018 Programming Fb Project

    4/20

    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 thedivisor.

    a. / b. %5. A value used on either side of an operator is called ________

    a. operant b. operand6. Increment and decrement operators increase and decrease a value stored in a number

    variable by _______.

    a. 0 b. 17. 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 / 152 + 4

    Answer: int result = (3 * 10 * 2 / 152 = 4);

    Part 3.Simulate the result. Write your answer on the space provided.

    Condition Result

    3 * 6 *4 7212 + 10 + 20 42

    44 - 23 21

    55 % 555 5

    63 / 8 7

  • 5/28/2018 Programming Fb Project

    5/20

    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 thedivisor.

    b. / b. %5. A value used on either side of an operator is called ________

    b. operant b. operand6. Increment and decrement operators increase and decrease a value stored in a number

    variable by _______.

    b. 0 b. 17. 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 + 62 * 2Answer: 6

    2. 90 / 9 * 2 + 42Answer: 22

    3. ((3 / 3) * 9)6 + (4 + (2 * 2))Answer: 11

    4. (5 * 520) % 252 + 3 * 5Answer: 3

    5. 2 % 4 * 22 + 6 / 3Answer: 4

  • 5/28/2018 Programming Fb Project

    6/20

    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 stopa. \t b. \s

    4. Prints a back slash charactera. // b. \\

    5. Prints a double quotation marka. \ 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 stopb. \t b. \s

    4. Prints a back slash characterb. // b. \\

    5. Prints a double quotation markb. \ b. \

  • 5/28/2018 Programming Fb Project

    7/20

    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 valueor inform them of something.

    a. JOptionPane b. JOptionPaneWindow2. It is package where JOptionPane can be imported.

    a. Javax.swing b. javax.exe3. It is a method used to convert a string to an integer value

    a. parseDouble b. parseInt4. It is a method used to convert a string to double value.

    a. parseDouble b. parseInt5. The JOptionPane.showInputDialog will display a dialog with a message, a textfield and

    ________.

    a. OK button b. Cancel buttonSelf-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 valueor 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 valueb. 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

  • 5/28/2018 Programming Fb Project

    8/20

    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, withoutbranching off in another direction.

    a. Sequence structure b. Sequence number c. Decision Structure2. 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 Structure3. It is a less than operator.

    a. > b. b 6. b = b3. a = b 8. (b + c) == a4. (b + c) > a 9. c == c5. c != (ab) 10. b >= (ac)

  • 5/28/2018 Programming Fb Project

    9/20

    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 b 6. b = b3. a == b 8. (b + c) == a4. (b + c) > a 9. c == c5. c != (ba) 10. b >= (ca)

  • 5/28/2018 Programming Fb Project

    10/20

    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 betrue or false

    a. Short-circuit logical operator b. Logical operator c. Bitwise Logical Operator2. 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 Operator4. 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

    1. (a > b) && (a > b) 3. (c < b) && (b > a) 5. c != (ab)2. (a == b) || (b + c) < c 4. (a < b) || (b > a)

  • 5/28/2018 Programming Fb Project

    11/20

    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);

    elseSystem.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

  • 5/28/2018 Programming Fb Project

    12/20

    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 =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. >=

  • 5/28/2018 Programming Fb Project

    13/20

    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

  • 5/28/2018 Programming Fb Project

    14/20

    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 onlyb. 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;

    }

  • 5/28/2018 Programming Fb Project

    15/20

    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 radiusfor example int radius = 2. Save the class as

    Circle.java.

    Algorithm:

    1. Read in the radius2. Compute the area using the following formula:

    Area = radius x radius x 3.142

    3. Display the areaWrite 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

  • 5/28/2018 Programming Fb Project

    16/20

    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 variablesfor example, length = 20 and width = 15. Then complete and

    display the floor space in square feet. Display explanatory text with the valuefor 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

  • 5/28/2018 Programming Fb Project

    17/20

    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. Theexpected 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

  • 5/28/2018 Programming Fb Project

    18/20

    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 = (ij);

    double subtract2 = (xy);

    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 = (jy);

    double mix2 = (i * x);

    System.out.println(Variable values. . .);

    System.out.println(i = + i);

  • 5/28/2018 Programming Fb Project

    19/20

    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);

    }

    }

  • 5/28/2018 Programming Fb Project

    20/20

    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 NameLast 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