CS1: Lecture 35 – Stopwatch
Dear students, As with methods, a primary benefit of object-oriented programming is code reuse. We can create a utility and use it over and over again, in many contexts. We will do just that by designing a Stopwatch class. Stopwatch We will use our stopwatch to time a few operations: the amount of time it […]
CS1: Lecture 34 – Reverse Engineering Objects
Dear students, In object-oriented programming, the programmer is really a writer of screenplays. Objects are our actors, which we orchestrate around the stage. We cue them to say certain things, have them interact with other objects, and shape them to have an identity that is all their own. Today, we’ll feel our away around the […]
CS1: Lecture 33 – A Growable Array
Dear students, Today, November 22, is National Growable Array Day. We will celebrate growable arrays everywhere by growing one of our own growable arrays, right here, in our classroom. I hope you wore your festive gear. Behind every growable array is an plain old ungrowable array. When that ungrowable array gets filled up, a new […]
CS1: Lecture 32 – More Objects
Dear students, Last time we started our discussion of objects. We continue that discussion today with more examples. Out of concrete examples we build generalized knowledge, right? It’s not the other way around. At this point in the learning process, seeing patterns is more important than feeling like you understand objects. Both need to happen […]
CS1: Lecture 31 – A First Object
Dear students, Today we move on to our last personality: the Computer as a Creator. Up till this point, code and data have been separate entities in our code. Now, we will marry them. We’ll organize code and the data that it operates on into a single being: an object. Objects are models of some […]
CS1: Lecture 30 – 2D Arrays and ArrayList
Dear students, Today we will complete a whirlwind tour through a couple of concepts that really deserve a couple of conversations each. These concepts are two-dimensional arrays and ArrayList. Two-dimensional Arrays Let’s consider a famous statistical problem. Suppose birthdays are uniformly distributed across the calendar year. What’s the probability that we in this room all […]
CS1: Lecture 29 – Bundled Data
Dear students, Last time we used arrays as a means to map integers to values. We associated our data with 0, 1, 2, 3, and so on. When we got a new piece of data in, we use its index to reach inside our array directly. Today we shine the spotlight on arrays as a […]
CS1: Lecture 28 – Indexed Data
Dear students, We officially close out our discussion of the Computer as a Pilot, during which we made the computer navigate this way and that way and back again through our code using conditional statements and loops. But, like always, these ideas of branching and repetition will never leave us. Computers make a lot of […]
CS1: Lecture 27 – BufferedImage
Dear students, In homeworks 4 and 5, we work with images. Loops are a natural companion to images, which are large collections of indexed data that we are not even tempted to process without loops. The general pattern of visiting all pixels of an image is this: for (int r = 0; r < image.getHeight(); […]
CS1: Lecture 26 – Looping Patterns
Dear students, So far we’ve used loops to traverse 1D spaces: the number line, files, and a sequence of random events like coin flipping. Today we bust out into 2D spaces, traversing images and other Cartesian grids. Nesting Loops To transition to our next concept, let’s write a program to mimic the activity we see […]