Java Review & Functional Decomposition in CSE 122 Spring 2023

 
Java Review &
Functional Decomposition
 
Talk to your neighbors:
What is your favorite
restaurant around UW?
 
BEFORE WE START
 
Lecture Outline
 
Announcements/Reminders
Review Java
Functional Decomposition
Code Quality
First Assignment
-
Grading
 
Announcements
 
Ho
pe you had fun in your first quiz section yesterday!
Java Review Session Monday 4/3
GUG 220, 2:30pm-3:30pm
IPL
 will open on Monday!
Programming Assignment 0 (P0) released later today
Due next Thurs (4/6)
Focused on Java Review
 
Lecture Outline
 
Announcements/Reminders
Review Java
Functional Decomposition
Code Quality
First Assignment
-
Grading
 
Reminders: Review Java Syntax
 
Java Tutorial
 
reviews all the relevant programming features you should
familiar with (even if you don’t know them in Java).
-
Printing and comments
-
Variables, types, expressions
-
Conditionals (if/else if/ else)
-
Loops (for and while)
-
Strings
-
Methods
-
File I/O
-
Arrays
In-Class Activities
 
Goal
: Get you actively participating in your learning
Typical Activity
-
Question is posed
-
Think
 
(1 min): Think about the question on your own
-
Pair
 
(2 min): Talk with your neighbor to discuss question
-
If you arrive at different conclusions, discuss your logic and figure out why you differ!
-
If you arrived at the same conclusion, discuss why the other answers might be wrong!
-
Share
 
(1 min): We discuss the conclusions as a class
During each of the 
Think
 
and 
Pair
 stages, you will respond to the
question via a sli.do poll
-
Not worth any points, just here to help you learn!
 
What is the output of this Java program?
public class 
Demo {
   
public static void 
main
(String[] args) {
      
int
[] nums = {
2
, 
3
, 
5
, 
9
, 
14
};
      
int 
totalDiff = 
0
;
      
for 
(
int 
i = 
1
; i <= nums.
length
; i++) {
         totalDiff += (nums[i] - nums[i - 
1
]);
      }
      System.
out
.println(
"Total Diff = ” 
+ totalDiff);
   }
}
 
A)
 
Total Diff = 12
B)
 
Total Diff = 11
C)
 
Total Diff = 7
D)
 
Error
 
What is the output of this Java program?
public class 
Demo {
   
public static void 
main
(String[] args) {
      
int
[] nums = {
2
, 
3
, 
5
, 
9
, 
14
};
      
int 
totalDiff = 
0
;
      
for 
(
int 
i = 
1
; i <= nums.
length
; i++) {
         totalDiff += (nums[i] - nums[i - 
1
]);
      }
      System.
out
.println(
"Total Diff = ” 
+ totalDiff);
   }
}
 
A)
 
Total Diff = 12
B)
 
Total Diff = 11
C)
 
Total Diff = 7
D)
 
Error
 
Practice : Pair
What is the output of this Java program?
public class 
Demo {
   
public static void 
main
(String[] args) {
      
int
[] nums = {
2
, 
3
, 
5
, 
9
, 
14
};
      
int 
totalDiff = 
0
;
      
for 
(
int 
i = 
1
; i <= nums.
length
; i++) {
         totalDiff += (nums[i] - nums[i - 
1
]);
      }
      System.
out
.println(
"Total Diff = ” 
+ totalDiff);
   }
}
A)
 
Total Diff = 12
B)
 
Total Diff = 11
C)
 
Total Diff = 7
D)
 
Error
Practice : 
Share
throws an 
IndexOutOfBoundsException
 
Case Study: Temperatures
 
Write a program to prompt the user for how many days’ temperatures they
want to enter, then asks the user for the temperatures of that many days. The
program should then report the highest temperature that occurred and what
day it occurred on. The program then should allow the user to ask for the
average temperature across a range of days, and report how many of those
days were above average.
 
Review skills
-
User input
-
For loops
-
Arrays
-
Maximum calculation
-
Cumulative sum
How many days' temperatures? 
7
Day 0's high temp: 
45
Day 1's high temp: 
44
Day 2's high temp: 
39
Day 3's high temp: 
48
Day 4's high temp: 
37
Day 5's high temp: 
46
Day 6's high temp: 
53
The highest temperature was on day 6 and was
53.
 
What range of days are you interested in? 
2 5
Average temperature was 42.5
2 days were above average.
 
