Vous êtes sur la page 1sur 63

Republic of the Philippines

Department of Education
National Capital Region
DIVISION OF CITY SCHOOLS – MANILA
Manila Education Center Arroceros Forest Park
Antonio J. Villegas St. Ermita, Manila

PROGRAMMING
JAVA NCIII
Grade 12

Quarter 1 Week 1 Module 1


Learning Competency:

APPLYING PROGRAMMING SKILLS IN A SECOND LANGUAGE


TLE_ICTCP9-12PS-IIa-b-2
LESSON 1 - LO 2. CODE USING STANDARD ALGORITHMS:
Algorithms
Division of City Schools-Manila
DEPARTMENT OF EDUCATION
K TO 12 BASIC EDUCATION CURRICULUM JUNIOR HIGH SCHOOL
TECHNICAL LIVELIHOOD EDUCATION AND SENIOR HIGH SCHOOL -
TECHNICAL-VOCATIONAL-LIVELIHOOD TRACK INFORMATION AND
COMMUNICATIONS TECHNOLOGY –PROGRAMMING JAVA NC III

by:
GIBSON J. OLAZO
Master Teacher II
Jose Abad Santos High School
Senior High School

Before starting the module, I want you to set aside other tasks that will disturb you
while enjoying the lessons. Read the simple instructions below to successfully
enjoy the objectives of this kit. Have fun!
1. Follow carefully all the contents and instructions indicated in every page of this
module and follow the given instructions for each of the given learning outcome/s.
2. As you read, you can also do the hands-on to check if you were able to follow
the basic programming procedure.
3. Demonstrate what you have learned by doing what the Activity required you to
do so.
4. Analyze conceptually the posttest and apply what you have learned.
5. Enjoy studying!

• Expectations - These are what you will be able to know after completing
the lessons in the module.
• Pre-test - This will measure your prior knowledge and the concepts to be
mastered throughout the lesson.
• Technical terms - A word that has a specific meaning within a specific field
of expertise.
• Looking Back to your Lesson - This section will measure what learnings
and skills did you understand from the previous lesson.
• Brief Introduction- This section will give you an overview of the lesson.
• Activities - This is a set of activities you will perform with a partner.
• Remember - This section summarizes the concepts and applications of
the lessons.
• Check your Understanding- It will verify how you learned from the
lesson.
• Post-test - This will measure how much you have learned from the entire
module.
TLE_ICTCP9-12PS-IIa-b-2

At the end of the lesson, the students should be able to:


1. understand standard algorithm; and
2. code using standard algorithms.

Algorithm – the step-by-step procedure of solving a problem.

End point - the final stage of a period or process.

Outcome - the way a thing turns out; a consequence.

Starting point - a place or position where something begins; a place or position


where something begins.
What have you learned from your Grade 11 lessons in Computer Programming?
What lesson/s you love the most? and you love the least?
Multiple Choice: Choose the letter of the correct answer that referred to the
statements below on the steps in writing an algorithm.
1. To determine the outcome of your code, one must know?
A. What is the specific problem you want to solve or the task you want it to
accomplish?
B. What facts will we learn from the process?
C. What formulas are applicable to the issue at hand?
D. What will be added or no longer exist?

2. Finding your starting and ending point are crucial to listing the steps of the
process. To determine a starting point, determine the answer to these
questions, except?
A. What data/inputs are available?
B. Where is that data located?
C. What facts will we learn from the process?
D. What formulas are applicable to the issue at hand?

3. As with the starting point, you can find the end point of your algorithm by
focusing on these questions, except?
a. What facts will we learn from the process?
b. What changes from the start to the end?
c. What will be added or no longer exist?
d. How do the data values relate to each other?

4. To use a real-world example, let’s say your goal is to have lasagna for
dinner. You’ve determined that the starting point is to find a recipe, and
that the end result is that you’ll have a lasagna fully cooked and ready to
eat by 7 PM. What will you do?
a. Determine how will you accomplish each step.
b. List the steps from start to finish.
c. Find the ending point of the algorithm.
d. Determine the outcome of your code.

5. Now that you’ve written your algorithm, it’s time to evaluate the process
by?
a. Review the algorithm.
b. List the steps from start to finish.
c. Find the ending point of the algorithm.
d. Determine how will you accomplish each step.
Intelligence is one of the key characteristics which differentiate a human being
from other living creatures on the earth. Basic intelligence covers day to day
problem solving and making strategies to handle different situations which keep
arising in day to day life. One person goes Bank to withdraw money. After knowing
the balance in his account, he/she decides to withdraw the entire amount from his
account but he/she has to leave minimum balance in his account. Here deciding
about how much amount he/she may withdraw from the account is one of the
examples of the basic intelligence. During the process of solving any problem, one
tries to find the necessary steps to be taken in a sequence. In this unit, you will
develop your understanding about problem solving and approaches.
Problem solving is a part of our daily life. In computer programming, problem
solving is inevitable too and it is one of the main reasons why a program is created.
You can think of a programming algorithm as a recipe that describes the exact
steps needed for the computer to solve a problem or reach a goal. We've all seen
food recipes - they list the ingredients needed and a set of steps for how to make
the described meal. Well, an algorithm is just like that. In computer lingo, the word
for a recipe is a procedure, and the ingredients are called inputs. Your computer
looks at your procedure, follows it to the letter, and you get to see the results, which
are called outputs. A programming algorithm describes how to do something, and
your computer will do it exactly that way every time. Well, it will once you convert
your algorithm into a language it understands!
However, it's important to note that a programming algorithm is not computer
code. It's written in simple English (or whatever the programmer speaks). It doesn't
beat around the bush--it has a start, a middle, and an end. In fact, you will probably
label the first step 'start' and the last step 'end.' It includes only what you need to
carry out the task. It does not include anything unclear, often called ambiguous in
computer lingo, that someone reading it might wonder about.
In this lesson, we will learn the various concepts on how to plan a program’s
output, step by step using algorithm.

