SlideShare a Scribd company logo
COMPSCI 121: INTRODUCTION TO
PROGRAMMING
FALL 2019
WHAT ARE THE GOALS FOR TODAY’S CLASS
• Introduce you to some java
programming constructs.
• Introduce you to problem solving
techniques.
• Demo: using jGRASP
• Point out good programming practices.
2
LET’S PRACTICE T-P-S
Think
How do you learn best? (2 mins)
Pair
Share your thoughts with
your neighbor (2 mins)
Share
A few insights with the class (2 mins)
3
WHY ARE WE USING JAVA?
4
● Java is a widely used language in
industry.
● Knowledge of Java is in high demand.
● It is a mature language (1995) and is
frequently updated.
● Helps you learn other languages.
● Created as a “Software Engineering”
language so that large programs can be
more easily developed and maintained.
● It is designed to support software best
practices.
WHY ARE WE USING JAVA?
TIOBE Index for August 2019
https://www.tiobe.com/tiobe-index/
5
6
QUESTIONS?LET’S START PROGRAMMING
PROGRAMMING STEPS & PATTERN
7
Best to write a little
code, test it,
debug (find and
remove errors) if
test(s) failed, or
continue to write
more code if the
test(s) passed.
Note:
A computer can only
execute one step at a
time. Each step must be
clearly defined.
PROGRAMMING STEPS
All programming has this pattern:
8
Read and analyze all aspects of the
problem the program is to address.
Make sure you understand what the
program should do- its logic. What are
the inputs and outputs to the program?
Write a step-by-step process, an
algorithm, that will use the input to
produce the expected output.
Write code that will correctly
implement some or all of the
algorithm.
Test some or all of the program:
compare program output to correct
output given a set of inputs.
Continue to
develop the
program or
debug if any
tests did not
pass.
BAKING ANALOGY
• Problem: I want some banana bread.
• Input: The ingredients.
• Output: Warm banana bread to eat!
• Test: Must be edible and must look and taste like
banana bread.
• Algorithm: A step-by-step plan, like a recipe, for
getting from the Input to the Output.
• Implementation: in this case, ME!
9
AN ALGORITHM YOU CAN ENJOY!
10
1. Preheat oven to 350 degrees F (175 degrees C).
2. Lightly grease a 9x5 inch loaf pan.
3. In a large bowl, combine flour, baking soda and salt.
4. In a separate bowl, cream together butter and brown sugar.
5. Stir in eggs and mashed bananas until well blended.
6. Stir banana mixture into flour mixture; stir just to moisten.
7. Pour batter into prepared loaf pan.
8. Bake in preheated oven for 60 to 65 minutes.
9. Bake until a toothpick inserted into center of the loaf comes out
clean.
10. Let bread cool in pan for 10 minutes.
11. Turn out onto a wire rack.
12. Test the output!
In this case, there is no way to partially
implement the algorithm, so if the test
fails, you’ll have to start over!
HOW DOES PROGRAMMING IN JAVA WORK?
1. The problem is analyzed
and understood.
2. Inputs and outputs
defined.
3. An algorithm is
designed.
4. Then, Java code is
written in one or more
source code files.
5. This file is compiled and
run.
6. The output is generated.
7. Tests can be run on the
output.
11
DEMO IN zyBooks AND JGRASP
Saving files in folders
Compiling & running the Salary program (from zyBooks).
Printing in single/new lines.
Making/removing syntax errors.
12
PROBLEM STATEMENT & ANALYSIS
Write a program that calculates the annual salary
given the hourly wage.
1. What are the inputs?
2. What are the outputs?
THINK - PAIR - SHARE!
13
DESIGN THE ALGORITHM
Write a program that calculates the annual salary
given the hourly wage.
1. What are the inputs? hourly wage
2. What are the outputs? annual salary
3. What is the algorithm (steps) for the program?
THINK - PAIR - SHARE!
14
DESIGN THE ALGORITHM
3. What is the algorithm (steps) for the program?
1. Get the hourly rate (for example, from user).
hourlyWage = ?
2. Calculate the annual salary:
hoursPerWeek = 40, weeksPerYear = 50
annSalary = hourlyWage * hoursPerWeek * weeksPerYear
3. Print the result.
15
WRITE THE JAVA CODE - CHECK FOR ERRORS
16
Line numbers Class name
Variable assignment
Output statements
Semi-colons
DEMO IN
JGRASP
{ } braces for scope
Declare a variable
Note: Code in jGRASP is color-coded
CLICKER QUESTION #1
On which line does the program start when it runs?
A. On the first line of the program public class Salary
B. With the main statement public static void main
C. With the print statement System.out.print
17
ANSWER CLICKER QUESTION #1
On which line does the program start?
A. On the first line of the program public class Salary
B. With the main statement public static void main
C. With the print statement System.out.print
18
HOW DO WE ASSIGN VALUES TO VARIABLES?
Assignment statements: create a variable and assign a
value to it.
int num = 450;
• LHS has to be a variable, RHS has to resolve to a value.
19
value
assignment
operator
data
type variable
name
RHSLHS
“Declaration” of the variable
“num” with data type “int”.
It also assigns the value 450 to
that variable.
ASSIGNMENT IN JAVA: WHAT HAPPENS IN MEMORY
20
EXAMPLE:
After the execution of the last statement, the variable “num1” now
references an integer value of 3.
State diagram
ASSIGNMENT IN JAVA: WHAT HAPPENS IN MEMORY
21
Notice that you declare a variable only once,
but can use it as much as necessary once it’s
declared.
You cannot re-declare a variable:
int a = 450;
int a = 450;
int a = 22;
declaration OK
re-declaration Not OK
You can re-assign a variable:
int a = 450;
a = 22; re-assignment OK
CLICKER QUESTION 2
Which variable holds the highest number?
1. int num = 14;
2. int num2 = (num + 1);
3. int num3 = num2;
4. num2 = num3 + 3;
5. num = 17;
A. num
B. num2
C. num3 22
ANSWER CLICKER QUESTION 2
Which variable holds the highest number?
1. int num = 14;
2. int num2 = (num + 1);
3. int num3 = num2;
4. num2 = num3 + 3;
5. num = 17;
A. num = 17
B. num2 = 18
C. num3 = 15 23
HOW DID WE SHOW THE OUTPUT TO THE USER?
24
Uses "" to output a string literal.
Multiple output statements continue printing
on the same output line.
Uses "" to output a string literal.
Starts a new output line after the
outputted values, called a newline.
CLICKER QUESTION 3
Given this code (assume variables have been declared):
hourlyWage = 20, hoursPerWeek = 40, weeksPerYear = 50;
annSalary = hourlyWage * hoursPerWeek * weeksPerYear;
Which one does not print 40000?
A. System.out.print(annSalary);
B. System.out.print(hourlyWage * hoursPerWeek *
weeksPerYear);
C. System.out.print(“annSalary”);
D. System.out.print(20 * 40 * 50);
25
CLICKER QUESTION 3
Given this code (assume variables have been declared):
hourlyWage = 20, hoursPerWeek = 40, weeksPerYear = 50;
annSalary = hourlyWage * hoursPerWeek * weeksPerYear;
Which one does not print 40000?
A. System.out.print(annSalary);
B. System.out.print(hourlyWage * hoursPerWeek *
weeksPerYear);
C. System.out.print(“annSalary”);
D. System.out.print(20 * 40 * 50); 26
PROBLEM: HOW DO WE GET USER INPUT FOR OUR PROGRAM?
For our Salary program, we want the user to input the wage from
the keyboard.
Solution: we use the special Java text parser called Scanner.
Steps:
1. Create a Scanner object: Scanner scnr = new Scanner(System.in);
System.in corresponds to keyboard input.
2. Given Scanner object scnr, get an input value and assign to a
variable with scnr.nextInt()
scnr.nextInt()is a function (method) that gets the input
value of type integer (int)
27
USING SCANNER TO GET USER INPUT FROM KEYBOARD
28
Import the Scanner class
Create instance
Scanner method
TESTING FOR LOGIC ERRORS
29
Now let’s calculate the monthly salary.
What if our program works but the output is wrong?
GRADING CRITERIA OF PROGRAMMING PROJECTS
Code Style: follows good style (as defined in the course
material). This means your code is readable to you and to
others. This is professional “best practice”.
Code Compiles: A program that doesn't compile cannot run and
is not a successful program. This program does not get credit.
Logical Correctness: The code is logically correct if it runs and
produces the correct output.
30
CLICKER QUESTION 4
A. All that glittersis not gold.
B. All that glitters is not gold.
C. All that glitters isnot gold.
D. All that glitters is not gold.
What is the output of running this file?
31
CLICKER QUESTION 4 ANSWER
A. All that glittersis not gold.
B. All that glitters is not gold.
C. All that glitters isnot gold.
D. All that glitters is not gold.
What is the output of running this file?
Watch
white
spaces!
32
SOME GOOD PROGRAMMING PRACTICES
1. Create a good solution (algorithm) first, before you start coding.
2. Compile after writing only a few lines of code, rather than writing
tens of lines and then compiling.
3. Make incremental changes— Don't try to change everything at
once.
4. Focus on fixing just the first error reported by the compiler, and
then re-compiling.
5. When you don't find an error at a specified line, look to previous
lines.
6. Be careful not type the number "1" or a capital I in
System.out.println.
7. Do not type numbers directly in the output statements; use the
variables.
33
Week 1 TODO List:
1. Register your iClicker in Moodle.
2. Install OpenJDK and jGRASP.
3. Complete zyBook chapter 1 exercises.
4. Attend lab on Friday with your laptop.
5. Read the course documents (Moodle).
6.Give your consent to use Gradescope.
7.Complete the Orientation Quiz in Moodle.
8.Ask questions in Piazza.
34

