0% found this document useful (0 votes)
4 views

ComputerProgramming.grade11.Q3 w4 for Student

The document is a learning activity sheet for Grade 11 Computer Programming (Java), focusing on Java data types, operator and decision constructs, and conditional statements. It includes objectives, materials needed, and detailed instructions for creating programs using if-else and switch statements. Additionally, it provides sample code and assessment activities to reinforce learning.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

ComputerProgramming.grade11.Q3 w4 for Student

The document is a learning activity sheet for Grade 11 Computer Programming (Java), focusing on Java data types, operator and decision constructs, and conditional statements. It includes objectives, materials needed, and detailed instructions for creating programs using if-else and switch statements. Additionally, it provides sample code and assessment activities to reinforce learning.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Computer Programming (Java) – Grade 11

Learning Activity Sheets


Quarter 3

Republic Act 8293, section 176 states that: No copyright shall subsist in any
work of the Government of the Philippines. However, prior approval of the government
agency or office wherein the work is created shall be necessary for exploitation of such
work for profit. Such agency or office may, among other things, impose as a condition
the payment of royalties.
Borrowed materials (i.e., songs, stories, poems, pictures, photos, brand names,
trademarks, etc.) included in this activity sheet are owned by their respective copyright
holders. Every effort has been exerted to locate and seek permission to use these
materials from their respective copyright owners. The publisher and authors do not
represent nor claim ownership over them.

Published by the Department of Education – Schools Division of Tacloban City


Schools Division Superintendent: Mariza S. Magan
Assistant Schools Division Superintendent: Edgar Y. Tenasas

Development Team of the Activity Sheet

Writers: Maneth B. Vivero


Leah Amor V. Felicilda
Evaluator: Almer H. Bugal
Management Team:
CID Chief: Mark Chester Anthony G. Tamayo
Division EPS of LRMS: Gretel Laura M. Cadiong
Division Learning Area EPS: Evelyn P. Malubay

Department of Education - Region No. VIII – Schools Division Office of


Tacloban City
Office Address: Real St., Tacloban City
COMPUTER PROGRAMMING (JAVA) GRADE 11
LEARNING ACTIVITY SHEET
Quarter 3 Week 4

Objectives: (TLE_ICTJAVA11-12POAD-IIf-i-29)
• Demonstrate working with java data types in accordance with Java Framework;
• Demonstrate using operator and decision constructs in accordance with Java
Framework; and
• Create program that applies conditional statement (if, if-else, ladderized if, switch
case) applying API/GUI in the programs created.

Materials:
• Computer
• NetBeans IDE

Let’s kick it off!


Have you seen your grades already in the First or Second Quarter? Let’s say
your grades are like the image shown below:

Are you taking it?

If you were to create a program that computes for the General Average of 5
subjects as shown above and will give Remarks such as “With Highest Honors”, “With
High Honors”, “With Honors”, “Passed”, or “Failed”, how will you do it?

7|Q3 W4
Let’s ponder:
o How to work with Java data types?
o How to use operator and decision constructs in Java?
o How to apply conditional statement (if, if-else, ladderized if, switch case)
using API/GUI in Java?

Here’s how it is!


Java Data Types

As explained in the previous lessons, a variable in Java must be a specified data type. You
must know what data types to use when you start coding.
Example:
int myNum = 5; // Integer (whole number)
float myFloatNum = 5.99f; // Floating point number
char myLetter = 'D’; // Character
boolean myBool = true; // Boolean
String myText = "Hello”; // String

Remember that data types are divided into two groups:

• Primitive data types - A primitive data type specifies the size and type of variable
values, and it has no additional methods. It
includes byte, short, int, long, float, double, boolean and char.
• Non-primitive data types - Non-primitive data types are called reference
types because they refer to objects. Examples of non-primitive types
are Strings, Arrays, Classes, Interface, etc. You will learn more about these in a later
lesson.
Java Decision Making

Let’s review about Java decision-making statements which allows you to make a decision,
based upon the result of a condition.

Conditional Statements in Java:

• Use if to specify a block of code to be executed, if a specified condition is true


• Use else to specify a block of code to be executed, if the same condition is false
• Use else if to specify a new condition to test, if the first condition is false
• Use switch to specify many alternative blocks of code to be executed

if Statement
Use the if statement to specify a block of JavaScript code to be executed if a condition
is true.
Syntax: if (condition) {
// block of code to be executed if the condition is
true
}

7|Q3 W4
Note: that if is in lowercase letters. Uppercase letters (If or IF) will generate a
JavaScript error.
else Statement
Use the else statement to specify a block of code to be executed if the condition is
false.
Syntax:
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}

else if Statement
Use the else if statement to specify a new condition if the first condition is false.
Syntax:

if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false and condition2 is false
}

