CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading...

12
CSE11 Discussion 2 with Chris Taylor

Transcript of CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading...

Page 1: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

CSE11 Discussion 2with Chris Taylor

Page 2: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

Reading docs“Constructors”, how you can set up the variable

(not super important yet)

“Methods”, the functions available

Scanner scnr = new Scanner(System.in); scnr.close() scnr.hasNext()

Page 3: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

Methods

InputsOutput

(“void” means no output)

Page 4: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

Now use your powers

Input: a String to test if insideOutput: something about where the string is

This looks promising

Page 5: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

CharSequence?

Ok, maybe using the official docs isn’t so easy… (but it should make more sense later)

Basically, this says that “CharSequence” is a kind of String

Page 6: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

JAVA STYLE• No indent character allowed • Pressing indent = 2 spaces

• (vim and emacs should do this) • 80 characters per line max • Good comments • Google’s Java style guide has much

more:

google.github.io/styleguide/

javaguide.html

Sublime and Notepad++ can visually show spaces

“:set list” in vim reveals if there are tabs (tab = ^I)

Page 7: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

Good comments

You can get an idea of what it does without really reading the code

Page 8: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

Bad comments

😐

Page 9: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

Homework 2• turnToFace() and moveTo() can be super useful

• Instead of calculating angles, just tell it the exact point to go next

• No magic constants, e.g. turn(83)

• instead do something like:int w_angle = 83; turn(w_angle);

• Constants often repeat themselves so it’s not so bad

Page 10: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

Compilingjavac -cp turtleClasses.jar:. CS11TurtleGraphics.java java -cp turtleClasses.jar:. CS11TurtleGraphics

• -cp: “classpath”, search for libraries here • turtleClasses.jar:. search in “turtleClasses.jar” and

“.” (current directory)

Page 11: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

Questions

Page 12: CSE11 Discussion 2 - d1b10bmlvqabco.cloudfront.net · CSE11 Discussion 2 with Chris Taylor. Reading docs “Constructors”, how you can set up the variable ... scnr.close() scnr.hasNext()

Turtle graphics fun