Download as pdf or txt
Download as pdf or txt
You are on page 1of 67

Faculty of Computing

Programming Concept
Week 1
Student Guide
Agenda
1. Autonomous Professional Profile

2. Program Learning Outcome

3. Course Learning Outcome

4. Syllabus

5. Class Managers and e-Campus

6. Programming Concept Pt. 1


Presentation title 2
Autonomous Professional Profile
Informatics Study Program
1. Graduates from the study program will have successful careers in the field of
informatics or other relevant sectors.
2. Graduates from the study program will succeed as entrepreneurs who
develop a Startup Business related to and supported by information
technology.
3. Graduates from the study program will successfully pursue postgraduate
studies and/or play an active role in the development of science, tools, or
technology related to the study of informatics.

3
Autonomous Professional Profile
Information System Study Program
1. Having excellent skills as an Information System Professional and ability to lead
innovation at Enterprise through Information System Technology utilization.
2. Having technopreneurial quality to develop and lead an independent business
by incorporating various technologies and cross-disciplinary approaches.
3. Having excellent ability in knowledge transfer to advance the Information
System field through the publication of innovative, creative, and applicable
scientific works.

4
Program Learning Outcome
Bachelor of Informatics

• PLO-1 Able to analyze complex problems in the field of informatics and apply principles of informatics and other relevant
disciplines to identify their solutions by taking into account insights from the advancements of trans-disciplinary fields.
• PLO-2 Able to design, implement, and evaluate computing-based solutions that meet the computing needs of a disciplinary
program.
• PLO-3 Able to communicate proficiently in various professional contexts.
• PLO-4 Able to comprehend professional responsibilities and to conduct assessment based on appropriate information in
computing practices and legal and ethical principles.
• PLO-5 Able to effectively conduct the role of team leader or member in activities that are in accordance with the discipline of
the study program.
• PLO-6 Able to apply computer science theories and the basis of software development to develop computing-based solutions.
• PLO-7 Able to analyze, design, and develop a Startup Business supported by information technology.
• PLO-8 Able to comprehend the basics of research and scientific writing in the field of informatics.
5
Program Learning Outcome
Bachelor of Information System

• PLO 1 Possessing the ability to identify and analyze complex problems in the field of computing by utilizing principles of computing,
supported by other related fields, to develop innovative and creative solutions in accordance with the development of cross-disciplinary fields
• PLO 2 Possessing the skills to design computing-based solutions and to implement them by applying modern style techniques in order to
offer complete solutions based on appropriate requirements, and to evaluate the solutions in a certain domain
• PLO 3 Possessing the proficiency to communicate properly and correctly, both orally and in writing, in a variety of domains
• PLO 4 Possessing a professionally responsible attitude and the ability to conduct assessments based on data and information in computing
practices while paying attention to ethical and legal norms
• PLO 5 Possessing the capability to be effective and efficient leaders or team members in a variety of activities, that are relevant to both the
field of information systems and those of other fields
• PLO 6 Possessing the ability to support the concept, delivery, utilization, and management of information systems within an industrial and
business environment in particular, as well as those of other environments
• PLO 7 Possessing an entrepreneurial attitude and the capability to design an independent business/start-up related to information systems
• PLO 8 Being able to learn independently as a lifelong study, and to generate and transfer cutting-edge scientific knowledge
6
Course Learning Outcome

• [PLO1 - CLO 1] Able to analyze problem in the environment and identify possible
solution that can be deliver through concepts of programming and possible programming
capability advancements of trans-disciplinary fields
• [PLO2 - CLO 2] Able to design, implement, and evaluate problem in the perspective of
programming, and present effective and efficient solutions that meet the computing
standards and serve as solution towards identified problem
• [PLO6 - CLO 3] Able to apply concept of programming theories and the basis of software
development to develop programming-based solutions

7
Team of Lecturer

Programming Concept Course Lecturer Course Lecturer Course Lecturer


Course Coordinator Ronny Juwono, S.Pd., M.T. Rikip Ginanjar, M.Sc. Agus Priyanto, M.Kom

cutifa@president.ac.id ronny@president.ac.id rikip@president.ac.id agus.priyanto@president.ac.id