WHAT IS AN ALGORITHM?
Generally, an algorithm is a step-by-step procedure to solve problems. A guide
for isntalling new software, a manual for assembling appliances, and even recipes are
examples of an algorithm. In programming, making an algorithm is exciting, they are
expressed in a programming language or in a pseudocode.
Algorithm makes the whole procedure more efficient as well as consistent. It also
helps in identifying decision points, processes, and essential variables to solve the
problem. A programmer can also see and determine easily the errors in a particular
process using an algorithm.

STEPS IN WRITING AN ALGORITHM IN PROGRAMMING


1. Determine the outcome of your code. What is the specific problem you want
to solve or the task you want it to accomplish?
2. Decide on a starting point. Finding your starting and ending point are crucial
to listing the steps of the process. To determine a starting point, determine the
answers to these questions:
• What data/inputs are available?
• Where is that data located?
• What formulas are applicable to the issue at hand?
• What are the rules to working with the available data?
• How do the data values relate to each other?
3. Find the ending point of the algorithm. As with the starting point, you can
find the end point of your algorithm by focusing on these questions:
• What facts will we learn from the process?
• What changes from the start to the end?
• What will be added or no longer exist?
4. List the steps from start to finish. Start with broad steps. To use a real-world
example, let's say your goal is to have lasagna for dinner. You've determined
that the starting point is to find a recipe, and that the end result is that you'll
have a lasagna fully cooked and ready to eat by 7 PM.
5. Determine how you will accomplish each step. Now that you have a step-
by-step outline, it's time to think about how you might code each step.
6. Review the algorithm. Now that you've written your algorithm, it's time to
evaluate the process. Your algorithm is designed to accomplish something
specific, and you'll need it to start writing your program.

PROGRAMMING ALGORITHM
You probably wish you could see an example, right? So, what exactly does an
algorithm in programming look like? Well, asking a user for an email address is
probably one of the most common tasks a web-based program might need to do, so
that is what we will use here for an example. An algorithm can be written as a list of
steps using text. We will make one of each which you will see here:
Wasn't that easy? Notice how the top of our example is just a numbered list of
steps using plain English, stating exactly what we want the procedure to do (no more,
no less). That's a nice thing here, because in one of our steps (step 7) a decision must
be made and, depending on the result of that decision, our steps may not go in order
from start to end.
Let's take a quick run through our little recipe:
1. Step 1 is really just a reminder that this is a procedure with a beginning and an end.
2. In step 2, we make a place in the computer to store what the user types in, also
called a variable
3. In step 3, we clear this variable because we might need to use it again and don't
want the old contents mixed in with the new.
4. In step 4, we prompt the user for an email address
5. In step 5, we stick it in our nifty variable.
6. In step 6, we tell our computer to take a close look at this email address-- is it
really an email address?

ALGORITHM EXAMPLES

EXAMPLE 1: Write an algorithm to convert the length in feet to centimeter

.
Algorithm

Step 1: Input Lft


Step 2: Lcm=Lft x 30
Step 3: Print Lcm

EXAMPLE 2: Write an algorithm that will read the two sides of a rectangle and
calculate its area.

Algorithm
Step 1: Input W,L
Step 2: A=LxW
Step 3: Print A
1. Write an algorithm to print 1 to 20.

2. Write an algorithm to Convert temperature: Fahrenheit to Celsius. C=5/9*(F-32)

3. Write an algorithm that will calculate the roots of a quadratic equation


ax2+bx+c=0. Hint: d=sqrt(b2-4ac), and the roots are: x1=(-b+d)/2a and x2=(-b-
d)/2a

4. Write an algorithm that reads two values, determine the largest value and prints
the largest value with an identifying message.
An algorithm shows
you every step of
reaching the final
solution. An
algorithm uses
mainly words to
describe the steps to
make the process
understandable.

Direction: Write your understanding about the following:

How can an algorithm help in making an efficient program?


Multiple Choice: Choose the letter of the correct answer that referred to the
statements below on the steps in writing an algorithm.
1. To determine the outcome of your code, one must know?
A. What is the specific problem you want to solve or the task you want it to
accomplish?
B. What facts will we learn from the process?
C. What formulas are applicable to the issue at hand?
D. What will be added or no longer exist?

2. Finding your starting and ending point are crucial to listing the steps of the
process. To determine a starting point, determine the answer to these
questions, except?
A. What data/inputs are available?
B. Where is that data located?
C. What facts will we learn from the process?
D. What formulas are applicable to the issue at hand?
E.
3. As with the starting point, you can find the end point of your algorithm by
focusing on these questions, except?
A. What facts will we learn from the process?
B. What changes from the start to the end?
C. What will be added or no longer exist?
D. How do the data values relate to each other?

4. To use a real-world example, let’s say your goal is to have lasagna for
dinner. You’ve determined that the starting point is to find a recipe, and
that the end result is that you’ll have a lasagna fully cooked and ready to
eat by 7 PM. What will you do?
A. Determine how will you accomplish each step.
B. List the steps from start to finish.
C. Find the ending point of the algorithm.
D. Determine the outcome of your code.

5. Now that you’ve written your algorithm, it’s time to evaluate the process
by?
A. Review the algorithm.
B. List the steps from start to finish.
C. Find the ending point of the algorithm.
D. Determine how will you accomplish each step.
LESSON 1 - Let’s do the checking

Answer Key

1 Algorithm: 3 Step 1: Input a,b,c


Step 2: d=sqrt(bxb-4xaxc)
Step 1: Initialize X as 0, Step 3: x1=(-b+d)/(2xa)
Step 2: Increment X by 1,
Step 4: x2=(-b-d)/(2xa)
Step 3: Print X,
Step 4: If X is less than 20 then Step 5: Print x1,x2
go back to step 2.

2 Algorithm: 4 Step 1: Input VALUE1, VALUE2


Step 2: if (VALUE1>VALUE2) then
Step 1: Read temperature in MAX=VALUE1
Fahrenheit else
Step 2: Calculate temperature MAX=VALUE2
with formula C=5/9*(F-32) Step 3: Print “The largest value
Step 3: Print C is”,MAX

1. How can an algorithm help in making an efficient program?


Answer: An algorithm makes the whole procedure more efficient as well
consistent. It helps in identifying decision points, processes, and essential
variables to solve the problem. A programmer can also see the errors in a
particular process using an algorithm.
Innovative Training Works, Inc. “Computer Programming Volume I” Technical
Vocational Livelihood K to 12 First Edition
https://faradars.org/wp-content/uploads/2015/07/Algorithm-and-Flow-Chart.pdf
https://sielearning.tafensw.edu.au/toolboxes/Database_Administration/software/cont
ent/programmingconstructs/control_structures.htm
https://study.com/academy/lesson/what-is-an-algorithm-in-programming-definition-
examples-analysis.html

Acknowledgements
Writer: Gibson J. Olazo- MTII
Editors: Ariel Tosio-EPS, Vladimir B. Paraiso-Assistant Principal
Reviewers: Robert P. Velasquez – Principal, Perlito Malaya HT-VI,
Anthony Ducta HT-III
Management Team: Maria Magdalena M. Lim-Schools Division
Superintendent-Manila, Aida H. Rondilla-Chief Education Supervisor Lucky
S. Carpio-EPS and Lady Hannah C Gillo, Librarian II-LRMS
Republic of the Philippines
Department of Education
National Capital Region
DIVISION OF CITY SCHOOLS – MANILA
Manila Education Center Arroceros Forest Park
Antonio J. Villegas St. Ermita, Manila

PROGRAMMING
JAVA NCIII
Grade 12

Quarter 1 Week 2 Module 2


Learning Competency:

APPLYING PROGRAMMING SKILLS IN A SECOND LANGUAGE


TLE_ICTCP9-12PS-IIa-b-2
LESSON 2 - LO 2. CODE USING STANDARD ALGORITHMS:
Pseudocodes
Division of City Schools-Manila
DEPARTMENT OF EDUCATION
K TO 12 BASIC EDUCATION CURRICULUM JUNIOR HIGH SCHOOL
TECHNICAL LIVELIHOOD EDUCATION AND SENIOR HIGH SCHOOL -
TECHNICAL-VOCATIONAL-LIVELIHOOD TRACK INFORMATION AND
COMMUNICATIONS TECHNOLOGY –PROGRAMMING JAVA NC III

by:
GIBSON J. OLAZO
Master Teacher II
Jose Abad Santos High School
Senior High School

Before starting the module, I want you to set aside other tasks that will disturb you
while enjoying the lessons. Read the simple instructions below to successfully
enjoy the objectives of this kit. Have fun!
1. Follow carefully all the contents and instructions indicated in every page of this
module and follow the given instructions for each of the given learning outcome/s.
2. As you read, you can also do the hands-on to check if you were able to follow
the basic programming procedure.
3. Demonstrate what you have learned by doing what the Activity required you to
do so.
4. Analyze conceptually the posttest and apply what you have learned.
5. Enjoy studying!

• Expectations - These are what you will be able to know after completing
the lessons in the module.
• Pre-test - This will measure your prior knowledge and the concepts to be
mastered throughout the lesson.
• Technical terms - A word that has a specific meaning within a specific field
of expertise.
• Looking Back to your Lesson - This section will measure what learnings
and skills did you understand from the previous lesson.
• Brief Introduction- This section will give you an overview of the lesson.
• Activities - This is a set of activities you will perform with a partner.
• Remember - This section summarizes the concepts and applications of
the lessons.
• Check your Understanding- It will verify how you learned from the
lesson.
• Post-test - This will measure how much you have learned from the entire
module.
TLE_ICTCP9-12PS-IIa-b-2

At the end of the lesson, the students should be able to:


1. use pseudocode in problem solving; and
2. code using pseudocodes.

Pseudocode – use to describe processes using natural language.

Syntax - is the set of rules that defines the combinations of symbols that are
considered to be a correctly structured document or fragment in that language.

Task - is a basic unit of programming that an operating system control. Depending


on how the operating system defines a task in its design, this unit
of programming may be an entire program or each successive invocation of a
program.

Variable - is a value that can change, depending on conditions or on information


passed to the program. Typically, a program consists of instruction s that tell
the computer what to do and data that the program uses when it is running.
To recap, algorithm is a step-by-step procedure of solving a problem. Base from
the previous lesson, give your understanding of the Steps in Writing an Algorithm
in Programming. The steps in writing an algorithm are the following:

• Determine the outcome of your code

• Decide on a starting point

• Find the ending point of the algorithm

• List the steps from start to finish

• Determine how you will accomplish each step

• Review the algorithm


Multiple Choice: Choose the letter of the correct answer that referred to the
statements below.
1. The aim of pseudocode is to make programming easier by using symbols.
A. Yes
B. No

2. Is a way of expressing an algorithm without conforming to specific syntactic


rules.
a. Pseudocode
b. Data Type
c. Algorithm
d. Flowchart

3. It is a set of rules on how to use and organize statements in a programming


language.
a. Variable
b. Syntax
c. Language
d. Code

4. Before you write once piece of computer code, you should?


a. Conform to specific syntax
b. Create a variable
c. Know what the program is suppose to do
d. Describe an algorithm

5. In writing basc pseudocode is not like writing an actual coding language. It


cannot be compiled or run like a regular program. It can be written on?
a. How you want
b. Computer
c. Peripheral input and output devices
d. Accepted notations
Although showing learners direct translations between block-based and text-
based languages can be useful, this is not always possible. For instance, most
block-based languages cannot communicate with a computer’s operating system,
so file handling isn’t really possible, nor are communication between one computer
and another, or access to peripheral input and output devices.