switch Statement
Use the switch statement to select one of many code blocks to be executed.
Syntax:
Note:
switch(expression) { ✓ Java switch statements can take
case x: input only as integers or
// code block characters.
✓ The switch can only check for
break;
equality. This means that the
case y: other relational operators such
// code block as greater than are rendered
break; unusable in a case.
default: ✓ The break statement is used to
// code block stop current iteration of loop or
} end Switch-case block.

7|Q3 W4
Now do it!
ACTIVITY 3-4
Instructions: Given the project specifications below, let’s create a program design using
NetBeans IDE using (1) if-else statement AND (2) switch statement.

Project Name : ifelseActivity (This is using the if else function)


switchActivity (This is using the switch statement)
JFrame Class Name : ifelseActivity
switchActivity
Variable Name : JLabel JTextField JButton
lblTitle txtEnglish btnCompute
lblEnglish txtMath btnClear
lblMath txtScience btnExit
lblScience txtHistory
lblHistory txtTLE
lblTLE txtAverage
lblAverage txtRemarks
lblRemarks
Display Text : JLabels (see output design)
JTextFields (blank)
JButton (see output design)
Button function : btnCompute -computes for the average of the 5 grades input
btnClear -clears the JTextField
btnExit -exits the program
Output Display : txtAverage -displays the average of the 5 grades input
txtRemarks -displays the following:
With Highest Honors if Average is 98-100
With High Honors if Average is 97-95
With Honors if Average is 90-94
Passed if Average is 75-89
Failed if Average is 74 and below
7|Q3 W4
Output Submission:
Take a screenshot or picture of the following components and send to your teacher via
FB Messenger or E-Mail:
1. Form Design
2. Project Window
3. Properties for each JLabel
4. Properties for each JTextField
5. Properties for each JButton
6. Message box per JButton operation

Sample Output

if-else sample code:


private void btnComputeActionPerformed(java.awt.event.ActionEvent evt) {
double english, math, science, history, TLE, average;

english = Double.parseDouble(txtEnglish.getText());
math = Double.parseDouble(txtMath.getText());
science = Double.parseDouble(txtScience.getText());
history = Double.parseDouble(txtHistory.getText());
TLE = Double.parseDouble(txtTLE.getText());
average = (english + math + science + history + TLE) / 5;

if (average >= 98){


txtRemarks.setText("With Highest Honors");
}
else if (average >= 95){
txtRemarks.setText("With High Honors");
}
else if (average >= 90){
txtRemarks.setText("With Honors");
}
else if (average >= 75){
txtRemarks.setText("Passed");
}
else {
txtRemarks.setText("Failed");
}
txtAverage.setText(Double.toString(average));
}

7|Q3 W4
switch sample code:
private void btnComputeActionPerformed(java.awt.event.ActionEvent evt) {
double english, math, science, history, TLE, average;
int value=0;

english = Double.parseDouble(txtEnglish.getText());
math = Double.parseDouble(txtMath.getText());
science = Double.parseDouble(txtScience.getText());
history = Double.parseDouble(txtHistory.getText());
TLE = Double.parseDouble(txtTLE.getText());
average = (english + math + science + history + TLE) / 5;
value = (int)average;

switch(value){
case(100):
case(99):
case(98):
txtRemarks.setText("With Highest Honors");
break;
case(97):
case(96):
case(95):
txtRemarks.setText("With High Honors");
break;
case(94):
case(93):
case(92):
case(91):
case(90):
txtRemarks.setText("With Honors");
break;
case(89):
case(88):
case(87):
case(86):
case(85):
case(84):
case(83):
case(82):
case(81):
case(80):
case(79):
case(78):
case(77):
case(76):
case(75):
txtRemarks.setText("Passed");
break;
default:
txtRemarks.setText("Failed");
break;
}
txtAverage.setText(Double.toString(average));
}

7|Q3 W4
Ace it!
ASSESSMENT
Name: ________________________________________________ Date: _______________
Grade and Section: _____________________________________ Score: ______________

I. FILL IN THE BLANKS


Instruction: Add the correct data type for the following variables:
1. ____________ myNum = 9;
2. ____________ myFloatNum = 8.99f;
3. ____________ myLetter = 'A';
4. ____________ myBool = false;
5. ____________ myText = "Hello World";

II. PROGRAMMING

1) Print "Hello World" if x is greater than y.


int x = 50;
int y = 10;
(x y) {
System.out.println("Hello World");

2) Print "1" if x is equal to y, print "2" if x is greater than y, otherwise print "3".
int x = 50;
int y = 50;
(x y) {
System.out.println("1");
} (x > y) {
System.out.println("2");
} {
System.out.println("3");
}
3) Create a switch statement that will alert "Hello" if fruits is "banana", and
"Welcome" if fruits is "apple".
(fruits) {
"Banana":
alert("Hello")
break;
"Apple":
alert("Welcome")
break;
}

Congratulations! You made it! You just finished Module 4.


7|Q3 W4
7|Q3 W4

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy