Lecture 7 Notes

advertisement

BIT 115 Lecture 7 Page 1 / 2

NOTE TO STUDENTS :

These notes are for the instructor's use. If you happen to find them to be useful, that's great. If not, then please ignore these. Thanks!

—The Instructor

Lecture 4:

The midterm exam will focus on the first three learning outcomes

 conceptualize the logical steps needed to accomplish a task,

 apply structured programming techniques to accomplish a task,

 test and debug a program

Exam Topics:

 Setting up a city with walls, things, robots

 Using the robots built-in services

 Extending a robot to include new services

 Tracing code and pinpointing where it goes wrong

 Explaining the compile/run process

 Selecting when to use different programming structures like loops, decisions, and services

 Writing syntax for loops, decisions, local variables, and parameters

The exam will be similar to the quiz format, i.e., pencil-paper, from memory, individual work.

Loop Patterns: Counting

There are certain arrangements of code that you'll see again & again

For example, if you want to count from one number to another, you'll end up with code that's similar to every OTHER time you want to do this.

These similarities are good to notice

Instead or reinventing the wheel each time, REUSE stuff

I'm going to call these 'patterns'

The details (like what a variable is named, etc) will change

The important parts, the structure , won't.

Looping until something is true

Looping until something is not true

<Find all the errors, then trace it>

Input / Output

We've made programs which can do a bunch of things

We've even made programs that can adapt to changing situations

(while there's stuff to pick up, pick it up)

However, everything's completely predictable

BIT 115 LECTURE 6.b Page 1 / 2

BIT 115 Lecture 7

(This is nice for debugging / error-finding!)

Meaning that given the same City, the robot will do the same thing each time

What if you wanted to make a game, "Drive The Robot"?

We need a way to ask the user what to do (info we get from the user is input )

And to deliver information to the user (info we print to the user is output )

We're going to stick with an old, reliable method:

Print text to the screen

Get text from the keyboard

We'll leave stuff involving windows, buttons, etc till (much) later….

<Demo IO here>

Page 2 / 2

Make sure to point out that I/O will be shunted to the Output Panel of jGrasp, NOT the console

We'll use the standard Java output mechanism:

System.out.println( "Whatever I want to print, surrounded by doublequotes" );

System.out

: This is the name of the thing we're asking to do the output println: the name of the service that actually does the output-ing

( … ) : where the info we're passing it begins & ends

"…" : Everything in between the double-quotes ( " ), but not including the double-quotes, is what we want to actually appear on the user's screen.

(Obscure Note: Word has these 'Smart Quote' thingee that look better, but don't work as double-quotes. If you write code in Word (for some reason), watch out for them if you then copy-and-paste the code into jGrasp)

And, of course, the semi-colon at the end

INPUT I/O will be covered in next Lecture

Input: standard Java input is actually a bit more tricky, so we're going to use some input objects built into the custom robot software.

This software ONLY gets input from the keyboard

The Java compiler needs to be told about this chunk of specialized software.

At the top of the file write: import becker.io.TextInput;

<Go through the demo in more detail>

Notice that we print out enough instructions to give the user a good shot at actually providing reasonable input.

<Look at the ClearStreets example to demonstrate some more complicated behavior)

BIT 115 LECTURE 6.b Page 2 / 2

Download