Pseudocode is a way of expressing an algorithm without conforming to


specific syntactic rules. By learning to read and write pseudocode, learners can
more easily communicate ideas and concepts to other programmers, even though
they may be using completely different languages. What’s more, algorithmic
solutions to many problems are often provided, meaning an ability to translate
between pseudocode and a given programming language is a valuable skill.

There is no such thing as correct pseudocode, although there are a few


generally accepted notations that are widely understood by programmers (e.g. x
<-- 10 to create a variable called x with a value of 10), no matter which language
they use.

It always leads to a solution and tries to be the most efficient solution we can
think up. It's often a good idea to number the steps, but you don't have to. Instead
of numbered steps, some folks use indentation and write in pseudocode, which is
a semi-programming language used to describe the steps in an algorithm. But, we
won't use that here since simplicity is the main thing.

Before you write one piece of computer code, you have to know what the
program is supposed to do. Before you write one line of code in any language, it is
a good idea to write it in a simple way first to ensure you have included everything
you need. The best way to set this up is by using pseudocode.

WHAT IS A PSEUDOCODE?
A pseudocode is a description of an algorithm or a computer program using
natural language. Because the aim of pseudocode is to make reading program easier,
some codes that are not essential for human understanding are omitted. This
language is commonly used in planning out structure of a program or a system, like
the blueprint for creating a house or a building.
A pseudocode is a simple way of writing programming code in English.
Pseudocode is not actual programming language. It uses short phrases to write code
for programs before you actually create it in a specific language. Once you know what
the program is about and how it will function, then you can use pseudocode to create
statements to achieve the required results for your program.

A pseudocode makes creating programs easier. Programs can be complex and


long; preparation is the key. It is challenging to find a mistake without understanding
the complete flow of a program. That is where pseudocode becomes more appealing.

To use pseudocode, all you do is write what you want your program to say in
English. Pseudocode allows you to translate your statements into any language
because there are no special commands and it is not standardized. Writing out
programs before you code can enable you to better organize and see where you may
have left out needed parts in your programs. All you have to do is write it out in your
own words in short statements. Let's look at some examples.

EXAMPLES OF PSEUDOCODE
1. Create a program to add 2 numbers together and then display the result.

• Start Program
• Enter two numbers, A, B
• Add the numbers together
• Print Sum
• End Program
2. Compute the area of a rectangle.
• Get the length, l, and width, w
• Compute the area = l*w
• Display the area
3. Compute the perimeter of a rectangle.
• Enter length, l
• Enter width, w
• Compute Perimeter = 2*l + 2*w
• Display Perimeter of a rectangle

Remember, writing basic pseudocode is not like writing an actual coding language.
It cannot be compiled or run like a regular program. Pseudocode can be written how
you want. But some companies use specific pseudocode syntax to keep everyone in
the company on the same page. Syntax is a set of rules on how to use and organize
statements in a programming language. By adhering to specific syntax, everyone in
the company can read and understand the flow of a program. This becomes cost
effective and there is less time spent finding and correcting errors.
PRACTICE PSEUDOCODE
Write your own pseudocode program to accomplish a simple task.

Step 1: Choose a Task

• Choose a simple task to accomplish with your program. You want this to be
complex enough to require multiple steps while still being relatively simple to
accomplish. Some ideas are:
o Walk across a room
o Find the difference between two numbers
o Determine if a number is even or odd

Step 2: Write the Pseudocode

• When writing the code, remember the four guidelines:


o The language should be universal.
o Limit each line to one task/action.
o Capitalize all key words (even if not at the beginning of a sentence).
o Indent loops (like if/then statements)
• Don't forget to start with 'Start Program' and end with 'End Program'.

Step 3: Test Your Code

• After you have written your pseudocode program, put it aside for at least 1 day
(more is better).
o The act of resting the ideas you have written will help you to edit your
work more accurately later.
• When you are ready, try to follow your program exactly.
o Did you accomplish the task?
o If you were not successful in completing the task, trouble shoot your
program to find out why.
 You have likely left out a small step that seemed logical to you as
you were writing the code, but needed to be spelled out to get an
accurate program.
• If you needed to do any trouble shooting, wait another day or two before testing
your code again.
o Continue to test until you successfully include all steps required to
complete your task.
• Alternatively, you can ask someone to attempt to complete your task following
your pseudocode precisely.
o Troubleshoot as described above.
1. Write a pseudocode to convert the length in feet to centimeter.

2. Write pseudocode that will read the two sides of a rectangle and calculate its
area.

3. Write a pseudocode that will calculate the roots of a quadratic equation


ax2+bx+c=0. Hint: d=sqrt(b2-4ac), and the roots are: x1=(-b+d)/2a and x2=(-b-
d)/2a
Creating a pseudocode for a
program makes the task easier
because it foresees processes
and points of decision.
Pseudocodes is ideal for
explaining the processes of the
program to be created.

Direction: Write your understanding about the following:

Why do you think a programmer must create a pseudocode?


Multiple Choice: Choose the letter of the correct answer that referred to the
statements below.
1. The aim of pseudocode is to make programming easier by using symbols.
A. Yes
B. No

2. Is a way of expressing an algorithm without conforming to specific syntactic


rules.
A. Pseudocode
B. Data Type
C. Algorithm
D. Flowchart

3. It is a set of rules on how to use and organize statements in a programming


language.
A. Variable
B. Syntax
C. Language
D. Code

4. Before you write once piece of computer code, you should?


A. Conform to specific syntax
B. Create a variable
C. Know what the program is suppose to do
D. Describe an algorithm

5. In writing basc pseudocode is not like writing an actual coding language. It


cannot be compiled or run like a regular program. It can be written on?
A. How you want
B. Computer
C. Peripheral input and output devices
D. Accepted notations
LESSON 2 - Let’s do the checking

Answer Key

STEPS IN WRITING AN ALGORITHM IN PROGRAMMING


