0% found this document useful (0 votes)
24 views

Module - 1 PAC and Pesudocode

Uploaded by

Rahul Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Module - 1 PAC and Pesudocode

Uploaded by

Rahul Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 72

BCSE103E

Computer Programming: JAVA


Course Objective

1. To introduce the core language features of Java and understand


the fundamentals of Object -Oriented programming in Java.
2. To develop the ability of using Java to solve real world problems.
Course Outcomes

1. Understand basic programming constructs;


realize the fundamentals of Object Orientated
Programming in Java; apply inheritance and
interface concepts for enhancing code reusability.

2. Realize the exception handling mechanism; process


data within files and use the data structures in
the collection framework for solving real world
problems.
Course Content
Course Content
Course Content
Rubrics
Note: Preliminary plan for the Course
Sl. No Exams Marks Weightage Module
1 PAT1 10 10 Java Basics, Loops
2 PAT2 10 10 Module 2
3 PAT3 10 10 Module 3
4 Mid-Term 50 20 Module 4,5
5 Quiz 20 10 Module 1-6
6 FAT 50 40 Module 1-7
Note
• Do not miss any class, practice problem, assessments
and challenging tasks.

• Be ethical and professional throughout the course

• Unethical practices are punishable

Important: No Re-exam

Exams will be conducted through

http://www.vpropel.in/
JAVA - IDE
JAVA - Eclipse
Step 1) Installing Eclipse Open your browser and type https://www.eclipse.org/

Step 2) Click on “Download” button.


JAVA - Eclipse
Step 3) Click on “Download 64 bit” button

Step 4) Click on “Download” button


JAVA - Eclipse
Step 4) Install Eclipse.
1.Click on “downloads” in Windows file explorer.
2.Click on “eclipse-inst-win64.exe” file.

Step 5) Click on Run button


JAVA - Eclipse
Step 6) Click on “Eclipse IDE for Java Developers”
JAVA - Eclipse
Step 7) Click on “INSTALL” button
JAVA - Eclipse
Step 8) Click on “LAUNCH” button.
JAVA - Eclipse
Step 9) Click on “Launch” button.
JAVA - Eclipse
Step 10) Click on “Create a new Java project” link.
JAVA - Eclipse
Step 11) Create a new Java
Project:
1.Write project name.
2.Click on “Finish button”.
JAVA - Eclipse
Step 12) Create Java Package.
1.Goto “src”.
2.Click on “New”.
3.Click on “Package”.
JAVA - Eclipse
Step 13) Writing package name.
1.Write name of the package
2.Click on Finish button.
JAVA - Eclipse
Step 14) Creating Java Class
1.Click on package you have created.
2.Click on “New”.
3.Click on “Class”.
JAVA - Eclipse
Step 15) Defining Java Class.
1.Write class name
2.Click on “public static void main (String[]
args)” checkbox.
3.Click on “Finish” button.
JAVA - Eclipse
Helloword.java file will be created as shown below:
JAVA - Eclipse
Step 16) Click on “Run” button.

Reference: https://www.guru99.com/install-eclipse-
Output will be displayed as shown below.

java.html
Problem Solving Techniques
Problem Solving: Definition
• It is a process of identifying the problem,
developing an algorithm or approach, then
converting algorithm into computer code or program

• Programming is a problem solving activity.

• Program - Instruction for the computer to solve


something for you.
Problem?
Problem to Solution
Input
List of Data provided

Processing
Actions needed to obtain the required output

Output
List of Output Required
Problem Analysis Chart (PAC)
• According to Sprankle and Hubbard, (2012), the initial step for
a programs need to do when get a problem is to analyze and
understand the requirements.
• To easily analyze the problem, a Problem Analysis Chart (PAC)
was introduced. This chart have four section:
• The given data
• The required result
• The processing involved
• A list of solution alternative
PAC - Table
Problem Analysis Chart (PAC)
1. A program is required to find average of five
numbers.
Given Data Required Result
Number_1 Average of 5 numbers
Number_2
Number_3
Number_4
Number_5

Process Required Solution Alternative


Total = Number 1+ Number 2+ 1. Define the numbers as constants.
Number 3+ Number 4+ 2. Define the numbers as input
Number 5 values
Average = Total / 5
Problem Analysis Chart (PAC)
• Calculate the area of a circle for any given radius

Given Data Required Result