8
Class Marks
• Attendance = 5%
• Class Exercises & Participations = 15 %
• Case Studies and Assignments = 15%
• Projects = 15%
• Midterm = 20%
• Final Exam = 30%

https://ecampus.president.ac.id
Student with absent more than 4 may not be
allowed to sit for Final Exam.
9
Class Agreements
1. Attendance will be done before the class starts
2. No tolerance form lateness. Students that missed
the attendance period will be counted as absent
though permitted to enter the class
3. Importance to uphold manners in class. Students
need to seek for approval prior leaving the class
(i.e. to go to toilet, urgent phone calls)
4. No Slippers!
5. Late assignment submissions will receive a penalty
score as a score reduction. We honor those who
submit on-time
6. Plagiarism and cheating are serious offenses which
results in zero (non-negotiable once proven) 10
Course Syllabus

Week 1 [4-8 September] : Introduction to Programming, Identifiers and Variables, Data Types variable,
Constant, Assignments statement and expressions, Mathematical operator +, -, *, /, \
Week 2 [11-15 September] : Introduction to Flowchart, Selections, Boolean Data Types, If – Else and
multi ways of If – Else statement, Logical Operator, Conditional Operator,
Week 3 [18-22 September] : Nested If-Else statement, Switch Statements, Quiz 1
Week 4 [25-29 September] : Mathematical Functions, Characters and Strings, String types, length and
concatenations.
Week 5 [2-6 October] : Introduction to Loops, While Loop and Do-While Loop, Loop Control (when
to break, and to continue), Nested While Loop
Week 6 [9-13 October] : For Loop, Increment, Decrement, Loop Control (with increment ++; and
decrement --), Nested For Loop, Quiz 2
Week 7 [16-20 October] : Implementation of Selection and Repetition in Problem Solving. Output
Formatting. Class Case Studies.
11
Week 8 [23-27 October] : Midterm
Course Syllabus

Week 9 [30 Oct – 2 November] : Introduction to Single Dimensional Array, Array Basics, Copying
Arrays, Counting Arrays
Week 10 [6– 10 November]: Searching Arrays, Sorting Arrays, Quiz 3
Week 11 [13 – 17 November] : Introduction to Multidimensional Arrays, Processing Two-
Dimensional Arrays
Week 12 [20 – 24 November] : Passing values between Two-Dimensional Arrays, Implementation
2D Arrays in Problem Solving. Class Case Studies.
Week 13 [27 Nov – 1 December] : Programming Project: from Requirements, Flowchart, to Coding
Implementation utilizing Selection, Loop and Arrays.
Week 14 [4 – 8 December] : Programming Project : Hands-on. Realizing Programming Project. Pt. 1
Dealing with User Input and on Monitor output.
Week 15 [11 – 15 December]: Programming Project : Hands-on. Realizing Programming Project. Pt.
2 Dealing with from txt/csv data input and txt/csv data output
12
Week 16 [ 18-20 December]: Final Exam
Week 1 : Introduction to Programming,
Identifiers and Variables, Data Types variable,
Constant, Assignments Statement and
Expressions, Mathematical operator +, -, *, /, \

13
Programs
Computer programs, known as software, are instructions to the computer.

You tell a computer what to do through programs. Without programs, a


computer is an empty machine. Computers do not understand human
languages, so you need to use computer languages to communicate with
them.

Programs are written using programming languages.

14
Popular IDEs
https://www.eclipse.org/downloads/packages/

15
A Simple Program
Listing 1.1
// This program prints Welcome to Java!
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}

Note: Clicking the green button displays the source code


with interactive animation. You can also run the code in
a browser. Internet connection is needed for this button.

16
Creating, Compiling, and Running Programs

17
Two More Simple Examples

18
Special Symbols
Character Name Description

{} Opening and closing Denotes a block to enclose statements.


braces
() Opening and closing Used with methods.
parentheses
[] Opening and closing Denotes an array.
brackets
// Double slashes Precedes a comment line.

" " Opening and closing Enclosing a string (i.e., sequence of characters).
quotation marks
; Semicolon Marks the end of a statement.
19
Blocks
• A pair of braces in a program forms a block that groups components of
a program.

