ICS2602
ICS2602
1805 him
Fortier1 : importance of
programming
Prof. Maria Lourdes L. Edang
Instructor:Asst.
PROGRAMMING
consultation Hours: TBA
-it is a tool to get solution by carefully,
pushing the repetitive tasks the
to
(C + +) -
17 computer
·
To harness the power of computing
in all human endeavor
GRADING SYSTEM
·
To automate tasks
PRELIM GRADE
30%. Machine Problem ·
To create intelligentmachines
30% long quizzes
40% Prelims exam
Importantterms to remember
FINAL GRADE
1) Programming language
301. Machine Problem
2)Syntax
CONVERSION GRADE
OF TO 75%
-
rules governing its word usage
andpunctuation
25/40 ·
(grade 60) -
75
+
3) computer memory
passing rate is 75% -
volatile
4) storage
permanent devices
- nonvolatile
↑
understanding
Program Development
5) compiler/Interpreter cycle
-
4) program executes/runs
~
Inputwill be accepted i
-
some processing will occur,
andresults will be output
3) Logical Errors
mostdifficult
aspects
a) logic ofComputer program One ofthe of programming
-
in specific order
Planning the logic
10) variable
-
heart
of the programming process
-mostcommon
planning tools
-Namedmemory location whose Flowchart
·
Parough
-
X +
9
a program's logic
number
On
paper before you actually
write
the
program
variable Coding the program
addition
sign
Program Development
cycle
-understand the problem
-plan the logic
-
a
translate the program into machine into machine
program language
language
Testt he
program SyntaxError
-
into production
Translator Program
-putthe program compiler/interpreter -
misuse a
of
language's
-
Maintain the program -changes the
programmer's grammar rules programmer
english-like high-level corrects listedsyntaxerrors
programming language into the the
mightneed to recompile
low-level machine language code several times
understanding the Evolution Programming
of
Models
Major Difference
-
-conversion
-
entire seto factions an organization t ake
must
programs
-Use a
syntactically
correct statementbutuse
context
current
the
wrong one for the
-
Test
-execute the program with some sample data to
data
of
ALGORITHM
setof instructions to perform a specific
-
Maintenance -
well-definedstep-by-stepsolution
-making changes after program is putinto Flowchart
production -
Graphical representation of an
algorithm
-common changes to existing programs
-
method of
describing algorithm
Understanding User Environments
unggembing programminganguage
-
Command line
-Location on your computer screen atwhich
communicate with
you type textentries to flowsharting symbol
operating system
the computer's
OUAPU Or Write
A, B.
A, B.
↳ pseudocode
OutputA;Or Write A;
*3. 1416
EXAMPLE 1
Design Flowchart and pseudocode thatwill
↳> Pseudocode a
accept two numbers display
and the computed
sum and product
SetX to 11
SetPI to 3.1416 pseudocode Flowchart
start start
Product 0 =
inputA, B
FindATB an dassign to sum it
A,B
↳Flowchart product
FindAAB and assign to
Sum, product Sum A
=
+ B product-A*B
Display
end
Display sum, product
A, B.
IPUt Or
ARE End
↳ pseudocode
InputA;or Read A;
Input B; Read Bi
CONDITIONAL OPERATION Flowchart
e
-
EXAMPLE2
isret
a flowchartandpseudocode
to determine
Create
if the passwordis correct. The correctpassword
is 123
pseudocode
Start
Set PASSWORD to 0
Input PASSWORD
IFPASSWORD is equal to 123
EXAMPLE4
Display"PASSWORD
is correct"
end
Create a flowchartandpseudocode to
"itrary
Pseudocode
Start
Set NUM OO
InputNUM
NUM
IF is less than to 0
"
Display:NUM than 8
is less
in
else IF NUM IS
greater than to 0
Display "NUM IS greater than to 0
"
else
End
EXAMPLE3
create a flowchartand Pseudocode to determine Flowchart
if a number is oddor even
Start
Pseudocode
Set NUM to 0
mirae
Nissant
InputNUM
NUM
IF mod (1.) 2 is equal to 0
Display "NUM is EVEn"
start start
setn B sq to
8
Pis C0
=
re
andstore the
69 0 outputA
result to sq
=
AHr2
=
W end
inputn
Flowchart: pseudocode:
sq n*
n=
Start start
Set s, Airto 0 and
↓
display sq 3.14
pi to
arein
input S
end anddivide
multiply 2 to 3
to
its 3.14 then store
the result to r
antimeter pinches
& Develop an algorithm thatadverts
multiply to itself and to 3
Flowchart: pseudocode: then store the result
toA
start
Nat in
set 3 cm to display I
En
in
convertc m to
an
e
multiply cm to 2.54
display in
end
↓
ed
MODULE 3: SEQUENTIAL JAVA PROGRAMMING
INTRODUCTION
• Computers have greatly affected our daily lives - helping us complete many tasks
LANGUAGE OF A COMPUTER
• Machine Language: the most basic language of a computer
• A sequence of 0s and 1s
• Compiler: a program that translates a program written in a high-level language into the
equivalent machine language
• Java Virtual Machine (JVM): hypothetical computer developed to make Java programs
machine independent
PROGRAMMING METHODOLOGIES
• 2 Basic Approach to programming design
- Structured Design
• The solutions of all subproblems are the combined to solve the problem
• Steps in OOD
1. Identify objects
- An object-oriented language
- General-purpose
- Advantages
- Security features
- Architecturally neutral
• Source code
• Byte code
- A binary program into which the Java compiler converts source code
• Java interpreter
- Executes bytecode instructions line by line within the Java Virtual Machine
• WORA
• Console applications
• Windowed applications
- Menus
- Toolbars
- Dialog boxes
A JAVA PROGRAM
Public class ASimpleJavaProgram
Sample Run:
9 + 8 = 17
PROCESSING OF A JAVA PROGRAM
• Two types of Java programs: applications and applets
• Interpreter: reads and translates each bytecode instruction into machine language
and then executes it
3. Maintain the program: use and modify if the problem domain changes
A JAVA PROGRAM
Public class First
{ -
First
System.out.println(“First Java Application”);
Clas S
}
• Java Identifiers
- Names of things
·
- Consist of:
- Letters
- Digits
- Underscore
- Dollar sign
- Letters
- Digits
- Underscores
- Dollar signs
IDENTIFIERS
• Upper Camel casing (Pascal casing)
- UnderGradStudent
- InventoryItem
• Access specifier
`
- Defines how a class can be accessed
• Example
double amountDue;
int counter;
char ch;
• Example
ClassMembers
Statement 1
Statement n
}
PARTS OF TYPICAL CLASS
- reserved keyword
- Means the method is accessible and usable even though no objects of the class exist
• Void
- Indicates the main() method does not return a value when called
• For every opening curly brace ( { ) in a Java program, there must be a corresponding closing
curly brace
(} )
• Placement of the opening and closing curly braces is not important to the compiler
• System.in object
• AccessusingtheScannerclass
• Scannerobject
• To read data:
• Example
int feet;
int inches;
23 7
Methods :
println
Syntax:
System.out.print(StringExp);
System.out.println(StringExp);
System.out.print();
System.out.println(“Hello World”);
System.out.print(“Hello World”);
int x = 100;
System.out.println(“x”);
System.out.println (x);
System.out.println (5 + 10);
System.out.println (5 + 10 + “abc”);
• To produce console output on multiple lines in the command window, use one of these
options:
Import STATEMENT
• Used to import the components of a package into a program
• Reserved word
• import java.io.*
Example:
num1 = 13;
num2 = 5 * 5 - 11;
first = ‘A’;
- The compiler does not translate, and the JVM does not execute its command
TYPES OF COMMENTS
• Line comments
• Block comments
• Javadoc comments
INDENT STYLE
• Use whitespace to organize code and improve readability
• For every opening curly brace ( { ) in a Java program, there must be a corresponding closing
curly brace (} )
• Placement of the opening and closing curly braces is not important to the compiler
• For public classes, class name and filename must match exactly
• Compilation outcomes
- A misspelled filename
- The symbol
- The location
• Compile-time error
• Parsing
- The syntax is correct but incorrect results were produced when executed
• Run-time error
- Type javaFirst
SAMPLE RUN
FINDING HELP
• Java API
- Free to download
DON’T DO IT
• Don’t forget the file’s name must match the class name
- Parentheses, braces, brackets, curly braces, square brackets, and angle brackets
- Don’t forget to end every statement with a semicolon • Do not end class or method
headers with a semicolon
• Don’t assume your program is perfect when all compiler errors are eliminated.
MODULE 4:DATA TYPES
DATA TYPES
• set of values together with a set of operations
• Floating
- float, double
• Textual
- char
• Logical
- boolean
INTEGRAL
Examples:
System.out.println(myNum);
System.out.println(myNum);
System.out.println(myNum);
System.out.println(myNum);
FLOATING POINT
float myNum = 5.75f;
System.out.println(myNum);
System.out.println(myNum);
float f1 = 35e3f;
double d1 = 12E4d;
System.out.println(f1);
System.out.println(d1);
TEXTUAL TYPE
• Can be represented in three ways:
TEXTUAL
Examples:
System.out.println(myGrade);
System.out.println(a);
System.out.println(b);
System.out.println(c);
BOOLEAN
Example:
STRING
• used to store a sequence of characters (text).
Example:
System.out.println(greeting);
CONCATENATION
• A numeric variable is concatenated to a String using the plus sign ( + )
• Primitive types are predefined (already defined) in Java. Non-primitive types are created by
the programmer and is not defined by Java (except for String).
• Non-primitive types can be used to call methods to perform certain operations, while
primitive types cannot.
• A primitive type has always a value, while non-primitive types can be null.
• A primitive type starts with a lowercase letter, while non-primitive types starts with an
uppercase letter.
• The size of a primitive type depends on the data type, while non-primitive types have all the
same size.
byte -> short -> char -> int -> long -> float -> double
double -> float -> long -> int -> char -> short -> byte
WIDENING CASTING
• done automatically when passing a smaller size type to a larger size type
// double to int
System.out.println(myInt); // Outputs 9
}
}
• Syntax
(dataTypeName) expression
• Examples
(int)(7.9 + 6.7) = 14
(int)(7.9) + (int)(6.7) = 13
- Use methods from the built-in Java classes Integer and Double
- Type-wrapper classes
- Each primitive type has a corresponding class contained in the java.lang package
Integer.parseInt()
Double.parseDouble()