Lecture Outline
 
Announcements/Reminders
Review Java
Functional Decomposition
Code Quality
First Assignment
-
Grading
Functional Decomposition
Functional decomposition 
is the process of breaking down a complex
problem or system into parts that are easier to 
conceive, understand,
program, 
and 
maintain.
“Bake the cookies”
Functional Decomposition
Functional decomposition 
in code means break down a program into
smaller methods (also called functions).
Temperatures program
1.
Read in temperature data
2.
Finding the hottest day
3.
Finding the average on a range
4.
Reporting stats on a range
 
Avoid Trivial Methods
 
Introduce methods to decompose a complex problem, not just for the sake
of adding a method.
Bad example:
     
Good Example:
 
 
 
 
Rule of thumb: A method should do at least two steps
-
Ask yourself: Does adding this method make my code easier to understand?
public static void 
printMessage
(String message) {
    System.
out
.println(message);
}
public static double 
round
(
double 
num) {
    
return 
((
int
) Math.round(num * 
10
)) / 
10.0
;
}
 
Lecture Outline
 
Announcements/Reminders
Review Java
Functional Decomposition
Code Quality
First Assignment
-
Grading
 
Code Quality
 
“Programs are meant to be read by humans and only incidentally for
computers to execute.” – Abelson & Sussman, SICP
 
Code is about 
communication. 
Writing code with good 
code quality 
is
important to communicate effectively.
 
Different organizations have different 
standards 
for code quality.
-
Doesn’t mean any one standard is wrong! (e.g., APA, MLA, Chicago, IEEE, ...)
-
Consistency is very helpful within a group project
-
See our 
Code Quality Guide
 for the standards we will all use in CSE 122
 
What does this code do? How could you improve
the quality of this code? 
(No Slido poll)
public static int 
l
(String a,
char 
b){
       
int 
j=-
1
;
for
(
int 
a1=
0
;a1<a.length();a1   ++) {
  
if 
(a.charAt(a1) == b) {
        j = a1;
            } } 
if
(j==-
1
){
return 
-
1
;} 
else 
{
 
return 
j;} }
 
What does this code do? How could you improve
the quality of this code? 
(No Slido poll)
public static int 
l
(String a, 
char 
b)  {
    
int 
j=-
1
;
    
for
(
int 
a1=
0
;a1<a.length();a1     ++) {
if 
(a.charAt(a1) == b) {
    j = a1;
        }
    }
    
if
(j==-
1
) {
        
return 
-
1
;
        } 
else 
{
            
return 
j;
        }
}
 
CSE 122 Code Quality
 
Examples relevant for this week
Correctly formatted variable, class, and method names
Descriptive variable names
Indentation
No l
ong lines (
generally < 80 chars)
Spacing
Good method decomposition
Writing documentation - class and method comments
 
Lecture Outline
 
Announcements/Reminders
Review Java
Functional Decomposition
Code Quality
First Assignment
-
Grading
 
Graded Course Components
 
Your grade will consist of the following categories:
Each mark is graded on the scale:
-
E
(xcellent)
-
S
(atisfafactory)
-
N
(ot yet)
 
Course Grades
 
Instead of curving the class, we’ll use a bucket system:
-
Marks earned place in an initial bucket, additional S+ marks improve grade.
-
Must meet 
all 
requirements of a bucket for initial placement.
-
These are 
minimum
 GPA guarantees – grade can always be higher than min promise.
 
Programming Assignment 0 – Warm Up
 
Released today, due next Thursday (
4/6
) at 11:59 pm on Ed
-
Can submit as many times as you want before initial submission date with
Mark 
button
Focused on reviewing Java concepts and Functional Decomposition
-
Different structure than most assignments with 
multiple smaller problems
See 
Grading Rubric
 for how each dimension is assessed.
IPL opens Monday!
 
Tasks before next time!
 
Fill out the 
Introductory Survey
⭐ Complete the pre-class material (PCM) for Wednesday
(see calendar)
Come to Java Review Session on Monday if new to Java
GUG 220 @ 2:30 - 3:30
Attend quiz section on Tuesday!
Get started on P0
Slide Note
Embed
Share

Lecture 01 in CSE 122 covers Java review, functional decomposition, and code quality. Announcements include a Java review session, programming assignments, and reminders on Java syntax. The session encourages active participation through in-class activities using Slido polls. Students are also urged to engage with their peers to enhance learning.

  • Java Review
  • Functional Decomposition
  • CSE 122
  • Programming Assignments
  • Active Learning