public class Test {


public static void main(String[] args) { Class block
System.out.println("Welcome to Java!"); Method block
}
}

20
Block Styles
Use end-of-line style for braces.
Next-line public class Test
style {
public static void main(String[] args)
{
System.out.println("Block Styles");
}
}

End-of-line
style
public class Test {
public static void main(String[] args) {
System.out.println("Block Styles");
}
}

21
Programming Errors
• Syntax Errors
• Detected by the compiler
• Runtime Errors
• Causes the program to abort
• Logic Errors
• Produces incorrect result

22
Syntax Errors
public class ShowSyntaxErrors {
public static main(String[] args) {
System.out.println("Welcome to Java);
}
} Identify the error!

23
Runtime Errors
public class ShowRuntimeErrors {
public static void main(String[] args) {
System.out.println(1 / 0);
}
}
Identify the error!

24
Logic Errors
public class ShowLogicErrors {
public static void main(String[] args) {
System.out.println("Celsius 35 is Fahrenheit degree ");
System.out.println((9 / 5) * 35 + 32);
}
} Identify the error!

25
Introducing Programming with an Example
Listing 2.1 Computing the Area of a Circle
This program computes the area of the circle.

Note: Clicking the green button displays the source code


with interactive animation. You can also run the code in
a browser. Internet connection is needed for this button.

26
animation

Trace a Program Execution


allocate memory
for radius
public class ComputeArea {
/** Main method */
radius no value
public static void main(String[] args) {
double radius;
double area;

// Assign a radius
radius = 20;

// Compute area
area = radius * radius * 3.14159;

// Display results
System.out.println("The area for the circle of radius " +
radius + " is " + area);
}
}
27
animation

Trace a Program Execution


memory

public class ComputeArea { radius no value


/** Main method */
area no value
public static void main(String[] args) {
double radius;
double area;
allocate memory
// Assign a radius for area
radius = 20;

// Compute area
area = radius * radius * 3.14159;

// Display results
System.out.println("The area for the circle of radius " +
radius + " is " + area);
}
} 28
animation

Trace a Program Execution


assign 20 to radius

public class ComputeArea { radius 20


/** Main method */
public static void main(String[] args) { area no value
double radius;
double area;

// Assign a radius
radius = 20;

// Compute area
area = radius * radius * 3.14159;

// Display results
System.out.println("The area for the circle of radius " +
radius + " is " + area);
}
} 29
animation

Trace a Program Execution


memory

public class ComputeArea { radius 20


/** Main method */
public static void main(String[] args) { area 1256.636
double radius;
double area;

// Assign a radius
compute area and assign it
radius = 20;
to variable area
// Compute area
area = radius * radius * 3.14159;

// Display results
System.out.println("The area for the circle of radius " +
radius + " is " + area);
}
}

30
animation

Trace a Program Execution


memory

public class ComputeArea { radius 20


/** Main method */
public static void main(String[] args) { area 1256.636
double radius;
double area;

// Assign a radius
radius = 20; print a message to the
console
// Compute area
area = radius * radius * 3.14159;

// Display results
System.out.println("The area for the circle of radius " +
radius + " is " + area);
}
}

31
Variables
// Compute the first area
radius = 1.0;
area = radius * radius * 3.14159;
System.out.println("The area is “ + area + " for radius
"+radius);

// Compute the second area


radius = 2.0;
area = radius * radius * 3.14159;
System.out.println("The area is “ + area + " for radius
"+radius);
32
Declaring Variables
int x; // Declare x to be an
// integer variable;
double radius; // Declare radius to
// be a double variable;
char a; // Declare a to be a
// character variable;

33
Assignment Statements
x = 1; // Assign 1 to x;
radius = 1.0; // Assign 1.0 to radius;
a = 'A'; // Assign 'A' to a;

34
Declaring and Initializing
in One Step
• int x = 1;
• double d = 1.4;

35
Named Constants
final datatype CONSTANTNAME = VALUE;

final double PI = 3.14159;


final int SIZE = 3;

36
Rule for Identifiers
• An identifier is a sequence of characters that consist of letters, digits,
underscores (_), and dollar signs ($).
• An identifier must start with a letter, an underscore (_), or a dollar sign
($). It cannot start with a digit.
• An identifier cannot be a reserved word. (See Appendix A, “Java
Keywords,” for a list of reserved words).
• An identifier cannot be true, false, or null.
• An identifier can be of any length.

37
Exercise 1.1 Time!
1. Turn off devices, place your laptops a side
2. Take a piece of paper
3. Lets do it!

38
Problem: Converting Temperatures
Write a program that converts a Fahrenheit degree to Celsius using the
formula: celsius = ( 5 )( fahrenheit − 32)
9

39
Reading Input from the Console
1. Create a Scanner object
Scanner input = new Scanner(System.in);

2. Use the method nextDouble() to obtain to a double


value. For example,
System.out.print("Enter a double value: ");
Scanner input = new Scanner(System.in);
double d = input.nextDouble();

40
Numerical Data Types
Name Range Storage Size

byte –27 to 27 – 1 (-128 to 127) 8-bit signed

short –215 to 215 – 1 (-32768 to 32767) 16-bit signed

int –231 to 231 – 1 (-2147483648 to 2147483647) 32-bit signed

long –263 to 263 – 1 64-bit signed


(i.e., -9223372036854775808 to 9223372036854775807)

float Negative range: 32-bit IEEE 754


-3.4028235E+38 to -1.4E-45
Positive range:
1.4E-45 to 3.4028235E+38
double Negative range: 64-bit IEEE 754
-1.7976931348623157E+308 to -4.9E-324

Positive range:
41
4.9E-324 to 1.7976931348623157E+308
Reading Numbers from the Keyboard
Scanner input = new Scanner(System.in);
int value = input.nextInt();
Method Description

nextByte() reads an integer of the byte type.


nextShort() reads an integer of the short type.
nextInt() reads an integer of the int type.
nextLong() reads an integer of the long type.
nextFloat() reads a number of the float type.
nextDouble() reads a number of the double type.

42
Numeric Operators
Name Meaning Example Result

+ Addition 34 + 1 35

- Subtraction 34.0 – 0.1 33.9

* Multiplication 300 * 30 9000

/ Division 1.0 / 2.0 0.5

% Remainder 20 % 3 2

43
Integer Division

+, -, *, /, and %

5 / 2 yields an integer 2.
5.0 / 2 yields a double value 2.5

5 % 2 yields 1 (the remainder of the division)


44
Remainder Operator
Remainder is very useful in programming. For example, an even number % 2 is
always 0 and an odd number % 2 is always 1. So you can use this property to
determine whether a number is even or odd. Suppose today is Saturday and
you and your friends are going to meet in 10 days. What day is in 10 days?
You can find that day is Tuesday using the following expression:

Saturday is the 6th day in a week


A week has 7 days
(6 + 10) % 7 is 2
The 2nd day in a week is Tuesday
After 10 days

45
NOTE
Calculations involving floating-point numbers are approximated
because these numbers are not stored with complete accuracy. For
example,
System.out.println(1.0 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1);
displays 0.5000000000000001, not 0.5, and
System.out.println(1.0 - 0.9);
displays 0.09999999999999998, not 0.1. Integers are stored precisely.
Therefore, calculations with integers yield a precise integer result.
46
Exponent Operations
System.out.println(Math.pow(2, 3));
// Displays 8.0
System.out.println(Math.pow(4, 0.5));
// Displays 2.0
System.out.println(Math.pow(2.5, 2));
// Displays 6.25
System.out.println(Math.pow(2.5, -2));
// Displays 0.16

47
Number Literals
A literal is a constant value that appears directly in the program. For
example, 34, 1,000,000, and 5.0 are literals in the following
statements:

int i = 34;
long x = 1000000;
double d = 5.0;

48
double vs. float
The double type values are more accurate than the float type values. For
example,
System.out.println("1.0 / 3.0 is " + 1.0 / 3.0);

displays 1.0 / 3.0 is 0.3333333333333333

16 digits

System.out.println("1.0F / 3.0F is " + 1.0F / 3.0F);

displays 1.0F / 3.0F is 0.33333334


7 digits

49
Arithmetic Expressions
3 + 4 x 10( y − 5)( a + b + c ) 4 9+ x
− + 9( + )
5 x x y

is translated to

(3+4*x)/5 – 10*(y-5)*(a+b+c)/x + 9*(4/x + (9+x)/y)

50
Demo: Displaying Time
A program that obtains minutes and remaining seconds
from seconds.

51
Demo: Displaying Current Time
Write a program that displays current time in GMT in the format
hour:minute:second such as 1:45:19.
The currentTimeMillis method in the System class returns the current
time in milliseconds since the midnight, January 1, 1970 GMT. (1970
was the year when the Unix operating system was formally
introduced.) You can use this method to obtain the current time, and
then compute the current second, minute, and hour as follows.
Elapsed
time
Time
Unix Epoch Current Time
01-01-1970 System.currentTimeMills()
00:00:00 GMT

52
Augmented Assignment Operators

53
Numeric Type Conversion
Consider the following statements:
byte i = 100;
long k = i * 3 + 4;
double d = i * 3.1 + k / 2;

range increases

byte, short, int, long, float, double

54
Type Casting
Implicit casting
double d = 3; (type widening)

Explicit casting
int i = (int)3.0; (type narrowing)
int i = (int)3.9; (Fraction part is truncated)

What is wrong? int x = 5 / 2.0; range increases

byte, short, int, long, float, double

55
Demo: Keeping Two Digits After Decimal Points
Write a program that displays the sales tax with two digits after the
decimal point.

56
Exercise 1.2 Time!
1. Turn off devices, place your laptops a side
2. Take a piece of paper
3. Let’s do it!

57
Problem:
Computing Loan Payments
This program lets the user enter the interest
rate, number of years, and loan amount, and
computes monthly payment and total
payment.
loanAmount  monthlyInterestRate
monthlyPayment =
1− 1
(1 + monthlyInterestRate) numberOfYears12

58
Common Errors and Pitfalls
Common Error 1: Undeclared/Uninitialized
Variables and Unused Variables
Common Error 2: Integer Overflow
Common Error 3: Round-off Errors
Common Error 4: Unintended Integer Division
Common Error 5: Redundant Input Objects

Common Pitfall 1: Redundant Input Objects


59
Common Error 1: Undeclared/Uninitialized
Variables and Unused Variables

double interestRate = 0.05;


double interest = interestrate * 45;

60
Common Error 2: Integer Overflow

int value = 2147483647 + 1;


// value will actually be -2147483648

61
Common Error 3: Round-off Errors

System.out.println(1.0 - 0.1 - 0.1 - 0.1 - 0.1 - 0.1);

System.out.println(1.0 - 0.9);

62
Common Error 4: Unintended Integer
Division
int number1 = 1; int number1 = 1;
int number2 = 2; int number2 = 2;
double average = (number1 + number2) / 2; double average = (number1 + number2) / 2.0;
System.out.println(average); System.out.println(average);

(a) (b)

63
Common Pitfall 1: Redundant Input Objects

Scanner input = new Scanner(System.in);


System.out.print("Enter an integer: ");
int v1 = input.nextInt();

Scanner input1 = new Scanner(System.in);


System.out.print("Enter a double value: ");
double v2 = input1.nextDouble();
64
Exercise 1.3 Time!
1. Turn off devices, place your laptops a side
2. Take a piece of paper
3. Let’s do it!

65
Problem: Monetary Units
• Write a program lets the user enter the
amount in representing Rupiah and output a
report listing the monetary equivalent in:
• Hundred thousand rupiah
• Fifty thousand rupiah
• Twenty thousand rupiah
• Ten thousand rupiah
• Five thousand rupiah
• Two thousand rupiah
• One thousand rupiah
• Coins. ComputeChange
66
Class Exercise 1 Compilations

• Take a picture of your exercises 1.1, exercises 1.2 and exercises 1.3
• Hand over your exercises next week before the class start.
• Compile your exercises in one PDF and upload to e-campus
(given later, before 10 September 2023).
• Late upload in e-campus will results in 50% marks off per day.

67

You might also like