Java Planning our Programs Flowcharts Arithmetic Operators.
-
Upload
melanie-patrick -
Category
Documents
-
view
218 -
download
2
Transcript of Java Planning our Programs Flowcharts Arithmetic Operators.
![Page 1: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/1.jpg)
JavaPlanning our ProgramsFlowchartsArithmetic Operators
![Page 2: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/2.jpg)
Planning Programs It is very important to plan our
programs before we start coding
There are two ways of planning a program;
1. Pseudo-code = makes use of English statements to plot the program
2. Flowcharts = use graphical symbols
![Page 3: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/3.jpg)
Example Lets say we had the following
program class VariablesExample { public static void main (String args[]){ //variables are declared and assigned int N1 = 50; int N2 = 13; int tot; //the total of variables N1 and N2 //is stored in tot tot = N1 + N2; //Finally, we can show the result System.out.println(tot); }}
![Page 4: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/4.jpg)
Pseudo-code PlanThe following is the Pseudo-code
Plan for the previous program;
1. Start2. Store 50 in N1.3. Store 13 in N2.4. Add N1 to N2 and store result in tot.5. Display the value in tot.6. Stop
![Page 5: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/5.jpg)
Flowchart Plan The following is the Flowchart
Plan of the previous program;
Start
N1 = 50N2 = 13
tot = N1 + N2
Display tot
End
![Page 6: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/6.jpg)
Why do we Plan Programs?We plan our programs in order to
know what we will be doing before we start coding
With a plan it will be much easier to know what structure our program will have
Planning makes programming much easier
![Page 7: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/7.jpg)
Flowcharts A flowchart is basically a
graphical presentation of our program
A flowchart is very is to read and understand
Flowcharts break down our programs into many steps
![Page 8: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/8.jpg)
Flowchart Symbols
![Page 9: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/9.jpg)
Terminator The terminator is used to show1. The start and2. The end of a program
START
END
![Page 10: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/10.jpg)
ProcessA process is any action to be
done by the program
N1 = 50N2 = 13
The process in this case is declaring two variables
![Page 11: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/11.jpg)
Decision Decision are used when we have
a comparison Decisions have two outputs
which are YES or NO.
Is it Rainin
g?
YES
NO
![Page 12: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/12.jpg)
Input/OutputThe Input/ Output symbol is used1. When the program requires and
input2. When the program results in an
output Display tot
In this case the output to be shown is the contents of tot
![Page 13: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/13.jpg)
Try it out …Create1. The pseudo-codes plan 2. The flowchart plan for the following program;
class Variable{ public static void main (String args[]){ //variables are declared and assigned int N1 = 20; int N2 = 10; int tot; int tot2; //tot1 and tot 2 declared tot = N1 + N2; tot2 = N1 – N2; //Finally, we can show the result System.out.println(tot2); }}
![Page 14: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/14.jpg)
Arithmetic OperatorsArithmetic Operators are used to
perform mathematical calculations
The basic arithmetic operators ;1. + (addition)2. - (subtraction)3. / (division)4. * (multiplication)5. % (remainder)
These are called binary operators because they need to use at least two variables
![Page 15: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/15.jpg)
Unary OperatorsThen are also what we call unary operators
These only need one variable1. ++ (increment by 1)2. -- (decrement by 1)3. variable += x (same as variable = variable + x)
4. variable -= x (same as variable = variable - x)
5. variable *= x (same as variable = variable * x)
6. variable /= x (same as variable = variable / x)
7. variable %= x (same as variable = variable % x)
![Page 16: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/16.jpg)
Combining OperatorsWe could create a formula by
combining a number of operators
The order the operators are work out is the following;
1. Multiplication2. Division3. Remainder4. Addition5. Subtraction
X = 10 + 4 * 3 / 2;
10 + 4 * 3 / 210 + 12 / 210 + 616
![Page 17: Java Planning our Programs Flowcharts Arithmetic Operators.](https://reader036.fdocuments.in/reader036/viewer/2022082516/56649ccb5503460f94993fa9/html5/thumbnails/17.jpg)
Use of Brackets When we use brackets in our
formula we are telling the program which operations to calculate first
X = (10 + 4) * 3 / 2;(10 + 4 ) * 3 / 214 * 3 / 242 / 221
As we can see the result has changed!!