More Related Content

Similar to Week 1

Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.com
WilliamsTaylorza48
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.com
Stephenson22
 
Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0
PMILebanonChapter
 
Week 5
Week 5Week 5
Week 5
EasyStudy3
 
Week 5
Week 5Week 5
Week 5
EasyStudy3
 
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docxCOMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
donnajames55
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle
Frankie Jones
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
ssusere336f4
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docx
todd331
 
CODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtryCODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtry
kapib57390
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
iamluqman0403
 
Understanding Simple Program Logic
Understanding Simple Program LogicUnderstanding Simple Program Logic
Understanding Simple Program Logic
Ar Kyu Dee
 
Flowcharting week 5 2019 2020
Flowcharting week 5  2019  2020Flowcharting week 5  2019  2020
Flowcharting week 5 2019 2020
Osama Ghandour Geris
 
Cis 115 Education Redefined-snaptutorial.com
Cis 115 Education Redefined-snaptutorial.comCis 115 Education Redefined-snaptutorial.com
Cis 115 Education Redefined-snaptutorial.com
robertledwes38
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
noahjamessss
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
cskvsmi44
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
VAIBHAVKADAGANCHI
 
Programing Fundamental
Programing FundamentalPrograming Fundamental
Programing Fundamental
Qazi Shahzad Ali
 
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structures
Micheal Ogundero
 
