Unformatted text preview:

StuDocu is not sponsored or endorsed by any college or universityCMSC131 - Lecture notes AllObject-Oriented Programming I (University of Maryland)StuDocu is not sponsored or endorsed by any college or universityCMSC131 - Lecture notes AllObject-Oriented Programming I (University of Maryland)Downloaded by William Rabalais ([email protected])lOMoARcPSD|14265820html-color-codes.info/colors-from-image/www.manning.com/books/generative-arthttp://codingbat.com/javaDefinitions:1. Algorithm is the idea expressed by a program and is a generalized idea of a program independent of language2. A program is a sequence of clear instructions in an artificial programming language3. Different Programming Languages:a. Artificial- designed for a purposeb. Evolving- changing over timec. Equivalent- all general purpose languages can perform the same computations4. Computing in Processa. Data types- how to write data valuesb. Variables- how to store/retrieve datac. Expressions- how to calculate5. A computer is a general purpose programmable machine that processes or manipulates data6. Integer Data Type: for integers7. Float Data Type: for floating point valuesa. Fixed - 12.34 10b. Scientific Notation - 10e12 -1.3e-4c. Explicitly Typed- 12.3f 10f8. Sequential Processing: processed one line at a time and processed in order first to last.9. Von Neumann Machinea. Four parts: Input to Processor to both Output and Memory. b. Four Concepts:Sequential processing, stored program, binary circuits, electrical power. c. Java/Processing Commands are all either:i. Input: Data from input to memoryii. Assignments: data from memory to memoryiii. Outputs: data from memory to output10. Variable: we can declare a variable by first putting its type, then name, separated by a space, and ending with a semicolon11. What makes a good program?a. Good comments, Efficient, Organized, Easy to use, Functionality b. A program is correct if it matches the specifications. It is readable if it communicates well to a reader and efficient if it is shorter, faster. 12. What’s a <boolean expression>a. Values: True or Falseb. Operators: or II , and && , not !c. Variables: boolean isHappy=True13. Case Analysis: table of cases and actions. Cases do not overlap, mutually exclusive. 14. CPU: central processing unit, brains of the computerDownloaded by William Rabalais ([email protected])lOMoARcPSD|1426582015. ROM: read only memory, hold bootstrapping code in a form of firmware16. Hard Disk: example is hard drive, files are all stored here17. RAM: random access memory, way fast than disk, variables are stored here18. Cache: there are little levels. a. L1 is the fastest and smallestb. L2 slower than 1 but faster than 3c. L3 largest and slowest19. Operating System: system software that makes computer do work. Interface between programs and hardware20. Applications: software you install in your operating system21. Gregory’s Series 22. Iteration: mechanism of repetition 23. Conditional Processing : while there’s more data, get some, if it meets a condition, process it24. Integer Division:a. a / b is 3 (when a = 10 and b = 3)b. a % b is 1i. % is mod function (remainder)25. Methods vs Call a. Call needs a header, tells you what goes in and what goes outb. Method e.x println(sqr(4));i. Writing own Method:1. header { Examples: cube(x) x^3 2. body sigmoid(x) = 1/(1+e^x)3. } ii. Writing own method: float cube ( float x ) { return x * x * x }OR float abs ( float x ) {if (x < 0) return - x;else return x; }OR float max2( float x, float y) {if ( x > y) return x;else return y; }c. Call e.x println(2*sqr(2018);d. float y = sqr(PI)+4;e. Variable/Parameter can be constant26. Whats void? Means no return statement - method prints, drawsDownloaded by William Rabalais ([email protected])lOMoARcPSD|1426582027. Static and Dynamic Modea. Static: no definitions (e.x what goes into void setup();)b. Dynamic: method definitions (e.x is void)28. A local variable is valid only in the block which it is declared29. Series is a continuing sum of sequence of terms. 30. General Structure for Method: <type> <method name> (<parameters>) {a. <statements)b. <return>31. Arrays: instead of one variable and one value, one variable and multiple locations a. <type> [ ] <name> = new <type> [memory]b. Array Operations: does A equal B, copy A and B, sum product32. Naming Conventionsa. i, j, k used as indicesb. n, m used as length33. Geometric mean is to average as factorial is to sum34. Search: how to find an array if it contains a known key35.Documenting Your Code:1. //Lab # (NAME OF LAB)2. //S. Gessner, Month/Day/YearCommands:1. point(x,y);2. line(x,y,x2,y2);3. rect(x,y,w,h);4. triangle(x,y,x2,y2,x3,y3);5. quad(x,y,x2,y2,x3,y3,x4,y4);6. ellipse(x,y,w,h);7. arc(x,y,w,h,start,stop);8. fill(c); // set fill color (R,G,B,transparency”) 9. noFill();// set transparent fill10. stroke(c);// set stroke color11. noStroke(); //set transparent stroke12. keyPressed()13. void draw() {}14. void setup() {}15. float x = random16. float y = random17. strokeWeight()18. frameRate() // slows down or speeds up. The bigger # the faster19. To create a variable:a. Int x = 0 // the width begins at 0Downloaded by William Rabalais ([email protected])lOMoARcPSD|14265820b. Or to increase by 20…. X = x + 2020. void keyPressed(); //Is an event, happens when key is presseda. If (key == ‘s’)i. saveFrame(“pic###.jpg”)b. println(key)21. “Pic.jpg” //double quotes, multiple symbols22. println((int)key); //a cast converts types23. if (key == ‘’) // Use if to turn off stroke, change fill color, change stroke color… etc. a. Or if (<boolean_expression>)i. <statement>b. if (x> width) {c. Or if (<boolean_expression>)i. <statement1>ii. Elseiii. <statement2>d.24. void mouseDragged() { //happens when mouse is moved and dragged25. Equal is == , not equal is != , less than/equal is <= , greater than/equal >=26. abs(x) //absolute value27.Practice:1. Writing if Statements1. y = I x I a. if (x>=0) if (x<0)b. y = x y = -xc. if (x<0) elsed. y = -x; y = x;2. z= max(x,y) a. if (x>y) b. z = x; c. else d. z = y1. r= -b+-sqroot b^2-4ac all of 2a2. d = sqroot b^2-4aca. D = sqrt(b*b-4*a*c);b. if (d==0)c. r1 = -b1. Give grades. A >90 B>80 C elsea. if (score>90)b. grade = ‘A’;c. else if (score>80)d. grade = ‘B’;e. else Downloaded by William Rabalais ([email protected])lOMoARcPSD|14265820f. grade = ‘C’;2. For loopa. For (<init> ; <test> ;


View Full Document

UMD CMSC 131 - Lecture Notes

Documents in this Course
Set #3

Set #3

7 pages

Exam #1

Exam #1

6 pages

Exam #1

Exam #1

6 pages

Notes

Notes

124 pages

Notes

Notes

124 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?