• Determine the outcome of your code
Answer: Know what is the specific problem you want to solve or the task you
want to accomplish. What data/inputs are available? Where is that data
located? What formulas are applicable to the issue at hand? What are the rules
to working with the available data? How do the data values relate to each other?
• Decide on a starting point
Answer: Find your starting and ending point are crucial to listing the steps of
the process. To determine a starting point, determine the answers to these
questions: What data/inputs are available? Where is that data located? What
formulas are applicable to the issue at hand? What are the rules to working with
the available data? How do the data values relate to each other?
• Find the ending point of the algorithm
Answer: As with the starting point, you can find the end point of your algorithm
by focusing on these questions: What facts will we learn from the process? What
changes from the start to the end? What will be added or no longer exist?
• List the steps from start to finish
Answer: Start with broad steps. To use a real-world example, let's say your
goal is to have lasagna for dinner. You've determined that the starting point is
to find a recipe, and that the end result is that you'll have a lasagna fully cooked
and ready to eat by 7 PM.
• Determine how you will accomplish each step
Answer: Now that you have a step-by-step outline, it's time to think about how
you might code each step.
• Review the algorithm
Answer: Now that you've written your algorithm, it's time to evaluate the
process. Your algorithm is designed to accomplish something specific, and
you'll need it to start writing your program.

1 Pseudocode Pseudocode
3
• Input the length in feet (Lft) • Input the coefficients (a,b,c) of
• Calculate the length in cm the quadratic equation
(Lcm) by multiplying Lft with • Calculate d
30 • Calculate x1
• Print length in cm (Lcm) • Calculate x2
• Print x1 and x2

2 Pseudocode

• Input the width (W) and length


(L) of a rectangle
• Calculate the area (A) by
multiplying L with W
• Print A

Answer: Why do you think a programmer must create a pseudocode?


Answer: The aim for pseudocode is to make reading program easier, some
codes that are not essential for human understanding are omitted. With the
help of pseudocode, one can easily understand it without having to know
the technicalities.
Innovative Training Works, Inc. “Computer Programming Volume I” Technical
Vocational Livelihood K to 12 First Edition
https://techterms.com/definition/algorithm#:~:text=Algorithm,to%20perform%20a%20
specific%20task.&text=In%20computer%20programming%2C%20algorithms%20are
,referenced%20by%20a%20larger%20program.
https://study.com/academy/lesson/pseudocode-definition-examples-quiz.html

Acknowledgements
Writer: Gibson J. Olazo- MTII
Editors: Ariel Tosio-EPS, Vladimir B. Paraiso-Assistant Principal
Reviewers: Robert P. Velasquez – Principal, Perlito Malaya HT-VI,
Anthony Ducta HT-III
Management Team: Maria Magdalena M. Lim-Schools Division
Superintendent-Manila, Aida H. Rondilla-Chief Education Supervisor Lucky
S. Carpio-EPS and Lady Hannah C Gillo, Librarian II-LRMS
Republic of the Philippines
Department of Education
National Capital Region
DIVISION OF CITY SCHOOLS – MANILA
Manila Education Center Arroceros Forest Park
Antonio J. Villegas St. Ermita, Manila

PROGRAMMING
JAVA NCIII
Grade 12

Quarter 1 Week 3 Module 3


Learning Competency:

APPLYING PROGRAMMING SKILLS IN A SECOND LANGUAGE


TLE_ICTCP9-12PS-IIa-b-2
LESSON 3 - LO 2. CODE USING STANDARD ALGORITHMS:
Flowcharts
Division of City Schools-Manila
DEPARTMENT OF EDUCATION
K TO 12 BASIC EDUCATION CURRICULUM JUNIOR HIGH SCHOOL
TECHNICAL LIVELIHOOD EDUCATION AND SENIOR HIGH SCHOOL -
TECHNICAL-VOCATIONAL-LIVELIHOOD TRACK INFORMATION AND
COMMUNICATIONS TECHNOLOGY –PROGRAMMING JAVA NC III

by:
GIBSON J. OLAZO
Master Teacher II
Jose Abad Santos High School
Senior High School

Before starting the module, I want you to set aside other tasks that will disturb you
while enjoying the lessons. Read the simple instructions below to successfully
enjoy the objectives of this kit. Have fun!
1. Follow carefully all the contents and instructions indicated in every page of this
module and follow the given instructions for each of the given learning outcome/s.
2. As you read, you can also do the hands-on to check if you were able to follow
the basic programming procedure.
3. Demonstrate what you have learned by doing what the Activity required you to
do so.
4. Analyze conceptually the posttest and apply what you have learned.
5. Enjoy studying!

• Expectations - These are what you will be able to know after completing
the lessons in the module.
• Pre-test - This will measure your prior knowledge and the concepts to be
mastered throughout the lesson.
• Technical terms - A word that has a specific meaning within a specific field
of expertise.
• Looking Back to your Lesson - This section will measure what learnings
and skills did you understand from the previous lesson.
• Brief Introduction- This section will give you an overview of the lesson.
• Activities - This is a set of activities you will perform with a partner.
• Remember - This section summarizes the concepts and applications of
the lessons.
• Check your Understanding- It will verify how you learned from the
lesson.
• Post-test - This will measure how much you have learned from the entire
module.
TLE_ICTCP9-12PS-IIa-b-2

At the end of the lesson, the students should be able to:


1. use flowchart in problem solving; and
2. draw program using flowchart.

Flowchart – is a graphical representation of an algorithm. Programmers often use


it as a program-planning tool to solve a problem. It makes use of symbols which
are connected among them to indicate the flow of information and processing.

Flowchart symbols - are specific shapes used to create a visual representation


of a program. They can be as simple as three separate functions with one line
connecting them, or they can be an entire web of functions

Graphical Representation - is another way of analyzing numerical data. A


flowchart is a graphical representation of an algorithm.
To recap, pseudocode describes processes using natural language. Write the
pseudocode of the following problems.