TDD: seriously, try it! 
TDD: seriously, try it! TDD: seriously, try it! 
TDD: seriously, try it! 
Nacho Cougil
 

Similar to Week 1 (20)

Cmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.comCmis 102 Success Begins / snaptutorial.com
Cmis 102 Success Begins / snaptutorial.com
 
Cmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.comCmis 102 Enthusiastic Study / snaptutorial.com
Cmis 102 Enthusiastic Study / snaptutorial.com
 
Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0Monte Carlo Simulation for project estimates v1.0
Monte Carlo Simulation for project estimates v1.0
 
Week 5
Week 5Week 5
Week 5
 
Week 5
Week 5Week 5
Week 5
 
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docxCOMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
COMP 2213X2 Assignment #2 Parts A and BDue February 3 in cla.docx
 
2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle2.2 Demonstrate the understanding of Programming Life Cycle
2.2 Demonstrate the understanding of Programming Life Cycle
 
classVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptxclassVII_Coding_Teacher_Presentation.pptx
classVII_Coding_Teacher_Presentation.pptx
 
Sample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docxSample Questions The following sample questions are not in.docx
Sample Questions The following sample questions are not in.docx
 
CODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtryCODE TUNINGtertertertrtryryryryrtytrytrtry
CODE TUNINGtertertertrtryryryryrtytrytrtry
 