Radius r Area of the Circle

Process Required Solution Alternative


Area = pi * r^2 1. R as constant
2. R can be a User input
Problem Analysis Chart (PAC)
2. A program is required to find the volume of a
cuboid. Please construct the PAC for this problem.
Input Output
Length (l) Volume (V)
breadth (b)
width(w)

Process Required Solution Alternative


V = l*b*w 1. l, b, w as constant
2. User input
Problem Analysis Chart (PAC)
3. Write a Problem Analysis Chart (PAC) to convert the distance
in miles to kilometers where 1.609 kilometers per mile.

Given Data Required Result


Distance (d) in miles Distance (D) Kilometer
Fac = 1.609

Process Required Solution Alternative


D = d*Fac 1. d can be a constant
2. d can be a user input
Problem Analysis Chart (PAC)
4. Write a Problem Analysis Chart (PAC) to find an area of a
rectangle where area = height * length.

Given Data Required Result


Height(h), Length (l) Area (A)

Process Required Solution Alternative


A=h*l 1. h and l is constant
2. h and l as user input
Algorithm
Definition: a complete, unambiguous, finite number of
logical steps for solving a specific problem
• A set of sequential steps usually written in Familiar
Language to solve a given problem is called
Algorithm.
• It may be possible to solve to problem in more than
one ways, resulting in more than one algorithm.
Algorithm
• The choice of various algorithms depends on the
factors like reliability, accuracy and easy to modify.
• The most important factor in the choice of algorithm
is the time requirement to execute it, after writing
code in High-level language with the help of a
computer.
• The algorithm which will need the least time when
executed is considered the best.
Steps involved in algorithm development
Identification of input
1

Identification of Output
2

Identification the processing operations


3

Processing Definiteness
4

Processing Finiteness
5

Possessing Effectiveness
6
Characteristics of a good algorithm
• Finiteness: An algorithm must terminate in a finite number of steps
• Precision: the steps are precisely stated or defined.
• Effectiveness: it should be primitive easily convert able into program
statement
• Generality: The algorithm must be complete in itself so that it can
be used to solve problems of a specific type for any input data.
• Input/output: Each algorithm must take zero, one or more quantities
as input data produce one or more output values.
• An algorithm can be written in English like sentences - Pseudo Code
• Visual Representation of Algorithms – Flow chart
Pseudocode
• It is a simpler version of a programming code in plain English
which uses short phrases to write code for a program before
it is implemented in a specific programming language.
• It does not have a specific syntax like any of the programming
languages and thus cannot be executed on a computer.
• Many time algorithms are presented using pseudocode since
they can be read and understood by programmers who are
familiar with different programming languages
Pseudocode
• Pseudocode allows you to include several control structures
such as While, If-then-else, Repeat-until, for and case, which is
present in many high-level languages.
Keywords : INPUT, COMPUTE,PRINT, INCREMENT, DECREMENT,
IF/ELSE, WHILE, TRUE/FALSE
Advantages of Pseudocode
 Reduced complexity
 Increased flexibility
 Ease of understanding
Pseudocode
• The programming process is a complicated one.
• You must first understand the program specifications.
• Then you need to organize your thoughts and create
the program.
• You must break the main tasks that must be
accomplished into smaller ones in order to be able
to eventually write fully developed code.
• Writing Pseudocode will save you time later during
the construction & testing phase of a program's
development.
Example
Write a pseudocode to display the sum of two numbers
entered by user.
input num1
input num2
COMPUTE Result = num1 + num2
PRINT Result
Flowchart
A graphical representation of the sequence of operations in an
information system or program.
 Information system flowcharts show how data flows from
source documents through the computer to final
distribution to users.
 Program flowcharts show the sequence of instructions in a
single program or subroutine. Different symbols are used
to draw each type of flowchart.
A Flowchart
 shows logic of an algorithm
 emphasizes individual steps and their interconnections
 e.g. control flow from one action to the next
Flowchart
A flow chart is an organized
combination of shapes, lines
and text that graphically
illustrate a process or
structure.
Flowchart
Flowchart symbol Function Description
Start/End Also called “Terminator” symbol. It indicates
where the flow starts and ends.
Process Also called “Action Symbol,” it represents a
process, action, or a single step.
Decision A decision or branching point, usually a yes/no or
true/ false question is asked, and based on the
answer, the path gets split into two branches