1. A Teacher would like to create a program that will classify if a student’s


grade must be marked Passed or Failed. Any grades lower than 60 is
considered failed. From this given information, please provide the
necessary pseudocode.

2. Convert the length in feet to centimeter.


Multiple Choice: Choose the letter of the correct answer that referred to the
statements below.
1. It is one of the key characteristics which differentiate a human being from
other living creatures on the earth.
a. Kindness d. Beauty
b. Character e. Loyalty
c. Intelligence

2. It indicates any type of internal operation inside the processor or memory.


a. Connector d. Process
b. Terminal e. Decision
c. Input/Output

3. Allows the flowchart to be drawn without interesting lines or without a reverse


flow.
a. Connector d. Decision
b. Flow lines e. Process
c. Terminal

4. Show direction of the flow.


a. Input/Output d. Terminal
b. Decision e. Flow lines
c. Connector

5. Use for any I/O operation. Indicates that the computer is to obtain data or
output results.
a. Input/Output d. Flow lines
b. Off page connector e. Decision
c. On page connector
Flowcharts to document business processes came into use in the 1920s and
‘30s. In 1921, industrial engineers Frank and Lillian Gilbreth introduced the “Flow
Process Chart” to the American Society of Mechanical Engineers (ASME). In the
early 1930s, industrial engineer Allan H. Morgensen used Gilbreth’s tools to
present conferences on making work more efficient to business people at his
company. In the 1940s, two Morgensen students, Art Spinanger and Ben S.
Graham, spread the methods more widely. Spinanger introduced the work
simplification methods to Procter and Gamble. Graham, a director at Standard
Register Industrial, adapted flow process charts to information processing. In 1947,
ASME adopted a symbol system for Flow Process Charts, derived from the
Gilbreths’ original work.
Also in the late ‘40s, Herman Goldstine and John Van Neumann used
flowcharts to develop computer programs, and diagramming soon became
increasingly popular for computer programs and algorithms of all kinds. Flowcharts
are still used for programming today, although pseudocode, a combination of words
and coding language meant for human reading, is often used to depict deeper
levels of detail and get closer to a final product.
In Japan, Kaoru Ishikawa (1915-1989), a key figure in quality initiatives in
manufacturing, named flowcharts as one of the key tools of quality control, along
with complementary tools such as the Histogram, Check Sheet and Cause-and-
Effect Diagram, now often called the Ishikawa Diagram.
For years, flowcharts were used to map out programs before writing one line of
code in a language. However, they were difficult to modify and with the
advancement of programming languages, it was difficult to display all parts of a
program with a flowchart.
A flowchart is a type of diagram that represents an algorithm, workflow or
process. The flowchart shows the steps as boxes of various kinds, and their order
by connecting the boxes with arrows. This diagrammatic representation illustrates
a solution model to a given problem. Flowcharts are used in analyzing, designing,
documenting or managing a process or program in various fields.
WHAT IS A FLOWCHART?
Like pseudocodes, flowchart is also a description of an algorithm or a computer
program. It also serves as the programs blueprint during the Program Development
Process. The difference is that flowchart is a graphical representation of it. Flowcharts
help in the effective analysis of the problem as well as the application’s or program’s
maintenance, thus providing ease in identifying potential improvements of the system
or program.
It consists of 8 standard symbols namely: Terminal, Preparation/Initialization,
Process, Decision, On-page Connector, Off-page Connector, Input/Output operation,
and Flow lines (arrow).

FLOWCHART SYMBOLS

Symbol Name Description


Terminal Begin and end of the
program.

Preparation or Variable declaration part


Initialization and initial values.

Process Formula and defined


process are place.

Input / Output All display on the screen


and input from
keyboard.

Decision All conditions, logical


expressions

Flow Lines Connects all other


symbols from the
flowchart.

On-page Connector Connector to continuation


of flowchart on the same
page.
Off-page Connector Connector to continuation
of flowchart on the
separate page.

A FLOWCHART
• shows logic of an algorithm
• emphasizes individual steps and their interconnections
• e.g. control flow from one action to the next

GENERAL RULES FOR FLOWCHARTING


1. All boxes of the flowchart are connected with flow lines.
2. Flowchart symbols have an entry point on the top of the symbol with no other
entry points. The exit point for all flowchart symbols is on the bottom except for
the Decision symbol.
3. The Decision symbol has two exit points; these can be on the sides or the
bottom and one side.
4. Generally, a flowchart will flow from top to bottom. However, an upward flow
can be shown as long as it does not exceed 3 symbols.
5. Connectors are used to connect breaks in the flowchart. Examples are:
• From one page to another page.
• From the bottom of the page to the top of the same page.
• An upward flow of more than 3 symbols
6. Subroutines and Interrupt programs have their own and independent
flowcharts.
7. All flow charts start with a Terminal or Predefined Process (for interrupt
programs or subroutines) symbol.
8. All flowcharts end with a terminal or a contentious loop.

EXAMPLES OF FLOWCHART

1. Determine whether the temperature if below freezing or above freezing point.

Start

Read
Temperatur

N
Print “Above
Temperature<=0
Freezing”

Y
A
Print “Below
Freezing”

End
2. Draw a flowchart to convert the length in feet to centimeter

Flowchart

3. Draw a flowchart that will read the two sides of a rectangle and calculate its
area.
Flowchart
1. Draw a flowchart to find the area of a circle: Area=3.14*r*r

2. Draw a flowchart which gets two number and prints sum of their value.

3. Draw a flowchart to find the greater number between two numbers.


4. Draw a flowchart to find the sum of the first 50 natural numbers.

5. Write an algorithm and draw flowchart to print 1 to 20.

6. Write an algorithm and draw a flowchart to Convert temperature: Fahrenheit to


Celsius. C=5/9*(F-32)