Java developer trainee implementation and import
Java developer trainee implementation and importJava developer trainee implementation and import
Java developer trainee implementation and import
 
Understanding Simple Program Logic
Understanding Simple Program LogicUnderstanding Simple Program Logic
Understanding Simple Program Logic
 
Flowcharting week 5 2019 2020
Flowcharting week 5  2019  2020Flowcharting week 5  2019  2020
Flowcharting week 5 2019 2020
 
Cis 115 Education Redefined-snaptutorial.com
Cis 115 Education Redefined-snaptutorial.comCis 115 Education Redefined-snaptutorial.com
Cis 115 Education Redefined-snaptutorial.com
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
 
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-stringsDevry cis-170-c-i lab-5-of-7-arrays-and-strings
Devry cis-170-c-i lab-5-of-7-arrays-and-strings
 
Introduction to C ++.pptx
Introduction to C ++.pptxIntroduction to C ++.pptx
Introduction to C ++.pptx
 
Programing Fundamental
Programing FundamentalPrograming Fundamental
Programing Fundamental
 
csharp repitition structures
csharp repitition structurescsharp repitition structures
csharp repitition structures
 
TDD: seriously, try it! 
TDD: seriously, try it! TDD: seriously, try it! 
TDD: seriously, try it! 
 

More from EasyStudy3

Week 7
Week 7Week 7
Week 7
EasyStudy3
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
EasyStudy3
 
Week 6
Week 6Week 6
Week 6
EasyStudy3
 
2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolation
EasyStudy3
 
Chapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish completeChapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish complete
EasyStudy3
 
L6
L6L6
Chapter 5
Chapter 5Chapter 5
Chapter 5
EasyStudy3
 
2
22
Lec#4
Lec#4Lec#4
Lec#4
EasyStudy3
 
Chapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space mergedChapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space merged
EasyStudy3
 
Chpater 6
Chpater 6Chpater 6
Chpater 6
EasyStudy3
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
EasyStudy3
 
Lec#3
Lec#3Lec#3
Lec#3
EasyStudy3
 
Chapter 16 2
Chapter 16 2Chapter 16 2
Chapter 16 2
EasyStudy3
 
Chapter 5 gen chem
Chapter 5 gen chemChapter 5 gen chem
Chapter 5 gen chem
EasyStudy3
 
Topic 4 gen chem guobi
Topic 4 gen chem guobiTopic 4 gen chem guobi
Topic 4 gen chem guobi
EasyStudy3
 
Gen chem topic 3 guobi
Gen chem topic 3  guobiGen chem topic 3  guobi
Gen chem topic 3 guobi
EasyStudy3
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
EasyStudy3
 
Gen chem topic 1 guobi
Gen chem topic 1 guobiGen chem topic 1 guobi
Gen chem topic 1 guobi
EasyStudy3
 
Chapter1 f19 bb(1)
Chapter1 f19 bb(1)Chapter1 f19 bb(1)
Chapter1 f19 bb(1)
EasyStudy3
 

More from EasyStudy3 (20)

Week 7
Week 7Week 7
Week 7
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Week 6
Week 6Week 6
Week 6
 
2. polynomial interpolation
2. polynomial interpolation2. polynomial interpolation
2. polynomial interpolation
 
Chapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish completeChapter2 slides-part 2-harish complete
Chapter2 slides-part 2-harish complete
 
L6
L6L6
L6
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
2
22
2
 
