CS1: Lecture 14 – Relational Operators
Dear students, We have seen the Computer as Calculator, a lover of number crunching. We have seen the Computer as Chef, organizing its tasks into self-contained recipes. Now we see the Computer as Philosopher, seeking truth from our data. Truth is communicated in our programs through the boolean data type. Values of type boolean can […]
CS1: Lecture 15 – Logical Operators
Dear students, We’ve seen the arithmetic operators. We’ve seen the relational and equality operators. Today we meet the logical operators &&, ||, and !. These operators have boolean operands and yield boolean values; they are designed for gluing together simple predicates into compound ones. Before we look at them, let’s complete a little warmup exercise. […]
CS1: Lecture 13 – Test-driven Development
Dear students, Is there anything like charAt for integers? For instance, given a number and an “index” representing the place, can we get back the digit at that place? Not exactly, but there’s nothing stopping us from writing our own method to accomplish this task! But before we do that, let me share with you […]
CS1: Lecture 12 – Method Mechanics
Dear students, Just as writers write paragraphs, programmers write methods. Like a good paragraph, a method has a clear and narrow purpose. Just as paragraphs decompose a grand thesis into digestable points, methods decompose a large problem into manageable subproblems. Since so much of our time will be spent writing methods, it is paramount that […]
CS1: Lecture 11 – More Methods
Dear students, We’ll spend today continuing our discussion of methods—because we need practice. Java is a language, one invented by someone else, and we need to both speak it and hear it regularly in order to acquire it. Let’s start with an exercise in hearing Java, but with some parts inaudible. Fill in the Blanks […]
CS1: Lecture 10 – Abstraction
Dear students, When we discuss methods, there are really two areas of concern: the interface and the implementation. The interface is the method’s “shape,” detailing the method’s name, it number and type of parameters, and its return type. The implementation is the actual instruction that make the method fulfill its purpose. As consumers or callers […]
CS1: Lecture 9 – Methods with Return Values
Dear students, Today we dive deeper into our discussion of writing our own methods. We’ve actually been using methods all semester long; it’s just that now we’re starting to write our own. Before we dive in, let’s revisit our friend String. Stringo With Strings at our disposal, our programs start to feel human. We can […]
CS1: Lecture 8 – Methods
Dear students, Last time we distinguished between syntax (the grammatical rules) and semantics (the meanings) that guide our programs. When we invoke a method on an object—as in object.method()—we must know or learn the semantics of method if we want our program to do the right thing. With semantics in mind, let’s look at one […]
CS1: Lecture 7 – What’s Wrong With These?
Dear students, Today’s a bit of a clean-up day. There are some ideas that didn’t quite fit into our previous discussions, and I’ve also had the chance to see your code a few times now and want to address some concerns. Let’s have a day of miscellany. What’s Wrong With This? There are two dimensions […]
CS1: Lecture 5 – Primitive Types
Dear students, We’re going to start with a little game. You will pick a number, I will present to you a series of sheets with numbers written on them, you will tell me if your number is present, and I will tell you what your number is. It’ll be a little bit of magic! Or […]