Java Programming Module 1-4 Weel 1-4
Java Programming Module 1-4 Weel 1-4
JAVA NCIII
Grade 11
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
installing 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
1. Write an algorithm to print 1 to 20.
3. Write an algorithm that will calculate the roots of a quadratic equation ax 2+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.
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.
PROGRAMMING
JAVA NCIII
Grade 11
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.
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.
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.
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).
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.
Did you accomplish the task?
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.
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.
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?
How you want
Computer
Peripheral input and output devices
Accepted notations
PROGRAMMING
JAVA NCIII
Grade 11
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.
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
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
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.
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
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
PROGRAMMING
JAVA NCIII
Grade 11
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.
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.
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
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
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'
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.
letterA = 'A'
True or False
a = 100000
1.234
Hello World