Lec#4
Lec#4Lec#4
Lec#4
 
Chapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space mergedChapter 12 vectors and the geometry of space merged
Chapter 12 vectors and the geometry of space merged
 
Chpater 6
Chpater 6Chpater 6
Chpater 6
 
Chapter 5
Chapter 5Chapter 5
Chapter 5
 
Lec#3
Lec#3Lec#3
Lec#3
 
Chapter 16 2
Chapter 16 2Chapter 16 2
Chapter 16 2
 
Chapter 5 gen chem
Chapter 5 gen chemChapter 5 gen chem
Chapter 5 gen chem
 
Topic 4 gen chem guobi
Topic 4 gen chem guobiTopic 4 gen chem guobi
Topic 4 gen chem guobi
 
Gen chem topic 3 guobi
Gen chem topic 3  guobiGen chem topic 3  guobi
Gen chem topic 3 guobi
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Gen chem topic 1 guobi
Gen chem topic 1 guobiGen chem topic 1 guobi
Gen chem topic 1 guobi
 
Chapter1 f19 bb(1)
Chapter1 f19 bb(1)Chapter1 f19 bb(1)
Chapter1 f19 bb(1)
 

Recently uploaded

math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
Nguyen Thanh Tu Collection
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Fajar Baskoro
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Leena Ghag-Sakpal
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
TechSoup
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
Chevonnese Chevers Whyte, MBA, B.Sc.
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 

Recently uploaded (20)

math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
BÀI TẬP DẠY THÊM TIẾNG ANH LỚP 7 CẢ NĂM FRIENDS PLUS SÁCH CHÂN TRỜI SÁNG TẠO ...
 
Pengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptxPengantar Penggunaan Flutter - Dart programming language1.pptx
Pengantar Penggunaan Flutter - Dart programming language1.pptx
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
Bed Making ( Introduction, Purpose, Types, Articles, Scientific principles, N...
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
Leveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit InnovationLeveraging Generative AI to Drive Nonprofit Innovation
Leveraging Generative AI to Drive Nonprofit Innovation
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Constructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective CommunicationConstructing Your Course Container for Effective Communication
Constructing Your Course Container for Effective Communication
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 

Week 1

  • 1. COMPSCI 121: INTRODUCTION TO PROGRAMMING FALL 2019
  • 2. WHAT ARE THE GOALS FOR TODAY’S CLASS • Introduce you to some java programming constructs. • Introduce you to problem solving techniques. • Demo: using jGRASP • Point out good programming practices. 2
  • 3. LET’S PRACTICE T-P-S Think How do you learn best? (2 mins) Pair Share your thoughts with your neighbor (2 mins) Share A few insights with the class (2 mins) 3
  • 4. WHY ARE WE USING JAVA? 4 ● Java is a widely used language in industry. ● Knowledge of Java is in high demand. ● It is a mature language (1995) and is frequently updated. ● Helps you learn other languages. ● Created as a “Software Engineering” language so that large programs can be more easily developed and maintained. ● It is designed to support software best practices.
  • 5. WHY ARE WE USING JAVA? TIOBE Index for August 2019 https://www.tiobe.com/tiobe-index/ 5
  • 7. PROGRAMMING STEPS & PATTERN 7 Best to write a little code, test it, debug (find and remove errors) if test(s) failed, or continue to write more code if the test(s) passed. Note: A computer can only execute one step at a time. Each step must be clearly defined.
  • 8. PROGRAMMING STEPS All programming has this pattern: 8 Read and analyze all aspects of the problem the program is to address. Make sure you understand what the program should do- its logic. What are the inputs and outputs to the program? Write a step-by-step process, an algorithm, that will use the input to produce the expected output. Write code that will correctly implement some or all of the algorithm. Test some or all of the program: compare program output to correct output given a set of inputs. Continue to develop the program or debug if any tests did not pass.
  • 9. BAKING ANALOGY • Problem: I want some banana bread. • Input: The ingredients. • Output: Warm banana bread to eat! • Test: Must be edible and must look and taste like banana bread. • Algorithm: A step-by-step plan, like a recipe, for getting from the Input to the Output. • Implementation: in this case, ME! 9
  • 10. AN ALGORITHM YOU CAN ENJOY! 10 1. Preheat oven to 350 degrees F (175 degrees C). 2. Lightly grease a 9x5 inch loaf pan. 3. In a large bowl, combine flour, baking soda and salt. 4. In a separate bowl, cream together butter and brown sugar. 5. Stir in eggs and mashed bananas until well blended. 6. Stir banana mixture into flour mixture; stir just to moisten. 7. Pour batter into prepared loaf pan. 8. Bake in preheated oven for 60 to 65 minutes. 9. Bake until a toothpick inserted into center of the loaf comes out clean. 10. Let bread cool in pan for 10 minutes. 11. Turn out onto a wire rack. 12. Test the output! In this case, there is no way to partially implement the algorithm, so if the test fails, you’ll have to start over!
  • 11. HOW DOES PROGRAMMING IN JAVA WORK? 1. The problem is analyzed and understood. 2. Inputs and outputs defined. 3. An algorithm is designed. 4. Then, Java code is written in one or more source code files. 5. This file is compiled and run. 6. The output is generated. 7. Tests can be run on the output. 11
  • 12. DEMO IN zyBooks AND JGRASP Saving files in folders Compiling & running the Salary program (from zyBooks). Printing in single/new lines. Making/removing syntax errors. 12
  • 13. PROBLEM STATEMENT & ANALYSIS Write a program that calculates the annual salary given the hourly wage. 1. What are the inputs? 2. What are the outputs? THINK - PAIR - SHARE! 13
  • 14. DESIGN THE ALGORITHM Write a program that calculates the annual salary given the hourly wage. 1. What are the inputs? hourly wage 2. What are the outputs? annual salary 3. What is the algorithm (steps) for the program? THINK - PAIR - SHARE! 14
  • 15. DESIGN THE ALGORITHM 3. What is the algorithm (steps) for the program? 1. Get the hourly rate (for example, from user). hourlyWage = ? 2. Calculate the annual salary: hoursPerWeek = 40, weeksPerYear = 50 annSalary = hourlyWage * hoursPerWeek * weeksPerYear 3. Print the result. 15
  • 16. WRITE THE JAVA CODE - CHECK FOR ERRORS 16 Line numbers Class name Variable assignment Output statements Semi-colons DEMO IN JGRASP { } braces for scope Declare a variable Note: Code in jGRASP is color-coded
  • 17. CLICKER QUESTION #1 On which line does the program start when it runs? A. On the first line of the program public class Salary B. With the main statement public static void main C. With the print statement System.out.print 17
  • 18. ANSWER CLICKER QUESTION #1 On which line does the program start? A. On the first line of the program public class Salary B. With the main statement public static void main C. With the print statement System.out.print 18
  • 19. HOW DO WE ASSIGN VALUES TO VARIABLES? Assignment statements: create a variable and assign a value to it. int num = 450; • LHS has to be a variable, RHS has to resolve to a value. 19 value assignment operator data type variable name RHSLHS “Declaration” of the variable “num” with data type “int”. It also assigns the value 450 to that variable.
  • 20. ASSIGNMENT IN JAVA: WHAT HAPPENS IN MEMORY 20 EXAMPLE: After the execution of the last statement, the variable “num1” now references an integer value of 3. State diagram
  • 21. ASSIGNMENT IN JAVA: WHAT HAPPENS IN MEMORY 21 Notice that you declare a variable only once, but can use it as much as necessary once it’s declared. You cannot re-declare a variable: int a = 450; int a = 450; int a = 22; declaration OK re-declaration Not OK You can re-assign a variable: int a = 450; a = 22; re-assignment OK
  • 22. CLICKER QUESTION 2 Which variable holds the highest number? 1. int num = 14; 2. int num2 = (num + 1); 3. int num3 = num2; 4. num2 = num3 + 3; 5. num = 17; A. num B. num2 C. num3 22
  • 23. ANSWER CLICKER QUESTION 2 Which variable holds the highest number? 1. int num = 14; 2. int num2 = (num + 1); 3. int num3 = num2; 4. num2 = num3 + 3; 5. num = 17; A. num = 17 B. num2 = 18 C. num3 = 15 23
  • 24. HOW DID WE SHOW THE OUTPUT TO THE USER? 24 Uses "" to output a string literal. Multiple output statements continue printing on the same output line. Uses "" to output a string literal. Starts a new output line after the outputted values, called a newline.
  • 25. CLICKER QUESTION 3 Given this code (assume variables have been declared): hourlyWage = 20, hoursPerWeek = 40, weeksPerYear = 50; annSalary = hourlyWage * hoursPerWeek * weeksPerYear; Which one does not print 40000? A. System.out.print(annSalary); B. System.out.print(hourlyWage * hoursPerWeek * weeksPerYear); C. System.out.print(“annSalary”); D. System.out.print(20 * 40 * 50); 25
  • 26. CLICKER QUESTION 3 Given this code (assume variables have been declared): hourlyWage = 20, hoursPerWeek = 40, weeksPerYear = 50; annSalary = hourlyWage * hoursPerWeek * weeksPerYear; Which one does not print 40000? A. System.out.print(annSalary); B. System.out.print(hourlyWage * hoursPerWeek * weeksPerYear); C. System.out.print(“annSalary”); D. System.out.print(20 * 40 * 50); 26
  • 27. PROBLEM: HOW DO WE GET USER INPUT FOR OUR PROGRAM? For our Salary program, we want the user to input the wage from the keyboard. Solution: we use the special Java text parser called Scanner. Steps: 1. Create a Scanner object: Scanner scnr = new Scanner(System.in); System.in corresponds to keyboard input. 2. Given Scanner object scnr, get an input value and assign to a variable with scnr.nextInt() scnr.nextInt()is a function (method) that gets the input value of type integer (int) 27
  • 28. USING SCANNER TO GET USER INPUT FROM KEYBOARD 28 Import the Scanner class Create instance Scanner method
  • 29. TESTING FOR LOGIC ERRORS 29 Now let’s calculate the monthly salary. What if our program works but the output is wrong?
  • 30. GRADING CRITERIA OF PROGRAMMING PROJECTS Code Style: follows good style (as defined in the course material). This means your code is readable to you and to others. This is professional “best practice”. Code Compiles: A program that doesn't compile cannot run and is not a successful program. This program does not get credit. Logical Correctness: The code is logically correct if it runs and produces the correct output. 30
  • 31. CLICKER QUESTION 4 A. All that glittersis not gold. B. All that glitters is not gold. C. All that glitters isnot gold. D. All that glitters is not gold. What is the output of running this file? 31
  • 32. CLICKER QUESTION 4 ANSWER A. All that glittersis not gold. B. All that glitters is not gold. C. All that glitters isnot gold. D. All that glitters is not gold. What is the output of running this file? Watch white spaces! 32
  • 33. SOME GOOD PROGRAMMING PRACTICES 1. Create a good solution (algorithm) first, before you start coding. 2. Compile after writing only a few lines of code, rather than writing tens of lines and then compiling. 3. Make incremental changes— Don't try to change everything at once. 4. Focus on fixing just the first error reported by the compiler, and then re-compiling. 5. When you don't find an error at a specified line, look to previous lines. 6. Be careful not type the number "1" or a capital I in System.out.println. 7. Do not type numbers directly in the output statements; use the variables. 33
  • 34. Week 1 TODO List: 1. Register your iClicker in Moodle. 2. Install OpenJDK and jGRASP. 3. Complete zyBook chapter 1 exercises. 4. Attend lab on Friday with your laptop. 5. Read the course documents (Moodle). 6.Give your consent to use Gradescope. 7.Complete the Orientation Quiz in Moodle. 8.Ask questions in Piazza. 34