Java
Java
PROGRAMMING
JAVA NCIII
Grade 12
by:
GIBSON J. OLAZO
Master Teacher II
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.
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.
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.
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
.
Algorithm
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
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.
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.
Answer Key
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
PROGRAMMING
JAVA NCIII
Grade 12
by:
GIBSON J. OLAZO
Master Teacher II
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.
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.
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
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.
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.
• 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
• 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.
2. Write pseudocode that will read the two sides of a rectangle and calculate its
area.
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
Answer Key
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
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
PROGRAMMING
JAVA NCIII
Grade 12
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.
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
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
A FLOWCHART
• shows logic of an algorithm
• emphasizes individual steps and their interconnections
• e.g. control flow from one action to the next
EXAMPLES OF FLOWCHART
Start
Read
Temperatur
N
Print “Above
Temperature<=0
Freezing”
Y
A
Print “Below
Freezing”
End
Downloaded by roberto bula ([email protected])
lOMoARcPSD|38005005
Flowchart
3. Draw a flowchart that will read the two sides of a rectangle and calculate its
area.
Flowchart
2. Draw a flowchart which gets two number and prints sum of their value.
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
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
Answer Key
1.C
2.D
3.A
4.E
5.A
Answer:
Pseudocode
Pseudocode
4
1
5
2
7
8 Flowchart
Flowchart consist of 8 standard symbols. Draw and name the 8 standard symbols
Answer:
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
PROGRAMMING
JAVA NCIII
Grade 12
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.
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.
Rational Operation – is nothing more than a fraction in which the numerator and/or
the denominator are polynomials.
2 3
4 5
6
7
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.
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
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).
. Data Type
Float
3. Identify the data type that will read the two sides of a rectangle and calculate its
area.
Data Type
Integer
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
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
5. Print 1 to 20.
7. “I love Philippines”
9. 11/12/2019
10. 'C'
a. letterA = 'A'
b. True or False
c. a = 100000
d. 1.234
e. Hello World
Answer Key
1. D
2. C
3. A
4. B
5. E
1. Float
2. Integer or Float
3. Integer or Float
4. Integer
5. Integer
6. Float
7. String
8. Boolean
9. Date
10. Char
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