cse11 discussion 2 - d1b10bmlvqabco.cloudfront.net · cse11 discussion 2 with chris taylor. reading...
TRANSCRIPT
![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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/1.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/2.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/3.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/4.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/5.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/6.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/7.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/8.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/9.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/10.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/11.jpg)
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()](https://reader034.vdocument.in/reader034/viewer/2022042217/5ec09b0b21f1ec06f46b55a8/html5/thumbnails/12.jpg)
Turtle graphics fun