Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the...
Transcript of Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the...
![Page 1: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/1.jpg)
Piech,CS106A,StanfordUniversity
Review
![Page 2: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/2.jpg)
Piech,CS106A,StanfordUniversity
Java
![Page 3: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/3.jpg)
Piech,CS106A,StanfordUniversity
total(containsanint)42
Three Properties of Variables
name
value
type
![Page 4: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/4.jpg)
Piech,CS106A,StanfordUniversity
Types// integer valuesint num = 5;
// real valuesdouble fraction = 0.2;
// letterschar letter = ‘c’;
// true or falseboolean isLove = true;
*Whyisitcalledadouble?
![Page 5: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/5.jpg)
Piech,CS106A,StanfordUniversity
+ Addition– Subtraction
* Multiplication/ Division% Remainder
Binary Operators
Todayisyourday,tio
![Page 6: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/6.jpg)
Piech,CS106A,StanfordUniversity
Remainder
// an example of the % operatorprintln(17 % 4);
// reads a number from the userint num = readInt("?: ");
// stores the ones digitint onesDigit = num % 10;
// equal to 1 if num is odd, // 0 if num is even.int isOdd = num % 2;
![Page 7: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/7.jpg)
Piech,CS106A,StanfordUniversity
+ Addition– Subtraction
* Multiplication/ Division% Remainder
Binary Operators
![Page 8: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/8.jpg)
Piech,CS106A,StanfordUniversity
Challenge Carbon Dating
Write a program that canturn a measurement of C14into an estimate of age.
![Page 9: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/9.jpg)
Piech,CS106A,StanfordUniversity
Example: Carbon Dating
C14=1.2dpm C14=13.6dpm
Wecancalculatethattheraptordied20,000yearsago
![Page 10: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/10.jpg)
Piech,CS106A,StanfordUniversity
Carbon Dating Equation
½ because of half life convention
*Someof thesevaluesareconstants**Usethefunction:Math.log( num )
age =
log(
x
13.6 )
log(
12 )
⇥ 5730
![Page 11: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/11.jpg)
Piech,CS106A,StanfordUniversity
EndReview
![Page 12: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/12.jpg)
Piech,CS106A,StanfordUniversity
Today’sGoal1. Know how to use graphics variables2. Understand For / While / If in Java
![Page 13: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/13.jpg)
Piech,CS106A,StanfordUniversity
Today’sRoute
ReviewGraphics
Simple Java
Youarehere
![Page 14: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/14.jpg)
Piech,CS106A,StanfordUniversity
Graphics Programs
![Page 15: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/15.jpg)
Piech,CS106A,StanfordUniversity
GRect is a variable type that stores a rectangle.
As an example, the followingrunmethod displays a blue square
public void run() {Grect rect = new GRect(200, 200);rect.setFilled(true);rect.setColor(Color.BLUE);add(rect, 50, 50);
}
LargestOval
GRect
![Page 16: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/16.jpg)
Piech,CS106A,StanfordUniversity
Graphics Coordinates0,0
getHeight();
getWidth();
40,20
40,120
120,40
![Page 17: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/17.jpg)
Piech,CS106A,StanfordUniversity
Learn By Example
![Page 18: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/18.jpg)
Piech,CS106A,StanfordUniversity
GObject
GRect GOval GLineGLabel
Graphics Variable Types
GRect myRect = new GRect(350, 270);
![Page 19: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/19.jpg)
Piech,CS106A,StanfordUniversity
Primitives vs ClassesPrimitiveVariableTypes ClassVariableTypes
intdoublecharboolean
GRectGOvalGLine…
Classvariables:1. Haveuppercamelcasetypes2. Youcancallmethodsonthem3. Areconstructedusingnew4. Arestoredinaspecialway
![Page 20: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/20.jpg)
Piech,CS106A,StanfordUniversity
public class HelloProgram extends GraphicsProgram {public void run() {
GLabel label = new GLabel("hello, world");label.setFont("SansSerif-36");label.setColor(Color.RED);add(label, 100, 75);
}}
HelloProgram
hello, world
label
hello, worldhello, worldhello, world
The following program illustrates sending a message to an object.Note that the label doesn’t appear until it is added to the canvas.
skip simulationGraphic courtesy of Eric Roberts
Graphics Trace
![Page 21: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/21.jpg)
Piech,CS106A,StanfordUniversityGraphic courtesy of Eric Roberts
HelloProgram
hello, world(100, 75)
(0, 0)
•GLabel coordinates are baseline of first character
Label Location
![Page 22: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/22.jpg)
Piech,CS106A,StanfordUniversity
object.setColor(color)Sets the color of the object to the specified color constant.
Operations on GRect
The standard color names are defined in the java.awt package:
Color.BLACKColor.DARK_GRAYColor.GRAYColor.LIGHT_GRAYColor.WHITE
Color.REDColor.YELLOWColor.GREENColor.CYAN
Color.BLUEColor.MAGENTAColor.ORANGEColor.PINK
![Page 23: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/23.jpg)
Piech,CS106A,StanfordUniversity
object.setColor(color)Sets the color of the object to the specified color constant.
object.setLocation(x, y)Changes the location of the object to the point (x, y).
object.move(dx, dy)Moves the object on the screen by adding dx and dy to its current coordinates.
Operations on GRect
object.setFilled( fill)If fill is true, fills in the interior of the object; if false, shows only the outline.
object.setFillColor( color)Sets the color used to fill the interior, which can be different from the border.
object.getWidth()Returns the width of the rectangle.
object.getHeight()Returns the height of the rectangle.
![Page 24: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/24.jpg)
Piech,CS106A,StanfordUniversity
object.setColor(color)Sets the color of the object to the specified color constant.
object.setLocation(x, y)Changes the location of the object to the point (x, y).
object.move(dx, dy)Moves the object on the screen by adding dx and dy to its current coordinates.
Operations on GOval
object.setFilled( fill)If fill is true, fills in the interior of the object; if false, shows only the outline.
object.setFillColor( color)Sets the color used to fill the interior, which can be different from the border.
object.getWidth()Returns the width of the rectangle.
object.getHeight()Returns the height of the rectangle.
![Page 25: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/25.jpg)
Piech,CS106A,StanfordUniversity
Methods specific to the GLabel classlabel.setFont( font)
Sets the font used to display the label as specified by the font string.
The font is typically specified as a string in the form
"family-style-size"
family is the name of a font familystyle is either PLAIN, BOLD, ITALIC, or BOLDITALICsize is an integer indicating the point size
Based on slides by Eric Roberts
Operations on GLabel
label.getAscent( )Returns the height of the label above its baseline.
label.getWidth( )Returns the width of the label.
![Page 26: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/26.jpg)
Piech,CS106A,StanfordUniversity
new GRect( x, y, width, height)Creates a rectangle whose upper left corner is at (x, y) of the specified size.
new GOval( x, y, width, height)Creates an oval that fits inside the rectangle with the same dimensions.
new GLabel( text)Creates a label with the given text.
Based on slides by Eric Roberts
new GRect(width, height)Creates a rectangle with dimensions width and height.
new GOval(width, height)Creates an oval that fits inside the rectangle with the same dimensions.
Construction
new GLine( x1, y1, x2, y2)Creates a line with the given start and end points.
![Page 27: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/27.jpg)
Piech,CS106A,StanfordUniversityBased on slides by Eric Roberts
add( object)Adds an object to the canvas. Location is not specified.
Graphics Methods
add( object, x, y)Adds an object to the canvas at a specific location.
getWidth()Returns the width of the screen.
getHeight( object, x, y)Returns the height of the screen.
![Page 28: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/28.jpg)
Piech,CS106A,StanfordUniversity
Another Example
![Page 29: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/29.jpg)
Piech,CS106A,StanfordUniversity
Today’sRoute
ReviewGraphics
Simple Java
Youarehere
![Page 30: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/30.jpg)
Piech,CS106A,StanfordUniversity
Today’sRoute
ReviewGraphics
Simple Java
Youarehere
![Page 31: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/31.jpg)
Piech,CS106A,StanfordUniversity
WhileLoopinKarel
while(frontIsClear()) {body
}
if(beepersPresent()) {body
}
![Page 32: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/32.jpg)
Piech,CS106A,StanfordUniversity
WhileLoopRedux
while(condition) {body
}
if(condition) {body
}
Theconditionshouldbea“boolean”whichiseithertrue orfalse
![Page 33: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/33.jpg)
Piech,CS106A,StanfordUniversity
// read the amount of C14 from the userdouble amount = readDouble("Amount of C14 in your sample: ");
// use the half life formula to calculate the agedouble age = Math.log(amount/LIVING_C14) / Math.log(0.5) *
HALF_LIFE;age = Math.round(age);println("Your sample is " + age + " years old.");
WhatDoesThisDo?
*ItcalculatestheageofaC14sample
![Page 34: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/34.jpg)
Piech,CS106A,StanfordUniversity
while(true) {// read the amount of C14 from the userdouble amount = readDouble("Amount of C14 in your sample: ");
// use the half life formula to calculate the agedouble age = Math.log(amount/LIVING_C14) / Math.log(0.5) *
HALF_LIFE;age = Math.round(age);println("Your sample is " + age + " years old.");
// add an extra line between queriesprintln("");
}
WhatDoesThisDo?
*ItrepeatedlycalculatestheageofaC14sample
Before repeating the body, check if this statement
evaluates to true
![Page 35: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/35.jpg)
Piech,CS106A,StanfordUniversity
BooleanComparisons
== EqualsTestNotequals
LessthanLessthanequals
!=
<=< Greaterthan
Greaterthanequals
>=>
![Page 36: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/36.jpg)
Piech,CS106A,StanfordUniversity
GuessMyNumber
![Page 37: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/37.jpg)
Piech,CS106A,StanfordUniversity
GuessMyNumber
int secretNumber = getHeight() % 100;println("I am thinking of a number between 0 and 99...");int guess = readInt("Enter a guess: ");// true if guess is not equal to secret numberwhile(guess != secretNumber) {
// true if guess is less than secret numberif(guess < secretNumber) {
println("Your guess is too low");} else {
println("Your guess is too high");}println(""); // an empty lineguess = readInt("Enter a new number: ");
}println("Congrats! The number was: " + secretNumber);
![Page 38: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/38.jpg)
Piech,CS106A,StanfordUniversity
Howwouldyouprintln “Nickrockssocks”100times
![Page 39: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/39.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
public void run() {for(int i = 0; i < 100; i++) {
println(“Nick rocks socks!”);}
}
![Page 40: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/40.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 100; i++) {println(“Nick rocks socks!”);
}
Enters the loop if this condition
passes
![Page 41: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/41.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
For Loop Redux
![Page 42: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/42.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
For Loop Redux
![Page 43: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/43.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 0
For Loop Redux
![Page 44: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/44.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 0
For Loop Redux
![Page 45: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/45.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 0
For Loop Redux
Nick rocks socks
![Page 46: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/46.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 1
For Loop Redux
Nick rocks socks
![Page 47: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/47.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 1
For Loop Redux
Nick rocks socks
![Page 48: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/48.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 1
For Loop Redux
Nick rocks socksNick rocks socks
![Page 49: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/49.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 2
For Loop Redux
Nick rocks socksNick rocks socks
![Page 50: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/50.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 2
For Loop Redux
Nick rocks socksNick rocks socks
![Page 51: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/51.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 2
For Loop Redux
Nick rocks socksNick rocks socks
Nick rocks socks
![Page 52: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/52.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 3
For Loop Redux
Nick rocks socksNick rocks socks
Nick rocks socks
![Page 53: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/53.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
i 3
For Loop Redux
Nick rocks socksNick rocks socks
Nick rocks socks
![Page 54: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/54.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
For Loop Redux
Nick rocks socksNick rocks socks
Nick rocks socks
![Page 55: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/55.jpg)
Piech,CS106A,StanfordUniversity
ForLoopRedux
for(int i = 0; i < 3; i++) {println(“Nick rocks socks!”);
}
For Loop Redux
Nick rocks socksNick rocks socks
Nick rocks socks
![Page 56: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/56.jpg)
Piech,CS106A,StanfordUniversity
Youcanusetheforloopvariable
![Page 57: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/57.jpg)
Piech,CS106A,StanfordUniversity
Howwouldyouprintln thefirst100evennumbers?
![Page 58: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/58.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
![Page 59: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/59.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < NUM_NUMS; i++) {println(i * 2);
}
![Page 60: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/60.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
For Loop Redux
![Page 61: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/61.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
For Loop Redux
![Page 62: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/62.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 0
For Loop Redux
![Page 63: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/63.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 0
For Loop Redux
![Page 64: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/64.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 0
For Loop Redux
0
![Page 65: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/65.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 1
For Loop Redux
0
![Page 66: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/66.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 1
For Loop Redux
0
![Page 67: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/67.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 1
For Loop Redux
0
2
![Page 68: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/68.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 2
For Loop Redux
0
2
![Page 69: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/69.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 2
For Loop Redux
0
2
![Page 70: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/70.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 2
For Loop Redux
0
2
4
![Page 71: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/71.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 3
For Loop Redux
0
2
4
![Page 72: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/72.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 3
For Loop Redux
0
2
4
![Page 73: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/73.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
i 3
For Loop Redux
0
2
4
![Page 74: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/74.jpg)
Piech,CS106A,StanfordUniversity
PrintingEvenNumbers
for(int i = 0; i < 3; i++) {println(i * 2);
}
For Loop Redux
0
2
4
![Page 75: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/75.jpg)
Piech,CS106A,StanfordUniversity
Today’sRoute
ReviewGraphics
Simple Java
Youarehere
![Page 76: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/76.jpg)
Piech,CS106A,StanfordUniversity
Today’sRoute
ReviewGraphics
Simple Java
Youarehere
![Page 77: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/77.jpg)
Piech,CS106A,StanfordUniversity
Today’sGoal1. Know how to use graphics variables2. Understand For / While / If in Java
![Page 78: Review - Stanford University · Piech, CS106A, Stanford University object.setColor(color) Sets the color of the object to the specified color constant. object.setLocation(x,y) Changes](https://reader030.fdocuments.net/reader030/viewer/2022041218/5e07d326fb6ec0328f1f103a/html5/thumbnails/78.jpg)
Piech,CS106A,StanfordUniversity
StringArt