+ All Categories
Home > Documents > 1 CS 177 Week 15 Recitation Slides Review. Announcements Final Exam on Sat. May 8th PHY 112 from...

1 CS 177 Week 15 Recitation Slides Review. Announcements Final Exam on Sat. May 8th PHY 112 from...

Date post: 21-Dec-2015
Category:
View: 214 times
Download: 0 times
Share this document with a friend
30
1 CS 177 Week 15 Recitation Slides Review
Transcript
Page 1: 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.

1

CS 177 Week 15 Recitation Slides

Review

Page 2: 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.

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

Page 3: 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.

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

Page 4: 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.

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

Page 5: 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.

Primitive Data Types:

5

Type Kind of values Sample Literals

int Integers -50

900031

double Floating-pointNumbers

3.14-0.6

6.02e23

boolean Boolean values true false

char Single characters ‘A’‘Z’‘&’

String Sequences ofcharaters

“Hello World”“Goodbye”

Page 6: 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.

From example exam:

6

Page 7: 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.

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

switch(data) { case val1: <Statement1> (break;) case val2: <Statement2> (break;) default: <Statement3> }

Page 8: 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.

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

Page 9: 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.

Example:

9

Page 10: 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.

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

Page 11: 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.

Example with arrays and loops

11

Page 12: 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.

12

What if i started with 0?

Page 13: 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.

Input Output

java ProgramOut > output.txt

java ProgramIn < output.txt

OR

java ProgramOut | java ProgramIn

13

Page 14: 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.

StdDraw

14

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

Page 15: 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.

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

Page 16: 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.

16

Page 17: 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.

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

Page 18: 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.

18

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)

Page 19: 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.

Classes and Objects

public class Name {

private type member1;

private type member2; //member variables

public Name(…) { //constructor

….

}

//other methods ….

}19

Page 20: 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.

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

Page 21: 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.

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

Page 22: 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.

22

Page 23: 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.

23

Page 24: 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.

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

Page 25: 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.

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

25

Page 26: 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.

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

Page 27: 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.

27

Page 28: 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.

28

Page 29: 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.

ANY QUESTIONS

29

Page 30: 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.

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


Recommended