Input/ Also called data symbol, this parallelogram shape


Output is used to input or output data

Arrow Connector to show order of flow between shapes.

Connector Connection of flowchart on the same page.

Connector Connection of flowchart from page to page.


Example
Write an algorithm to display the sum of two numbers
entered by user, using both pseudocode and flow chart.
Examples
Write an algorithm and draw a flowchart to convert
the length in feet to centimeter. [1 feet = 30 cm.]
Examples
Pseudocode:
Input Length in feet (Lft)
Calculate Lcm = Lft * 30
Print Lcm
Examples
START

Input
Lft

Lcm  Lft x 30

Print
Lcm

STOP
Examples
Write an algorithm and draw a flowchart that will read
the two sides of a rectangle and calculate its area.
Examples
Pseudocode
• Input the width (W) and Length (L) of a rectangle
• Calculate the area (A) by multiplying L with W
• Print A
Examples
START

Input
W, L

ALxW

Print
A

STOP
Exercise
Write PAC, Pseudocode and draw a flowchart that will
calculate the roots of a quadratic equation
Three Basic Language Structures

• Sequence structure
• Selection structure
• Repetition structure
Three Basic Language Structures
Flowcharts for three constructs
Pseudocode for three constructs
Examples
Create PAC, Pseudocode, Flowchart to check whether a number is
odd or even.
PAC
Given Data Required Result
n1 Display Odd or Even

Process Required Solution Alternative


If n1% 2 == 0 [% modulus]
even number
Else
odd Number
Pseudocode
PRINT "Enter the Number"
INPUT number
IF number MOD 2 == 0 THEN
PRINT "Number is Even"
ELSE
PRINT "Number is Odd"
Flow Chart
START

Input num1

Is
Yes num1 No
Mod
2==0?

Print “Even” Print “Odd”

STOP
Examples
Create PAC, Pseudocode, Flowchart to print the numbers 0 to “n”
value.
PAC
Given Data Required Result
n Sum of the n numbers

Process Required Solution Alternative


n value
I = 0 [Start]
While (i<=n)
Print I
i = i+1
End While
Pseudocode
PRINT "Enter the Number"
INPUT n
i= 0
WHILE (I <= n)
PRINT i
i= i+1
END WHILE
Flow Chart START

Input n

i=0

While False
(i<=n)

True

Print “i”

STOP
Programming Or Implementation Phase
• Transcribing the logical flow of solution steps in
flowchart or algorithm to program code and run the
program code on a computer using a programming
language.
• Programming phase takes 5 stages:
• Coding.
• Compiling.
• Debugging.
• Run or Testing.
• Documentation and maintenance.
Programming Or Implementation Phase
• Once the program is coded using one of the
programming language, it will be compiled to ensure
there is no syntax error.

• Syntax free program will then be executed to produce


output and subsequently maintained and
documented for later reference.
CODING

COMPILE THE MAKE


PROGRAM CORRECTION

NO SYNTAX
ERROR

EXECUTE OR
RUN

DOCUMENTATION OR
MAINTENANCE
Coding
• Translation or conversion of each operation in the
flowchart or algorithm (Pseudocode) into a computer-
understandable language.
• Coding should follow the format of the chosen
programming language.
Compiling and Debugging
• Compiling - Translates a program written in a particular high–level
programming language into a form that the computer can understand
• Compiler checks the program code so that any part of source code
that does not follow the format or any other language requirements
will be flagged as syntax error.
• This syntax error in also called bug, when error is found the
programmer will debug or correct the error and then recompile the
source code again
• Debugging process is continued until there is no more error in
program
Testing
• The program code that contains no more error is called
executable program. It is ready to be tested.
• When it is tested, the data is given and the result is verified
so that it should produced output as intended.
• Though the program is error free, sometimes it does not
produced the right result. In this case the program faces logic
error.
• Incorrect sequence of instruction is an example that causes
logic error.
Documentation and Maintenance
• When the program is thoroughly tested for a substantial period of time
and it is consistently producing the right output, it can be documented.
• Documentation is important for future reference. Other programmer
may take over the operation of the program and the best way to
understand a program is by studying the documentation.
• Trying to understand the logic of the program by looking at the source
code is not a good approach.
• Studying the documentation is necessary when the program is
subjected to enhancement or modification.
• Documentation is also necessary for management use as well as audit
purposes.

You might also like