Вы находитесь на странице: 1из 26

Programming with Java

Lecture 1
First stage Software Engineering Department 2013-2014
Assist. Lecturer: Nigar M. Shafiq Surameery Nigar.mahmoud@koyauniversity.org

Computer
!! A computer is an electronic device, that can input, and store a set of instructions designed to perform a specific task, input and store data, process the stored data according to instructions, and produce outputs. !! Almost things that a computer do, a human can do also, so why we need computers ?

why we need computers ?


!! The reason is that humans are not good in doing repetitive works. !! humans get tired, computers dont. !! Another reason is that, computers are much faster in performing calculations than human. !! Computers execute their works without errors.

Computer Components
!! What you can see and touch is a computer hardware. !! What you cant touch is a computer software. !! Hardwares, are all physical components of computer (Keyboard, Mouse, Monitor, Printer, Hard disk, Processor, memory card,.). !! Software includes all programs and data. !! System software: Operating systems (MS-Dos, Windows, Unix, Linux,.), Language translators, Linkers, Loaders, !! Application software: Autocad, MS-word, MS-Excel, MSPowerpoint, Windows Media Player,..

Program
"! Computer programming
!! the art and science of designing and writing computer programs !! programming is a challenging problem solving activity

"!Computer program
!! A program is a set of instructions commanded to a computer, to perform a specific task. Programs are written by Programmers to solve problems, using one of programming languages.

Programming Languages Assembly Languages

Machine Languages

High-Level Languages

High-Level Languages
#! Fortarn #! Basic #! Cobol #! Pascal #! C #! C++ #! Java #! In this course we will use

Java for programming.

Algorithm
!! An algorithm is a step-by-step description of the solution to a problem !! What information is needed? !! What control structures are needed? !! Test an algorithm by tracing it on some sample data

Algorithm Representation
!! Pseudocode !! Flowcharts In this course, we will use the Flowcharts only

Flowchart
!! A flowchart is a graph consisting of geometrical shapes connected by flow lines, used in designing for solving problems. !! graphical representation of an algorithm, using special purpose symbols
$! Show clearly how control structures operate

Flowchart
Example: Write an algorithm and draw a flowchart for the process of buying a book from a bookshop. Solution: The Algorithm 1- Start, 2- Ask book-seller for the book you want, 3- Receive the bill, 4- Pay the bill, 5- Leave, 6- End.

Flowchart

This type of flowchart called Simple Sequential flowchart, in which the events comes after each sequentially and not include any selections or looping.

Flowchart
Example: Write an algorithm and draw a flowchart for determining the area and circumference of a circle.

Solution: we know that area of a circle is a=! r2, and circumference c = 2!r. The Algorithm: 1- Start, 2- Read the radius, 3- Let p = 3.14, 4- a = p x r2 5- c = 2 x p x r, 6- print r, a , and c. 7- Stop

Flowchart
Example: In the same way, we can write an algorithm, and draw a flowchart for determining the area and circumference of a room?

The Algorithm: 1- Start, 2- Read W and L, 3- a = W x L 4- c = 2 ( W+L ), 5- print a, and c. 6- Stop

Flowchart
Example: Write an algorithm and draw a flowchart for a traffic light ? The Algorithm: 1- Begin, 2- Look at the color and save it in C, 3- if C == Green, then let the action A= Pass, go to step 6, 4- if C == Red, then let the action A= Stop, go to step 6, 5- Let the action A= Wait, 6- Do action as in A, 7- End.

Flowchart

Flowchart
Example: Write an algorithm and draw a flowchart for bellow function?

The Algorithm: 1- Begin, 2- Read x, 3- if x>0, f(x)=x+1, go to step 6 4- if x= =0, f(x)=sin (x)+5, go to step 6 5- f(x)=2x-1, 6- print f(x), 7- End.

Flowchart

Flowchart
Example: Write an algorithm and draw a flowchart for the process of determining area for a number of squares ? The Algorithm: 1- Begin, 2- Read squares width, in x, 3- a= x2, 4- Print a, 5- Ask if there are more squares? Save answer in Ans. 6- If Ans: Yes, then go back to step 2. 7- End.

Flowchart

Flowchart
Example: Write an algorithm and draw a flowchart for the process of printing odd numbers between 1 and 100. The Algorithm: 1- Begin, 2- Let n=1, 3- Print n, 4- n=n+2, 5- if n<100, go to step 3, 6- End.

Self study
Example: Draw a flowchart for the process of determining average for 23 students in 3 subjects. Read their names and degrees, then print their names with their averages.

Flowchart
Example: Draw a flowchart for the process of displaying numbers that can be divided by 3 without reminder, between 1 and 50.

Self study
Example: Draw a flowchart for determining maximum number among three non-equal numbers.

Thanks!!!!!!!!!!

Вам также может понравиться