1 CS 177 Week 15 Recitation Slides Review. Announcements Final Exam on Sat. May 8th  PHY 112 from 8-10 AM Complete your online review of your classes.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

Week 7 - Friday.  What did we talk about last time?  Array examples.
8-May-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
10-Jun-15 Just Enough Java. Variables A variable is a “box” that holds data Every variable has a name Examples: name, age, address, isMarried Variables.
Computer Science 1620 Loops.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Arrays Liang, Chpt 5. arrays Fintan Array of chars For example, a String variable contains an array of characters: An array is a data structure.
Additional control structures. The if-else statement The if-else statement chooses which of two statements to execute The if-else statement has the form:
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
16-Jun-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
CMT Programming Software Applications
COMP 110 Introduction to Programming Mr. Joshua Stough October 8, 2007.
Loops – While, Do, For Repetition Statements Introduction to Arrays
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
Arrays, Loops weeks 4-6 (change from syllabus for week 6) Chapter 4.
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
COMP 110 Introduction to Programming Mr. Joshua Stough September 19, 2007.
COMP 110 Introduction to Programming Mr. Joshua Stough September 24, 2007.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
The switch Statement, DecimalFormat, and Introduction to Looping
Week 7 - Wednesday.  What did we talk about last time?  Introduction to arrays  Lab 6.
Review Review Review. Concepts Comments: definition, example, different types of comments Class: definition, example Object: definition, example Data.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
The string data type String. String (in general) A string is a sequence of characters enclosed between the double quotes "..." Example: Each character.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Arrays and ArrayLists in Java L. Kedigh. Array Characteristics List of values. A list of values where every member is of the same type. Each member in.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
Lecture 4 Looping. Building on the foundation Now that we know a little about  cout  cin  math operators  boolean operators  making decisions using.
Chapter 5: Control Structures II J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design,
Chapter 4: Control Structures II
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
1 CS 177 Week 12 Recitation Slides Running Time and Performance.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
1-Dec-15 Additional control structures. 2 The if-else statement The if-else statement chooses which of two statements to execute The if-else statement.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
CSC 212 Object-Oriented Programming and Java Part 2.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Written by: Dr. JJ Shepherd
Week 7 - Wednesday.  What did we talk about last time?  Introduction to arrays  Lab 6.
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
COMP Loop Statements Yi Hong May 21, 2015.
Week 10 - Friday.  What did we talk about last time?  References and primitive types  Started review.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
int [] scores = new int [10];
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
CS0007: Introduction to Computer Programming The for Loop, Accumulator Variables, Seninel Values, and The Random Class.
Copyright © 2014 by John Wiley & Sons. All rights reserved.1 Decisions and Iterations.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS 1 Copyright: 2015 Illinois Institute of Technology_ George Koutsogiannakis.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Quiz 1 Exam 1 Next Monday. Nested if Statements if (myGrade >= 80) if (myGrade >= 90) System.out.println(“You have an A!” ); else System.out.println(“You.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Lecture 4b Repeating With Loops
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Recitation 13 Searching and Sorting.
Week 7 - Wednesday CS 121.
Week 15 – Wednesday CS 121.
Repetition-Sentinel,Flag Loop/Do_While
CS 177 Week 15 Recitation Slides
CISC124 Labs start this week in JEFF 155. Fall 2018
OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS
Additional control structures
Just Enough Java 17-May-19.
Presentation transcript:

1 CS 177 Week 15 Recitation Slides Review

Announcements Final Exam on Sat. May 8th  PHY 112 from 8-10 AM Complete your online review of your classes.  Your opinion matters!!! Project 6 due …  Just kidding 2

How to Study Know every detail of previous exams you have taken.  If there is something you DON’T understand, look it up, Google it and ask questions! Review the slides. Recitation slides are a summary of each week’s lecture.  Good to review both; they will compliment one another. Understand your labs and projects as though you had to re-program them from scratch.  Re-program key parts and ** learn how to trace a program… ** Use the book to fill in any question areas. DO NOT ONLY RELY ON THE EXAMPLE FINAL!!!!! 3

Remember the Good Ole’ Days Compile and run a program called Program.java:  javac Program.java  java Program Difference between System.out.println() and System.out.print() ?  println() adds a new line at the end of the printed statement Java is case sensitive:  VarName is different from varName. 4

Primitive Data Types: 5 TypeKind of valuesSample Literals int Integers double Floating-point Numbers e23 boolean Boolean values true false char Single characters ‘A’ ‘Z’ ‘&’ String Sequences of charaters “Hello World” “Goodbye”

From example exam: 6

Conditionals if statements use a boolean expression and execute a set of statements if the expression is true.  There may be a corresponding else block that handles cases where the expression is false Switch statements allow for the use of choices of several values, but must only be equality relationships for integers and characters. if( ) else 7 switch(data) { case val1: (break;) case val2: (break;) default: }

Loops For loops – Count controlled While loops – Event controlled Do/While – Event controlled loops that need to execute AT LEAST once Conditions in loops are ways to enter the loop but also the condition on which to leave the loop – The STOP condition (Keep going until…) 8

Example: 9

Arrays Multiple elements stored and accessed together via the same variable name, with indices 0 – (length of array-1) All elements must be the same type To declare an array called example of 100 integers: int example = new int[100]; To create an array with initial elements, you can use: int example = {1, 2, 3, 4, 5}; 10

Example with arrays and loops 11

12 What if i started with 0?

Input Output java ProgramOut > output.txt java ProgramIn < output.txt OR java ProgramOut | java ProgramIn 13

StdDraw 14 MethodUse void line(double x0, double y0, double x1, double y1) Draw a line from (x0,y0) to (x1,y1) void point(double x, double y) Draw a point at (x,y) MethodUse void circle(double x, double y, double r) Draw a circle centered at (x,y) with radius r void filledCircle(double x, double y, double r) Draw a filled circle centered at (x,y) with radius r void square(double x, double y, double r) Draw a square centered at (x,y) with edges 2r void filledSquare(double x, double y, double r) Draw a filled square centered at (x,y) with edges 2r void setPenColor(Color c) Start drawing with color c

Methods public static type methodName(type name1, … type nameN) or private return type optional public int calculateSum(int[] array) { int sum = 0; for(int i = 0; i < array.length; i++) sum += array[i]; return sum; } 15

16

Audio Digital audio is made by sampling the heights of the sound wave many times per second CD quality audio samples at 44,100 Hz The frequency of the wave determines how high or low the wave sounds The height of the peaks from the troughs (amplitude) determines the loudness (volume) StdAudio lets us load WAV files as an array of samples in the range [-1.0,1,0] and save such arrays as WAV files 17

18 MethodUse static double[] read(String file) Read a WAV file into an array of double s static void save(String file, double[] input) Save an array of double s (samples) into a WAV file static void play(String file) Play a WAV file static void play(double[] input) Play an array of double s (samples)

Classes and Objects public class Name { private type member1; private type member2; //member variables … public Name(…) { //constructor …. } //other methods …. } 19

Objects and Classes cont. Objects behave differently from primitive data types Reference variables are used to keep track of objects When a reference is first declared, its value is null If you try to use the methods or members of a null reference, your program will crash Multiple references can point at a single object Changing the object that they point to will change it for all references 20

Objects contain  Members  Methods Members are the data inside of objects, and they are usually private Methods are ways of accessing and modifying that data, and they are usually public 21

22

23

Running Time and Performance Not every solution that “works” is the best solution to use.  Sometimes, even if a program works, it can be too slow.  Usually depends on how many loops and how many nested loops there are. 24

Searching and Sorting Searching  Can be done in O(n) time by just scanning through the array  Can be done in O(log n) time if the array is sorted by playing a high-low game called binary search Cutting the search space in half every time It’s an algorithm that works well even with very large n Sorting  Relatively simple methods take O(n 2 ) time  The “best” possible is O(n log n) time 25

Sorting Many possible ways of sorting.  The more efficient, the more difficult to program… Bubble Sort Insertion Sort Merge Sort Bucket Sort (Many others…)  SHOULD BECOME FAMILIAR WITH ALGORITHMS FROM SLIDES!!!!! 26

27

28

ANY QUESTIONS 29

QUIZ Using what you know and the remaining time, write down a question and answer that shows something you have learned this semester. Don’t forget your name in the process… (Please do not get over zealous where you may not be able to finish on time.) GOOD LUCK ON THE FINAL  (AND DON’T FORGET EVALUATIONS!!!) 30