CS 177 Week 15 Recitation Slides

Slides:



Advertisements
Similar presentations
Week 7 - Friday.  What did we talk about last time?  Array examples.
Advertisements

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.
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:
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.
Loops – While, Do, For Repetition Statements Introduction to Arrays
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.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
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 24, 2007.
COMP 14: Primitive Data and Objects May 24, 2000 Nick Vallidis.
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.
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.
Chapter 4: Control Structures II
Loops (cont.). Loop Statements  while statement  do statement  for statement while ( condition ) statement; do { statement list; } while ( condition.
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.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Week 7 - Wednesday.  What did we talk about last time?  Introduction to arrays  Lab 6.
COMP Loop Statements Yi Hong May 21, 2015.
Week 10 - Friday.  What did we talk about last time?  References and primitive types  Started review.
1 Flow of Control Chapter 5. 2 Objectives You will be able to: Use the Java "if" statement to control flow of control within your program.  Use the Java.
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.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Lecture 4 CS140 Dick Steflik. Reading Keyboard Input Import java.util.Scanner – A simple text scanner which can parse primitive types and strings using.
Information and Computer Sciences University of Hawaii, Manoa
Chapter 1.2 Introduction to C++ Programming
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Lecture 4b Repeating With Loops
CE221 – Data Structures & Algorithms Lab Introduction
UMBC CMSC 104 – Section 01, Fall 2016
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Chapter 7 User-Defined Methods.
Chapter 1.2 Introduction to C++ Programming
COMP 14 Introduction to Programming
Week 13: Searching and Sorting
Week 7 - Friday CS 121.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Recitation 13 Searching and Sorting.
Week 7 - Wednesday CS 121.
Java Coding 3 – part2 David Davenport Computer Eng. Dept.,
EGR 2261 Unit 4 Control Structures I: Selection
Chapter 5: Control Structures II
Review If you want to display a floating-point number in a particular format use The DecimalFormat Class printf A loop is… a control structure that causes.
Week 15 – Wednesday CS 121.
Repetition-Counter control Loop
CiS 260: App Dev I Chapter 4: Control Structures II.
Announcements Final Exam on August 17th Wednesday at 16:00.
Starting JavaProgramming
Introduction to Programming
An Introduction to Java – Part I, language basics
Arrays, Part 1 of 2 Topics Definition of a Data Structure
CISC124 Labs start this week in JEFF 155. Fall 2018
OBJECT ORIENTED PROGRAMMING I LECTURE 11 GEORGE KOUTSOGIANNAKIS
Suggested self-checks: Section 7.11 #1-11
Additional control structures
Question 1a) What is printed by the following Java program? int s;
Just Enough Java 17-May-19.
2008/11/19: Lecture 18 CMSC 104, Section 0101 John Y. Park
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Week 7 - Monday CS 121.
Presentation transcript:

CS 177 Week 15 Recitation Slides Review

Announcements Final Exam on Friday Dec. 18th STEW 183 from 1 – 3 PM Complete your online review of your classes. Your opinion matters!!! Project 6 due … Just kidding

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!!!!!

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.

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

From example exam:

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(<Boolean Expression>) <Statement1> else <Statement2> switch(data) { case val1: <Statement1> (break;) case val2: <Statement2> (break;) default: <Statement3> }

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…)

Example:

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};

Example with arrays and loops

What if i started with 0?

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

StdDraw void line(double x0, double y0, double x1, double y1) Method Use 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) Method Use 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; }

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

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

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

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

Members are the data inside of objects, and they are usually private 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

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.

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(n2) time The “best” possible is O(n log n) time

Sorting Many possible ways of sorting. Bubble Sort Insertion Sort 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!!!!!

ANY QUESTIONS

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!!!)