7. Draw a flowchart that reads two values, determine the largest value and prints
the largest value with an identifying message.
8.Draw a flowchart that will calculate the roots of a quadratic equation ax2+bx+c=0.
Hint: d=sqrt(b2-4ac), and the roots are: x1=(-b+d)/2a and x2=(-b-d)/2a

. A flowchart shows
you how to carry out
the process by
connecting each step.
A flowchart uses the
help of symbols,
shapes and arrows to
make the process
Direction: Write your understanding about the following:

Flowchart consist of 8 standard symbols. Draw and name the 8 standard symbols.
Multiple Choice: Choose the letter of the correct answer that referred to the
statements below.
1. It is one of the key characteristics which differentiate a human being from
other living creatures on the earth.
A. Kindness D. Beauty
B. Character E. Loyalty
C. Intelligence
2. It indicates any type of internal operation inside the processor or memory.
A. Connector D. Process
B. Terminal E. Decision
C. Input/Output
3. Allows the flowchart to be drawn without interesting lines or without a reverse
flow.
A. Connector D. Decision
B. Flow lines E. Process
C. Terminal
4. Show direction of the flow.
A. Input/Output D. Terminal
B. Decision E. Flow lines
C. Connector
5. Use for any I/O operation. Indicates that the computer is to obtain data or
output results.
A. Input/Output D. Flow lines
B. Off page connector E. Decision
C. On page connector
LESSON 3 - Let’s do the checking

Answer Key

1.C
2.D
3.A
4.E
5.A

1. A Teacher would like to create a program that will classify if a student’s


grade must be marked Passed or Failed. Any grades lower than 60 is
considered failed. From this given information, please provide the necessary
pseudocode.
Pseudocode
Answer:
• Input the Student’s Grade
• Read Student’s Grade
• If student’s grade >=60 Print
Passed, else Print Failed

2. Convert the length in feet to centimeter

Answer:
Pseudocode

• Input the length in feet (Lft)


• Calculate the length in cm
(Lcm) by multiplying Lft with
30
• Print length in cm (Lcm)

Pseudocode

If student’s grade is greater than or equal to 60


Print “Passed”
else
Print “Failed”
4
1

5
2

6
7
8 Flowchart

Flowchart consist of 8 standard symbols. Draw and name the 8 standard symbols

Answer:
Innovative Training Works, Inc. “Computer Programming Volume I” Technical
Vocational Livelihood K to 12 First Edition
https://uomustansiriyah.edu.iq/media/lectures/5/5_2016_03_22!07_06_46_PM.pdf
https://www.edrawsoft.com/explain-algorithm-flowchart.html
https://www.lucidchart.com/pages/what-is-a-flowchart-tutorial

Acknowledgements
Writer: Gibson J. Olazo- MTII
Editors: Ariel Tosio-EPS, Vladimir B. Paraiso-Assistant Principal
Reviewers: Robert P. Velasquez – Principal, Perlito Malaya HT-VI,
Anthony Ducta HT-III
Management Team: Maria Magdalena M. Lim-Schools Division
Superintendent-Manila, Aida H. Rondilla-Chief Education Supervisor Lucky
S. Carpio-EPS and Lady Hannah C Gillo, Librarian II-LRMS
Republic of the Philippines
Department of Education
National Capital Region
DIVISION OF CITY SCHOOLS – MANILA
Manila Education Center Arroceros Forest Park
Antonio J. Villegas St. Ermita, Manila

PROGRAMMING
JAVA NCIII
Grade 12

Quarter 1 Week 4 Module 4


Learning Competency:

APPLYING PROGRAMMING SKILLS IN A SECOND LANGUAGE


TLE_ICTCP9-12PS-IIa-b-2
LESSON 4 - LO 2. CODE USING STANDARD ALGORITHMS:
Data Types
Division of City Schools-Manila
DEPARTMENT OF EDUCATION
K TO 12 BASIC EDUCATION CURRICULUM JUNIOR HIGH SCHOOL
TECHNICAL LIVELIHOOD EDUCATION AND SENIOR HIGH SCHOOL -
TECHNICAL-VOCATIONAL-LIVELIHOOD TRACK INFORMATION AND
COMMUNICATIONS TECHNOLOGY –PROGRAMMING JAVA NC III

by:
GIBSON J. OLAZO
Master Teacher II
Jose Abad Santos High School
Senior High School
Before starting the module, I want you to set aside other tasks that will disturb you
while enjoying the lessons. Read the simple instructions below to successfully
enjoy the objectives of this kit. Have fun!
1. Follow carefully all the contents and instructions indicated in every page of this
module and follow the given instructions for each of the given learning outcome/s.
2. As you read, you can also do the hands-on to check if you were able to follow
the basic programming procedure.
3. Demonstrate what you have learned by doing what the Activity required you to
do so.
4. Analyze conceptually the posttest and apply what you have learned.
5. Enjoy studying!

• Expectations - These are what you will be able to know after completing
the lessons in the module.
• Pre-test - This will measure your prior knowledge and the concepts to be
mastered throughout the lesson.
• Technical terms - A word that has a specific meaning within a specific field
of expertise.
• Looking Back to your Lesson - This section will measure what learnings
and skills did you understand from the previous lesson.
• Brief Introduction- This section will give you an overview of the lesson.
• Activities - This is a set of activities you will perform with a partner.
• Remember - This section summarizes the concepts and applications of
the lessons.
• Check your Understanding- It will verify how you learned from the
lesson.
• Post-test - This will measure how much you have learned from the entire
module.
TLE_ICTCP9-12PS-IIa-b-2

At the end of the lesson, the students should be able to:


1. identify variables; and
2. know its corresponding data type.

Data Type – description of a specific data that can be stored in a variable, the
amount memory the item occupies, and the operations it can be performed.

Logical Operation - an operation that acts on binary numbers to produce a result


according to the laws of Boolean logic

Rational Operation – is nothing more than a fraction in which the numerator and/or
the denominator are polynomials.
To recap, flowchart creates meaningful representation of the program’s
processes. Identify the names of the 8 symbols and its functions.