Uploaded on Sep 06, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. Download presentation by click this link. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

E N D

Presentation Transcript


  1. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 BEFORE WE START Talk to your neighbors: What is your favorite restaurant around UW? LEC 01 CSE 122 CSE 122 Java Review & Functional Decomposition Instructors Tristan Huber & Hunter Schafer TAs Ambika Andrew Audrey Autumn Ayush Ben Colton Di Eesha Elizabeth Evelyn Jacob Jaylyn Jin Joe Kevin Leon Megana Melissa Mia Poojitha Rishi Rucha Shivani Shreya Steven Suhani Yijia Ziao Questions during Class? Raise hand or send here sli.do #cse122

  2. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Lecture Outline Announcements/Reminders Review Java Functional Decomposition Code Quality First Assignment - Grading

  3. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Announcements Hope you had fun in your first quiz section yesterday! Java Review Session Monday 4/3 GUG 220, 2:30pm-3:30pm IPL will open on Monday! Programming Assignment 0 (P0) released later today Due next Thurs (4/6) Focused on Java Review

  4. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Lecture Outline Announcements/Reminders Review Java Functional Decomposition Code Quality First Assignment - Grading

  5. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Reminders: Review Java Syntax Java Tutorial reviews all the relevant programming features you should familiar with (even if you don t know them in Java). - Printing and comments - Variables, types, expressions - Conditionals (if/else if/ else) - Loops (for and while) - Strings - Methods - File I/O - Arrays

  6. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Practice : Think sli.do #cse122 In-Class Activities Goal: Get you actively participating in your learning Typical Activity - Question is posed - Think (1 min): Think about the question on your own - Pair (2 min): Talk with your neighbor to discuss question - If you arrive at different conclusions, discuss your logic and figure out why you differ! - If you arrived at the same conclusion, discuss why the other answers might be wrong! - Share (1 min): We discuss the conclusions as a class During each of the Think and Pair stages, you will respond to the question via a sli.do poll - Not worth any points, just here to help you learn!

  7. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Practice : Think sli.do #cse122 What is the output of this Java program? A) Total Diff = 12 B) Total Diff = 11 C) Total Diff = 7 D) Error public class Demo { public static void main(String[] args) { int[] nums = {2, 3, 5, 9, 14}; int totalDiff = 0; for (int i = 1; i <= nums.length; i++) { totalDiff += (nums[i] - nums[i - 1]); } System.out.println("Total Diff = + totalDiff); } }

  8. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Practice : Pair sli.do #cse122 What is the output of this Java program? A) Total Diff = 12 B) Total Diff = 11 C) Total Diff = 7 D) Error public class Demo { public static void main(String[] args) { int[] nums = {2, 3, 5, 9, 14}; int totalDiff = 0; for (int i = 1; i <= nums.length; i++) { totalDiff += (nums[i] - nums[i - 1]); } System.out.println("Total Diff = + totalDiff); } }

  9. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Practice : Share sli.do #cse122 What is the output of this Java program? A) Total Diff = 12 B) Total Diff = 11 C) Total Diff = 7 D) Error public class Demo { public static void main(String[] args) { int[] nums = {2, 3, 5, 9, 14}; int totalDiff = 0; for (int i = 1; i <= nums.length; i++) { totalDiff += (nums[i] - nums[i - 1]); } System.out.println("Total Diff = + totalDiff); } } throws an IndexOutOfBoundsException

  10. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Case Study: Temperatures Write a program to prompt the user for how many days temperatures they want to enter, then asks the user for the temperatures of that many days. The program should then report the highest temperature that occurred and what day it occurred on. The program then should allow the user to ask for the average temperature across a range of days, and report how many of those days were above average. How many days' temperatures? 7 Day 0's high temp: 45 Day 1's high temp: 44 Day 2's high temp: 39 Day 3's high temp: 48 Day 4's high temp: 37 Day 5's high temp: 46 Day 6's high temp: 53 The highest temperature was on day 6 and was 53. Review skills - User input - For loops - Arrays - Maximum calculation - Cumulative sum What range of days are you interested in? 2 5 Average temperature was 42.5 2 days were above average.

  11. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Lecture Outline Announcements/Reminders Review Java Functional Decomposition Code Quality First Assignment - Grading

  12. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Functional Decomposition Functional decomposition is the process of breaking down a complex problem or system into parts that are easier to conceive, understand, program, and maintain. Mix butter and sugar Beat in eggs Wet Mix in flour, baking soda, and chocolate chips Dry Bake the cookies Make cookie-sized balls of dough Place evenly on baking sheet Place Bake at 350 degrees Fahrenheit for 10 minutes Let cool after Bake

  13. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Functional Decomposition Functional decomposition in code means break down a program into smaller methods (also called functions). 1.Read in temperature data 2.Finding the hottest day 3.Finding the average on a range 4.Reporting stats on a range Temperatures program

  14. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Avoid Trivial Methods Introduce methods to decompose a complex problem, not just for the sake of adding a method. Bad example: Good Example: public static double round(double num) { return ((int) Math.round(num * 10)) / 10.0; } public static void printMessage(String message) { System.out.println(message); } Rule of thumb: A method should do at least two steps - Ask yourself: Does adding this method make my code easier to understand?

  15. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Lecture Outline Announcements/Reminders Review Java Functional Decomposition Code Quality First Assignment - Grading

  16. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Code Quality Programs are meant to be read by humans and only incidentally for computers to execute. Abelson & Sussman, SICP Code is about communication. Writing code with good code quality is important to communicate effectively. Different organizations have different standards for code quality. - Doesn t mean any one standard is wrong! (e.g., APA, MLA, Chicago, IEEE, ...) - Consistency is very helpful within a group project - See our Code Quality Guide for the standards we will all use in CSE 122

  17. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 sli.do #cse122 What does this code do? How could you improve the quality of this code? (No Slido poll) public static int l(String a,char b){ int j=-1;for(int a1=0;a1<a.length();a1 ++) { if (a.charAt(a1) == b) { j = a1; } } if(j==-1){return -1;} else { return j;} }

  18. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 sli.do #cse122 What does this code do? How could you improve the quality of this code? (No Slido poll) public static int l(String a, char b) { int j=-1; for(int a1=0;a1<a.length();a1 ++) { if (a.charAt(a1) == b) { j = a1; } } if(j==-1) { return -1; } else { return j; } }

  19. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 CSE 122 Code Quality Examples relevant for this week Correctly formatted variable, class, and method names Descriptive variable names Indentation No long lines (generally < 80 chars) Spacing Good method decomposition Writing documentation - class and method comments

  20. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Lecture Outline Announcements/Reminders Review Java Functional Decomposition Code Quality First Assignment - Grading

  21. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Graded Course Components Your grade will consist of the following categories: Each mark is graded on the scale: - E(xcellent) - S(atisfafactory) - N(ot yet) Category # Marks per Total Marks Programming Assignments 4 4 (Behavior, Concepts, Quality, Testing/Reflection) 16 Creative Projects 4 1 4 Quizzes 3 3 (3 questions) 9 Exam 1 6 (6 questions) 6

  22. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Course Grades Instead of curving the class, we ll use a bucket system: - Marks earned place in an initial bucket, additional S+ marks improve grade. - Must meet all requirements of a bucket for initial placement. - These are minimum GPA guarantees grade can always be higher than min promise. Minimum Grade Creative Projects Programming Assignments Quiz/Exam Problems Total Marks 4 ESN 16 ESN 15 ESN 3.5 All (4) S+; 3 E All (16) S+; 12 E; 3 Es per dim. 13 S+; 11 E 3.0 All (4) S+; 2 E 14 S+; 8 E; 2 E per dim. 10 S+; 7 E 2.5 3 S+; 1 E 12 S+; 4 E; 1 E per dim. 8 S+; 3 E 2.0 2 S+ 10 S+ 7 S+ 1.5 1 S+ 8 S+ 5 S+ 0.7 1 S+ 4 S+ 3 S+

  23. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Programming Assignment 0 Warm Up Released today, due next Thursday (4/6) at 11:59 pm on Ed - Can submit as many times as you want before initial submission date with Mark button Focused on reviewing Java concepts and Functional Decomposition - Different structure than most assignments with multiple smaller problems See Grading Rubric for how each dimension is assessed. IPL opens Monday!

  24. LEC 01: Java Review & Functional Decomposition CSE 122 Spring 2023 Tasks before next time! Fill out the Introductory Survey Complete the pre-class material (PCM) for Wednesday (see calendar) Come to Java Review Session on Monday if new to Java GUG 220 @ 2:30 - 3:30 Attend quiz section on Tuesday! Get started on P0

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#