CS 112 MODULE Chapter 1-3 1st Sem 2021-2022
CS 112 MODULE Chapter 1-3 1st Sem 2021-2022
CS 112
NOR-AINE M. CORPUZ
DANILYN A. FLORES
2021
CS 112
NOR-AINE M. CORPUZ
DANILYN A. FLORES
2021
USM MISSION
Page
CHAPTER 1 Introduction to Computer Programming
What is Computer Programming? 1
Brief History of Programming 2
Traits of a Good Programmer 4
Good Programming Practices 6
Qualities of a Good Program 7
Formative Assessment 8
Chapter Summary 8
Summative Assessment 8
Chapter References 9
CHAPTER 2 Programming Fundamentals
Program Development Life Cycle 10
Comments 15
Tokens 16
Separators 16
Identifiers 16
Keywords 17
Literals 17
Data Types 18
Variables 19
Operators 20
Expressions 25
Statements 26
Blocks 26
Formative Assessment 27
Chapter Summary 28
Summative Assessment 29
Chapter References 29
CHAPTER 3 Inputs and Outputs
Getting to Know the Software Interface 30
Creating Simple Programs using JCreator 31
Displaying Output on Console 34
Creating Simple Programs using JAVA N-IDE 36
Getting Input and Displaying Output using Graphical User 40
Interface
Formative Assessment 40, 45
Chapter Summary 46
Summative Assessment 47
Chapter References 47
APPENDICES 48
ANSWER KEY 49
Course Information
Course Title Fundamentals of Programming
Course Code CS 112
Pre-requisite/Co-requisite None
Course Description
This course covers the use of general purpose programming language
to solve problems. The emphasis is to train students to design, implement, test,
and debug programs intended to solve computing problems using fundamental
computing constructs.
Fundamentals of Programming enables students to learn the important
basic programming concepts like variables, data types, operators, and control
structures, and apply these using the Java programming language. As an
introduction, this course gives an overview of the different problem-solving
strategies that will help them analyze problems to create programs throughout
the course.
The course helps students understand the processes and the
significance of making programs, its implementation, application, and
significance to the industry, and the community. Also, this course helps give
students a deep understanding and developed skills of all the basic concepts
of programming and effectively utilize the language and programming
structures in program-making that willhelp them learn other and new
programming languages for them to be competent individuals.
Course Objectives/Outcomes
Upon passing the course, you must be able to:
1. Discuss the different concepts and techniques used in creating
computer programs.
2. Use appropriate programming components in designing a computer
program for a given problem.
3. Create computer programs using the Java programming language for
given problems.
A program is a set of
instructions written in a language
understandable by the computer to
perform a particular function on the
computer. Fig. 1 shows a screenshot of
a simple code in Java that displays
Hello World!.
Fig. 1. Sample Program
A computer programmer is a Image Source:
http://javalanguageprogramming.blogspot.com/201
professional skilled in using constructs 3/03/first-java-program-hello-world.html
of programming languages to develop
executable and acceptable computer programs. A computer programmer can
be as young as 7 years old (as of 2016) or as old as 82 years old (as of 2017).
A Programming Language is
an artificial language created to be
used in preparing coded instruction
on the computer for later execution by
the computer. It is a standardized
communication technique for
expressing instructions to a
computer. It enables a programmer to
precisely specify what data a
computer will act upon, how these
data will be stored or transmitted and
precisely what actions to take under
various circumstances. It is usually
composed of a series of usage rules
Fig. 2. Top 10 Programming Languages 2017
Image Source:
(syntax) that determine the meaning
http://blog.revolutionanalytics.com/2017/07/ieee- (semantics) of expressions written in
spectrum-2017-top-programming-languages.html
the language. Each programming
language comes hand in hand with its own translator like an interpreter or
compiler as the case may be. Fig. 2 shows the 2017 Top 10 Programming
So you know how to code. That does not make you a good
programmer; that is just one of the traits of a good programmer. Programmers
aren’t born in a day. It is a product of constant learning and practice. Being a
good programmer is not just all coding. To understand this, here is a list of what
a good programmer’s traits should be by Katie Bouwkamp, currently a Sr.
Communications Manager at Smartsheet, in 2017.
Programmers do not code for themselves. And though end users are
the ones who actually use the software that programmers code, there are still
cases that the software needs maintenance and modification. With this, codes
should be easy to read and understand so that it will be easy to modify, debug,
and maintain, especially when the original programmer is not around anymore.
Below is a list of 10 good programming practices any programmer can follow
from Burak Guzel (2011) who is a full time PHP Web Developer and Andrey
Nikishaev (2017) who is a software developer for 15 years.
Formative Assessment
Chapter 1 Summary
Summative Assessment
[1] Guzel, B. (2021). Top 18 Best Practices for Writing Super Readable Code.
Retrieved 21 July 2021, from https://code.tutsplus.com/tutorials/top-15-best-
practices-for-writing-super-readable-code--net-8118
[3] Woodward, J., & Fayed, M. (2016). Why everyone should have to learn
computer programming. Retrieved 21 July 2021,
from http://theconversation.com/why-everyone-should-have-to-learn-
computer-programming-62328
Programmers do not just sit in front of their computers and write code.
There has to be a problem that needs to be addressed using a program; it can
be anything like process improvement, to understand the world more or to just
help people use computers better. But even if there is a problem, the
programmer cannot just go to writing codes just yet. Programmers have to
follow a series of steps called the Program Development Life Cycle to ensure
that the program written can indeed address the given problem. The steps of
the PDLC are discussed below.
The programmer has to analyze the given problem first and here
are the things that needs to be done:
a) Human Language
When using human
language, the programmer
can use any
language/dialect that can be
understood by everyone.
The algorithm can be Fig. 10. Algorithm in Human Language
Image Source:
represented using numbered https://www.slideshare.net/annisasabrina
description of the process or batrisyia/programming-1-compatibility-
mode
ordered description of a
process such as in Fig. 10.
b) Pseudocode
A pseudocode is an informal high-level description of the
operating principle of a computer program or other algorithm.
It is a combination of human language and programming
language.
c) Flowchart
A flowchart, introduced by
Frank and Lillian Gilberth in 1921, is a
diagrammatic method of representing
algorithms like what is shown in Fig. 11.
They use an intuitive scheme of
showing operations using different
symbols shown in Table 1 that
graphically show the flow of control in
an algorithm.
1. Syntax Error
This type of error occurs from grammar errors in the use of
the programming language such as a misspelled variable,
missing semicolons, improperly matched parentheses,
brackets, and braces and incorrect format in selection and
loop statements
2. Logic Error
This type of error occurs when there is a design flaw in the
program where the output is not what is expected such as
multiplying when it should be dividing, adding when it should
be subtracting, opening a data from the wrong file, displaying
the wrong message.
3. Runtime Error
This type of error occurs when a program with no syntax
error asks the computer to do something that the computer is
unable to reliably do such as trying to divide by a variable that
contains a value of zero or trying to open a file that doesn’t
exist.
EXAMPLE 1
Problem: Solve for the sum of 2 numbers.
2. PROGRAM DESIGN
Most people prefer visual stuff. So in programming, algorithm can be
better understood when represented using a flowchart (Scanlan, 1987).
A flowchart should have 1 start and 1 stop point only. For ease of
understanding, add a “get” for inputs and add “display” for outputs since
there is only 1 symbol for IO.
Flowchart 1 Flowchart 2
Start
Start • When creating
flowcharts, • Since the 2
names of numbers are
variables user inputs for
should match get num1 this version, no
num1 = 3 what is in the values are
analysis. initially
• Assigning assigned, num1
values to a and num2 are
get num2 inside IO
num2 = 4 variable is a
process, thus, symbols.
num1 = 3, num2 • Just include a
= 4, and sum = “get” for inputs
sum = num1 + num2 num1 + num2 sum = num1 + num2 and “display”
are inside for outputs to
process lessen
symbols. confusions.
• We want to
display sum display sum
output the
value of sum,
thus, sum is in
an IO symbol.
Stop • Make sure the Stop
arrows of the
flowline point
towards the
next symbol in
the process.
COMMENTS
Formative Assessment 2
1. What type of comment is used in the Hello World program?
2. Which lines in the program are comments?
-------------------------------------------------------------------------------------------------------
SEPARATORS
Formative Assessment 3
What are the different separators in the Hello World program?
-----------------------------------------------------------------------------------------
IDENTIFIERS
Formative Assessment 4
1. Can you point out the different identifiers in the Hello World program?
How many are there?
KEYWORDS
Formative Assessment 5
How many and what are the keywords used in the Hello World
program?
-------------------------------------------------------------------------------------------------------
LITERALS
Literals are constant values that are used for performing various
operations and calculations. The different types of literals are:
1. Integer Literals
Integer literals represent integer or numeric values.
Example: 1, 143, -830, 0
3. Boolean Literals
Boolean literals have two possible values: true or false.
4. Character Literals
Character literals represent single characters enclosed in
single quotes (‘ ’).
Example: ‘A’, ‘z’, ‘9’
5. String Literals
String literals represent multiple characters enclosed in
double quotes (““).
Example: “Error”, “Computer Programming”, “1 2 3 Go!”
-------------------------------------------------------------------------------------------------------
DATA TYPES
In Java, there are eight (8) primitive data types: byte, short, int, long,
float, double, boolean, and char. Other programming languages have different
data types with different ranges. For now we will focus on Java data types.
String is not a primitive data type in Java; it is a class that can be used
as a data type that contains multiple characters (numbers, letters and special
characters).
2.5 DDR4
Aspire 3 3.14344
E 802.11ac
true 555
99 z
Given the statement above, identify the different data, the data
types and identifiers that suite the data.
Data/Value Data Type Identifier
-------------------------------------------------------------------------------------------------------
VARIABLES
Example:
//declare a variable named result of data type boolean
boolean result;
//declare a variable named option of data type char
char option;
//assign the character ‘C’ to be the value of variable option
option = ‘C’;
Formative Assessment 8
1. Declare 5 different variables.
2. Declare a variable named age of type int with your age as the initial
value.
5. Assign your full name as the initial value of a String variable named
details.
----------------------------------------------------------------------------------------------------
OPERATORS
Example:
Assuming Expr, Expr1 and Expr2 are boolean expressions.
a. AND (&&)
Expr1 Expr2 Result
true && true true
true && false false
false && true false
false && false false
b. OR (||)
Expr1 Expr2 Result
true || true true
true || false true
false || true true
false || false false
d. NOT (!)
Expr Result
! true false
! false true
Conditional Operator
Expr1?Expr2:Expr3
Formative Assessment 9
Transform the following formulas into programming expressions using
different operators:
Formula Expression
A Length x Width x Height
B 1/2Base x Height
C Pi x Raduis2
b1+b2 x (H)
D
2
E 4Pi x Radius3
F m(c2)
dailyRate x 22 – ((10% of dailyRate
G
x 22) + sss + philhealth)
-------------------------------------------------------------------------------------------------------
Operator Precedence
Example: 8 ÷ 2 (2 + 2 )
For the expression above, some will say the answer is 1 some 16. The
correct answer is 16 because there can only be 1 correct answer.
If programming operators are used for the example above, it will look like
this:
8 / 2 * (2 + 2)
Formative Assessment 10
Evaluate the following expressions:
Provide the result of the following operation if int a = 5, int b = -2, int c = 2
boolean exp1 = a + b * c <= a + c * b;
boolean exp2 = !(c + a > b);
boolean exp3 = b - a >= c;
Evaluate the value of the following expressions:
6 – 2 + 10 % 4 + 7
int result = 4 + 2 / 1 * 3 – 1;
-------------------------------------------------------------------------------------------------------
EXPRESSIONS
Formative Assessment 11
1. Solve the following expressions using different operators:
STATEMENT
Formative Assessment 12
Determine whether the following is a statement or not a
statement.
System.out.print(“I am not a
statement”);
Sum = A + B
int num1, num2;
String FamName;
public class SampleStatement {
-------------------------------------------------------------------------------------------------------
BLOCKS
Formative Assessment 13
1. How many blocks are there in the Hello World program?
3. PROGRAM CODING
Before coding, the programmer must determine the data types of each
variable based on the values. There are 2 versions of the code, 1 for each
version of the program design.
Source Code 1
import javax.swing.JOptionPane;
public class Sum {
public static void main(String [ ]args) {
int num1 = 3;
int num2 = 4;
int sum = num1 + num2;
System.out.println(sum);
} }
Source Code 2
import javax.swing.JOptionPane;
public class Sum {
public static void main(String [ ]args) {
int num1=Integer.parseInt(JOptionPane.showInputDialog(“Enter first
number:”);
int num2 = Integer.parseInt(JOptionPane.showInputDialog(“Enter second
number:”);
int sum = num1 + num2;
System.out.println(sum);
} }
The code in the previous slide can be modified by changing the data type
of the variables to accommodate other types of values.
4. PROGRAM TESTING
The code is not always 100% bug free after writing. The trick is solving
the topmost or the first error first because usually the last error is just a
side effect of the first.
It helps to be observant of formats when debugging code.
Check also the accuracy of the output using different inputs when there
are no more syntax errors.
Formative Assessment 14
Write the code for the Program Design in Formative Assessment 1 #2.
Chapter 2 Summary
Chapter 2 References
[1] Burd, B. (2017). Beginning Programming with Java For Dummies (5th Ed).
New Jersey: John Wiley and Sons, Inc.
[2] Cavida, D.G, Frio, F.M., Flores, D. (2010). Computer Programming I.
Unpublished Workbook, University of Southern Mindanao, Kabacan, Cotabato
[3] Flask, R. (ND). Java for Beginners 2nd Edition [PDF File]. Retrieved from
http://staff.um.edu.mt/__data/assets/pdf_file/0010/57169/jn.pdf
[4] Mayfield, B. (2016). From Problem Analysis to Program Design Lab
Manual (3rd ed.). Philippines: Cengage Learning Asia Pte Ltd.
[5] Module 3: Algorithm Representation. Dragonwins.com. (2010). Retrieved 23
July 2021, from
http://www.dragonwins.com/courses/ECE1021/STATIC/LESSONS/Algorithm
Representation.htm.
[6] Prakash, P. (2015). codeforwin.org. Retrieved 23 July 2021, from
https://codeforwin.org/2015/05/introduction-to-programming-tokens.html.
[7] Usman, O., Owoade, A., Abimbola, B., & Ogunsanwo, G. (2016). (PDF)
INTRODUCTION TO COMPUTER PROGRAMMING (BASIC). ResearchGate.
Retrieved 23 July 2021, from
https://www.researchgate.net/publication/317182495_INTRODUCTION_TO_
COMPUTER_PROGRAMMING_BASIC.
[8] Fulmanski.pl. (1995). Retrieved 23 July 2021, from
https://fulmanski.pl/zajecia/ics/materialy/compalgorithm.pdf.
[9] Nishadha (2021). Retrieved 23 July 2021, from
https://www.google.com.ph/amp/s/creately.com/blog/diagrams/flowchart-
guide-flowchart-tutorial/amp/.
[10] Flowchart - Wikipedia. En.m.wikipedia.org. (2021). Retrieved 23 July 2021,
from https://en.m.wikipedia.org/wiki/Flowchart#History.
[11] Baldwin, R. (2007). ... in Java and C++ by Richard G Baldwin.
Dickbaldwin.com. Retrieved 23 July 2021, from
http://www.dickbaldwin.com/Cosc1315/Pf00120.htm.
[12] Comment (computer programming) - Wikipedia. En.m.wikipedia.org.
(2021). Retrieved 23 July 2021, from
https://en.m.wikipedia.org/wiki/Comment_(computer_programming).
[13] Van Tassel, D. (2004). Comments in programming languages.
Gavilan.edu. Retrieved 23 July 2021, from
http://www.gavilan.edu/csis/languages/comments.html.
[14] Kumar, K. (2021). Java Primitive Data Types. Size, Range and Default
Value of Basic Data Types. cs-fundamentals.com. Retrieved 23 July 2021, from
http://cs-fundamentals.com/java-programming/java-primitive-data-types.php.
Given you have analyzed a problem and created an algorithm for it, the
next step of course is to code it. To create a program using JCreator is simple.
Just follow these steps:
Fig. 18. Writing source code Fig. 19. Double checking file location
Sometimes, even if you have solved the error specified by the software, another
error will appear. That is just some of the limitations of the software. It is not the
software’s fault. Like for example you mistakenly typed a letter in the wrong
case for your class name. In this case, the ^ is below the keyword class. The
software is correct in identifying the line where the error is here but the actual
error is the identifier hello. The identifier here should be identical to your
filename which is Hello. Changing the ‘h’ to ‘H’ will solve the problem.
When you have solved all the errors and all that is left in the Build Output
window is Process Completed alone, then your code is error free and your
output will appear on the General output window just like in Fig. 20.
The program given in the previous example is just a simple program that
will display an output. Following PDLC, if we are to create an analysis for that
and a design it would look like this:
If you can notice, each step in the flowchart has an equivalent code. For
the Start, the class is declared followed by the main() method which is the
starting point of all Java programs. Without it, some codes will still compile but
it will not display any output. Next, inside the main block, are the variable
declarations where 2 variables of type int (since the problem clearly states
whole numbers) num1 and num2 are declared and assigned 3 and 4 to be their
initial values respectively, though those values can be changed anytime. Next
is the process sum which is also declared as a variable of type int and assigned
the value of adding num1 and num2 using the + arithmetic operator. Then the
Installation
For android users, open Play Store and
search for JAVA N-IDE.
Tap Install.
Tap Open when done.
Fig. 26. JAVA N-IDE App
Step 2
After setting up and
tapping OK, a
directory will appear.
Formative Assessment 1
Problem: Create a program that will solve for the average grade of a
1st year student enrolled in the 1st Year 1st semester.
Problem Program Program Coding:
Analysis: Design:
Using JOptionPane
Problem: Create a program that asks the user for a name and display a
message containing the name entered.
Problem Program Design: Program Coding:
Analysis: import javax.swing.JOptionPane;
Output: Start public class InputOutputName {
message public static void main(String [ ]args)
Input: name {
Process:
String name = “”;
message =
String message = “”;
“Hello “ + name get name
+ “!” name =
JOptionPane.showInputDialog
message=”Hello “+name+”!” (“Enter name:”);
sum=num1+num2
JOptionPane.showMessageDialog(null, “Sum: “ +
sum);
Display sum
} }
Stop
The line,
num1 = Integer.parseInt(JOptionPane.showInputDialog(“Enter a
number:”));
prompts the user for an input (Fig. 40) that will be converted to an integer value
through the parseInt() method, and will be assigned as the value of variable
num1. After the user enters a data for num1 (Fig. 41), input for num2 will be
prompted (Fig. 42) and after the user enters a data (Fig. 43) an output will be
displayed (Fig. 33).
Fig. 40. Input Dialog Box for num1 Fig. 41. Assigning Input Value for num1
Fig. 42. Input Dialog Box for num2 Fig. 43. Assigning Input Value for num2
Message and input dialog boxes can be customized wherein the dialog
title and message type can be changed.
For example:
import javax.swing.JOptionPane;
public class KeyboardIO3{
public static void main (String[] args) {
int num1 = 0;
int num2 = 0;
num1 = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter a number:
", "NUMBER", JOptionPane.PLAIN_MESSAGE));
num2 = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter another
number: ", "NUMBER", JOptionPane.PLAIN_MESSAGE));
int sum = num1+num2;
String msg = "The sum is: " + sum;
JOptionPane.showMessageDialog(null, msg, "OUTPUT", 1); } }
The line
num1 = Integer.parseInt(JOptionPane.showInputDialog(null, "Enter a number:
", "NUMBER", JOptionPane.PLAIN_MESSAGE));
customizes the input dialog box (Fig.
45) to have the title NUMBER instead
of Input and plain message as its type.
Fig. 46. Type 1 Output Dialog box Fig. 48. Type 3 Output Dialog box
Formative Assessment 2
1. The clerk of the department wants to have a way to input the basic
information of each new students such as full name, email address,
contact number, and complete home address and will display those data
CHAPTER 3 SUMMARY
To be able to create programs with ease, you must be familiar with the
user interface of the software that you are using like JCreator that has common
features of a regular window and some software specific features. It requires
you to save your file first before you can start coding. It also helps you detect
bugs and suggest solutions but you still have to spend time and effort in
detecting bugs that the software cannot identify.
To help you do program coding faster, it is recommended you follow the
PDLC since if you have analyzed the problem and created a design, all you
have to do is convert it into codes just like in the examples given.
The main() method is the starting point of a Java program and in order
to create programs that are interactive, where your program asks for inputs from
users, you can use pre-defined classes such as JOptioPane. Always mind the
indentation and code grouping so you won’t have a hard time debugging it in
case you have a lot of error and tons of lines of code.
You can display output in 2 different ways: in the General Output
window or in a dialog box. Your prompt messages should be as specific as
possible so that users will not have a hard time figuring out what input is
needed. Same goes to outputs, it should be well labeled. Dialog boxes can be
customized as to the title and type for a more user-friendly look.
If you have familiarized the logic of creating programs in a certain
programming language, it will be easier for you to use other programming
languages since the logic is just the same though some keywords and syntax
might change.
Programming is not easy. But it is also not that hard when you have
constant practice and dedication to what you are doing. It is just like math or
any other course where you have to understand a bunch of terms and
memorize formulas or formats so you can apply it to a bunch of different
situations so you can solve or create a solution for a given problem.
CHAPTER 3 REFERENCES
[1] Burd, B. (2017). Beginning Programming with Java For Dummies (5th Ed).
New Jersey: John Wiley and Sons, Inc.
[2] Cavida, D.G, Frio, F.M., Flores, D. (2010). Computer Programming I.
Unpublished Workbook, University of Southern Mindanao, Kabacan, Cotabato.
[3] Flask, R. (ND). Java for Beginners 2nd Edition [PDF File]. Retrieved from
http://staff.um.edu.mt/__data/assets/pdf_file/0010/57169/jn.pdf
[4] Mayfield, B. (2016). From Problem Analysis to Program Design Lab
Manual (3rd ed.). Philippines: Cengage Learning Asia Pte Ltd.
Appendix A
Appendix B
Appendix C
CHAPTER 1
Formative Assessment 1
1.
CHAPTER 2
Formative Assessment 1
1. a. Final grades for each subject for 1 semester
b. Flowchart
c. Manually compute the average and compare to the output of the
program
2. Step 1
Input: num1, num2, num3
Process: average = (num1 + num2 + num3) /3
Output: average
Step 2
Formative Assessment 2
1. Line Comment
2. Line 1, 3, and 5
Formative Assessment 4
1. Hello, main, args, out, print
2.
Identifiers with only Identifiers with digits Identifiers with
letters allowed special
characters
num num1 num_1
average average2 _average2
sum sum3 sum3_
name name4 name$4
grade grade5 grade5$
3.
Activity 1 There is a space Num_1
String $var
A Ex@mple Special char @
MyVariable i-am-valid Special char -
main 2ndNumber Began with digit
ChessTeam2 _crush
Formative Assessment 5
4: public, class, static, void
Formative Assessment 6
1. Yes, at Line 6 is a string literal.
2.
Integer Floating-point Character String
5 -143.4 ‘A’ “USM”
10 3.1416 ‘b’ “college”
200 1.00 ‘8’ “same as”
350 -2.75 ‘$’ “You passed!”
-30 99.99 ‘*’ “Submit by 5PM”
Formative Assessment 7
1.
2.5 float DDR4 String
Aspire 3 String 3.14344 float
E char 802.11ac String
true boolean 555 short
99 byte z char
2.
Data/Value Data Type Identifier
Danielle String name
15 byte age
1-BSIT String course
99.50 float average
College Scholar String scholarship
Formative Assessment 8
1.
String name = “Danielle”;
byte age = 15;
String course = “1-BSIT”
double average = 99.50;
double tuition = 22314.77;
2. int age = 20;
3. double z = x + y;
4. int ave = (num1+num2+num3) / 3;
5. String details = “Juan A. dela Cruz”;
Formative Assessment 9
Formula Expression
A Length x Width x Height Length * Width * Height
B 1/2Base x Height (Base * Height) / 2
C Pi x Raduis2 Pi * Radius * Radius
b1+b2 x (H)
D ((b1 + b2) / 2) * H
2
E 4Pi x Radius3 4*Pi * Radius * Radius * Radius
F m(c2) m*c*c
dailyRate x 22 – ((10% of dailyRate dailyRate * 22 – (((dailyRate*.10) *
G
x 22) + sss + philhealth) 22) + sss + philHealth)
Formative Assessment 10
Provide the result of the following operation if int a = 5, int b = -2, int c = 2
boolean exp1 = a + b * c <= a + c * b; false
boolean exp2 = !(c + a > b); true
boolean exp3 = b - a >= c; false
Evaluate the value of the following expressions:
6 – 2 + 10 % 4 + 7 13
int result = 4 + 2 / 1 * 3 – 1; 9
Formative Assessment 11
1.
EXPRESSION RESULT
(B + C) / A 50
A*B 20
++C 31
(B > A) true
A-- 0
Answer = A + B 21
C!=B true
C–A 29
A – (B*C) -599
B==C false
Formative Assessment 12
System.out.print(“I am not a statement”); Statement
Sum = A + B Not a Statement
int num1, num2; Statement
String FamName; Statement
public class SampleStatement { Not a Statement
Formative Assessment 13
1. 2 blocks
2. 4 bolcks
Formative Assessment 14
import javax.swing.JOptionPane;
public class average {
public static void main (String [ ]args) {
int num1=Integer.parseInt(JOptionPane.showInputDialog(“Enter a number: “));
int num2=Integer.parseInt(JOptionPane.showInputDialog(“Enter a number: “));
int num3=Integer.parseInt(JOptionPane.showInputDialog(“Enter a number: “));
int average = (num1+num2+num3)/3;
System.out.print(average);
}}
CHAPTER 3
Formative Assessment 1
Problem Analysis: Program Design: Program Coding:
Input: None public class _1SemAveGrade{
Start CS112=85
public static void main (String[] args) {
Process: double CS112 = 85;
SocSci1=90 CS113=90
CS112 = 85 double CS113 = 90;
CS113 = 90 double CS114 = 85;
CS114 = 85 PE1=90 CS114=85 double GE1 = 85;
GE1 = 85 double SocSci1 = 90;
SocSci1 = 90 NSTP=90 GE1=85 double PE1 = 90;
PE1 = 90 double NSTP = 90;
NSTP = 90 average= CS112 +CS113 double average = (CS112 +CS113 +CS114
+CS114 +GE1 +SocSci1 +GE1 +SocSci1 +PE1 +NSTP) / 7;
average = +PE1 +NSTP) / 7
System.out.println("Your average grade for
(CS112+CS113+C this semester is: " + average);
S114+GE1+SocSci display average }
1+PE1+NSTP)/7; }
display info
JOptionPane.showMessageDialog
(null, info);
}
}
Stop
2.
Problem Program Design: Program Coding:
Analysis: import javax.swing.JOptionPane;
Start dailyRate=500
Input: public class SalaryCalculator{
emName, public static void main (String[] args) {
daysWorked sss=220 philHealth=330 int dailyRate = 500;
int philHealth = 330;
Process: int sss = 220;
get empName
dailyRate = 500 String empName =
philHealth = 330 JOptionPane.showInputDialog ("Enter
sss = 220 get daysWorked Employee's Full Name: ");
monthlySalary = int daysWorked = Integer.parseInt
(dailyRate * (JOptionPane.showInputDialog("Enter
daysWorked) - monthlySalary=(dailyRate * Number of Days Worked for the month:
daysWorked) - "));
(sss + philHealth)
(sss+philHealth)
output = "PAY double monthlySalary = (dailyRate *
SLIP \n\n" + daysWorked) - (sss+philHealth);
"Employee Name: String output = "PAY SLIP \n\n" +
output = "PAY SLIP \n\n" +
" + empName+ "Employee Name: " + empName+ "Employee Name: " + empName+
"\nMonthly Salary: "\nMonthly Salary: " + "\nMonthly Salary: " + monthlySalary+ "
monthlySalary+ " pesos" pesos";
" + monthlySalary+
" pesos" JOptionPane.showMessageDialog(null,
output);
Output: display output Stop }
output }