2 3

4 5

6
7

8
When creating a variable, we also need to declare the data type it contains.
This is because the program will use different types of data in different ways.
Programming languages define data types differently. For example, almost all
languages differentiate between ‘integers’ (or whole numbers, eg 12), ‘non-
integers’ (numbers with decimals, eg 0.24), and ‘characters’ (letters of the alphabet
or words).
In computer science and computer programming, a data type or simply type is
an attribute of data which tells the compiler or interpreter how the programmer
intends to use the data. This data type defines the operations that can be done on
the data, the meaning of the data, and the way values of that type can be stored.
A data type, in programming, is a classification that specifies which type of
value a variable has and what type of mathematical, relational or logical operations
can be applied to it without causing an error. A string, for example, is a data type
that is used to classify text and an integer is a data type used to classify whole
numbers.

WHAT IS A DATA TYPE?


A data type is a description of a specific data that can be stored in a variable,
the amount of memory the item occupies, and the operations it can be performed.
Boolean • can only contain two values, True or e.g., True or False,
False, Yes or No or On and Off is also
boolean one = true
possible.
• represents one bit of information.
• representing logical values.
• used for simple flags that track
true/false conditions. Default value is
false.
Char • used to hold a single character, e.g., a
specifically a single Unicode
char letterA = 'A'
character. Unicode is a 16-bit
character which represents all the 97 (in ASCII, 97 is a lower
letters and symbols of all major case 'a')
languages existing.
• encode text numerically
• used to store any character
• single 16-bit Unicode character
Date • data type that holds date values, e.g., 03/01/2016
time values, or the combination of
both.
Float • floating point - number with a decimal e.g., 1.234,
point
float f1 = 234.5f
• used for precise values such as
currency. Default value is 0.0f.
• single precision 32-bit IEEE 754
floating point
Integer • holds only whole number, but loads e.g., 7, 12, 999, 1234, int
fast compare to other data types. a = 100000,
• generally used as the default data
int b = -200000
type for integral values unless there is
a concern about memory. Default
value is 0.
• 32-bit signed two’s complement
integer
String • data type used to hold set or multiple e.g., abcd, hello world,
of characters, like words and Alice, Bob123
sentences.
Void • data type that has no values or e.g., no data, void, N/A
operators and is used to represent
nothing
EXAMPLES OF DATA TYPE

1. A Teacher would like to create a program that will classify if a student’s grade must
be marked Passed or Failed. Any grades lower than 60 is considered failed. From this
given information, please provide the necessary data type.
Answer: Data Type
Float
The float data type is the best data type for this variable since a student’s grade is
usually a real number (numbers with decimal places).

2. Identify the data type to convert the length in feet to centimeter.

. Data Type
Float

Float because the possible answer is a number with a decimal point.

3. Identify the data type that will read the two sides of a rectangle and calculate its
area.
Data Type
Integer

Integer because the possible answer is a whole number.

4.Identify what data type that will calculate the roots of a quadratic equation
ax2+bx+c=0. Hint: d=sqrt(b2-4ac), and the roots are: x1=(-b+d)/2a and x2=(-b-d)/2a

Data Type
Void

Void because it has no values and is used to represent nothing.

5.Identify what data type that will determine the largest value and prints the largest
value with an identifying message.
Data Type
Integer or Float

` Integer because the possible answer maybe a whole number or


or
Float because the possible answer maybe a number with a decimal point.
Identify the data type of the following:

1. Find the area of a circle: Area=3.14*r*r

2. Gets two number and prints sum of their value.

3. Find the greater number between two numbers.

4. Find the sum of the first 50 natural numbers.

5. Print 1 to 20.

6. Convert temperature: Fahrenheit to Celsius. C=5/9*(F-32)

7. “I love Philippines”

8. True or False, Yes or No or On and Off.

9. 11/12/2019

10. 'C'
As its name indicates, a
data type represents a
type of the data which
you can process using
your computer program.
It can be numeric,
alphanumeric, decimal,
etc.

Identification: Identify the following data types:

a. letterA = 'A'

b. True or False

c. a = 100000

d. 1.234

e. Hello World
LESSON 4 - Let’s do the checking

Answer Key

1. D
2. C
3. A
4. B
5. E

8 SYMBOLS & FUNCTIONS:


1. Terminal – Begin and end of the program
2. Preparation/Initialization – Variable declaration part and initial values.
3. Flow Lines – Connects all other symbols from the flowchart.
4. Input / Output – All display on the screen and input from keyboard.
5. On-page Connector – Connector to continuation of flowchart on the
same page.
6. Process – Formula and defined process are place.
7. Off-page Connector - Connector to continuation of flowchart on the
separate page.
8. Decision – All conditions, logical expressions.
1. Float
2. Integer or Float
3. Integer or Float
4. Integer
5. Integer
6. Float
7. String
8. Boolean
9. Date
10. Char

Identify the following data types:

a. letterA = 'A' - Answer: Char


b. True or False - Answer: Boolean
c. a = 100000 - Answer: Integer
d. 1.234 - Answer: Float
e. Hello World - Answer: String
Innovative Training Works, Inc. “Computer Programming Volume I” Technical
Vocational Livelihood K to 12 First Edition
https://www.tutorialspoint.com/java/java_basic_datatypes.htm
http://www.yspuniversity.ac.in/cic/algorithm-manual.pdf

Acknowledgements
Writer: Gibson J. Olazo- MTII
Editors: Ariel Tosio-EPS, Vladimir B. Paraiso-Assistant Principal
Reviewers: Robert P. Velasquez – Principal, Perlito Malaya HT-VI,
Anthony Ducta HT-III
Management Team: Maria Magdalena M. Lim-Schools Division
Superintendent-Manila, Aida H. Rondilla-Chief Education Supervisor Lucky
S. Carpio-EPS and Lady Hannah C Gillo, Librarian II-LRMS

Vous aimerez peut-être aussi