CS 1110 Introduction to Computing using Java    Fall 2009  
11081 TR 09:05 Olin Hall 255 Instructors: David Gries & Lillian Lee  
11083 TR 11:15 Olin Hall 255 Grade: letter or S/U.   Credits: 4
flue image

Announcements


28 November A7: listening to mouse movement
16 October A4: a subtle error in the GUI
10 October A4: a note on round2Five
7 October A subtle programming error in function eatenBySame
7 October The principle of using existing methods applied to A3
11 September Using VideoNote
11 September About quizzes
11 September About labs
2 September Haven't received any CS1110 email yet?
2 September No serial number/device ID on your iClicker?
Register your iclicker, even if it's used.
28 August Complete quiz 1. "First Day Survey"
28 August About the course management system
28 August About H1N1 flu preparations
8 August Make extensions visible on your PC
8 August How to get a summary of lectures
8 August Seeing consultants, TAs, Lee, Gries

A7: Listening to mouse movement. We are getting emails about how to get the paddle to respond to mouse movements. We give some details here, but basically we want to to figure this out. Read below carefully and try to figure it out yourself. If you are still unable to listen to a mous movements, feel free to email us.

We talked about the concepts you need for listening to mouse events in the GUI lectures, and Tuesday's lecture gave a bit more detail, for reference.

(a) What are the three things that must be done to react to a mouse event? We didn't repeat them in the A7 handout because they were given quite clearly in the second GUI lecture. So look carefully at the second GUI lecture and understand what was done to listen to a mouse event.

(b) One thing we gave you in the handout: you had to write method mouseMoved.

(c) What else needs to be done? Wouldn't it stand to reason that the ACM folks who built the graphics package would provide what you need? Is Breakout a subclass of something? Perhaps the ACM folks have written some intermediate code layer that takes care of what has to be done. How might you find out?

A subtle error in A4. The text fields and buttons that allowed the user to input color values and then click one of the buttons were added just this semester. An error was introduced that had noting to do with the computation. Instead it has to do with "listening to sliders". It is fixed, and you can now use the applet and jar

Here's the quite subtle error, which took time to find. Whenever a slider value is changed, the system notices it and calls a method to process the change. So when values were placed in the CMYK fields and the InCMYK button was clicked, a lost of computation went on that ended up setting many slider values. Each change in the slider value caused the method that "listened to sliders" to be called, resulting in more unexpected computation, and ths caused the error.

The solution was: When a button like InCMYK is clicked, in the method that is called, (1) turn off listening to changes in sliders, (2) do all necessary computation and setting of the GUI, including the slider values, and finally (3) turn on listening to changes in sliders.

Much laer in the course, we will show you how GUIs are built and show you how methods are written and registered with the system to listen to events, like button clicks and changes in cliders. You will not have to learn much of this kind of stuff, but it will be useful for you to ahve seen it.

Sorry for this mistake.

More help on function round2Five. The tendency is to try to convert d to a String so that the period can be located, change the result a bit, convert back to a double, and call truncate2Five. Resist this temptation. It's clumsy and awkward. Instead, just add something to d and then call truncate2Five --what you add may depend on the size of d.

Suppose d >= 100. Then, the five-character result will have the form xxx.x, where the x's are digits. Ask yourself what you have to add to d so that truncating to 5 characters will then yield the right result. Here are two cases to consider:

d                after adding something and truncating to 5 digits
321.4667    321.5
321.4461    321.4

We could tell you what to add to d in this case, but then you don't learn yourself how to solve little problems.

Besides d >= 100, there are two other cases to deal with: 10 <= d < 100  and  d < 10.

A subtle programming error in function eatenBySame. What should be the value of the call Organism(b, c) where b and c are Organisms that are still alive, that is, have not been eaten? Looking at the specification,

= "org1 and org2 are not null and were eaten by the same Organism."

one would conclude that the value of the call is false. Two alive organisms certainly were not eaten by anything. But many of the eatenBySame functions in A3 submissions said the value was true. This is because, if both eatenBy fields are null, b.eatenby == c.eatenby is true. The body of this function should not have been:

return org1 != null   &&   org2 != null   &&  org1.eatenBy == org2.eatenBy;

It should have been:

return org1 != null   &&   org2 != null   &&  org1.eatenBy != null   &&   org1.eatenBy == org2.eatenBy;

If one had developed test cases beforehand, with an eye to covering all possibilities and extreme cases (e.g. eatenBy(b, b), where b is alive), the error would have been detected. Developing good test cases taks conscious efforst and is an arts in itself.

The conclusion to draw is that programming can involve subtle points, and one must be careful in the specifications of programs, in their implementations, and in testing them. For some, this whole process can be tedious. Others have immense satisfaction in this process of specifying, implementing, and testing. To each their own.

The principle of using existing methods applied to A3. We have mentioned (and illustrated) several times the use of a previously written and tested method in writing new methods. This principle can save programming time, reduce the number of errors introduced into a program, and make testing easier. Below, we give another example from A3. Note how simply the third constructor is written using two calls on other methods:

/** Constructor: a new Organism at food-chain level lev with m units of methylmercury; its
      nickname is nn. This new Organism has not eaten any Organism; eater immediately eats it.
      Precondition: nn has at least 1 char, lev and m are non-negative, and eater is not null. */
public Organism(int lev, int m, String nn, Organism eater) {
    this(lev, m, nn);
    eater.eat(this);
}

Here is a second example. The second isHigherThan function can be written using a call on the first.

/** = "org1 is not null and org2 is not null and org1 is at a higher level than org2."*/
public static boolean isHigherThan(Organism org1, Organism org2) {
     return org1 != null && org1.isHigherThan(org2);
}

Here, note how the specification is simply translated into Java:

1. org1 is not null   is translated into   org1 != null

2. and    is translated into   &&

3. Compare the expression   org2 is not null and org1 is at a higher level than org2   with the specification of the first isHigherThan function,

org is not null and this organism is at a higher level than org

and you see that the expression can be translated into   org1.isHigherThan(org2) .

A note on assignment a1. Procedure eat may be difficult for you for two reasons: (1) it has to change fields of two objects, victim and the one in which the method being executed resides. Four assignment statements will be needed in this procedure. (2) Somehow, it has to refer to the object in which the method being executed resides. Suppose the call

org.eat(vic);

is being executed. The best thing for you to do is to draw the two objects, writing down (only) the variables and fields being used. Get in the habit of drawing objects to help you figure things out.

Now, java has keyword this. Here is its definition: the value of this is is the name of the folder (object, instance) in which it appears. This is explained on

VideoNote Beginning Tuesday, 15 September, the 11:15 lecture will be filmed and place on www.cs.cornell.edu/videonote/cornell. Along with the video comes a table of contents; click on an item and the video changes immediately to the place corresponding to the item you clicked.

Use VideoNote as a supplement to the course. Look at a video if you want to go over some part. If you have to miss a lecture because of the flu, anther illness, an interview, a sports roadtrip, use VideoNote to see the lecture.

Don't use VideoNote to skip class regularly, as a prop to allow you to postpone studying, and so on. That will hurt you in the long run. Our study of the use of VideoNote shows that it can hurt rather than help the C- student who misses lots of lectures and procrastinates on studying because they feel they can catch up later with Videnote.

Together, the provost's office and the College of Engineering are spending $5,000 so that you can have access to VideoNote. Appreciate that.

About quizzes. About 80% of the class got 100 on the first quiz. They had no problem with explaining how to execute an assignment statement <var>= <expr>; ---evaluate the <expr> and store its value in the <var>.

However, the other 20% had not studied enough to know this simple fact. This is disheartening for us. We are working so hard to give you a good, effective experience in learning programming using Java. After many years of teaching, we know what works and doesn't work. We know that if you don't learn some basic things right away, as soon as you hear them, you will have a very difficult time later on. We also know that teaching (and learning) the next material is far far easier if you have learned the current material. The course builds steadily; it is cumulative.

So we give quizzes. We tell you precisely what will be on a quiz, because we know you should master that material immediately. We know the consequences if you don't. We expect everyone to get 100 on each quiz.

You have a quiz on Tuesday, 15 September. Please, everyone get 100 on it. What will be on the quiz is explained here.

What we have done so far is not difficult, just new. Achieving full understanding and a fluency in Java requires practice. It is better to practice every day for 15 minutes, reading the book and doing exercises on the computer using DrJava, than it is to wait 2 weeks and then spend 6 hours cramming. Please learn to budget your time for maximum learning.

About labs. Please read these guidelines for labs carefully.

  1. You are expected to attend a lab session each week. You do not have to be formally registered in the lab you attend, but you should regularly attend the same lab. If you miss more than 3 labs (or don't do the assignment for 3 labs) without a reasonable excuse given to the Lab TA beforehand, we reserve the right to lower your grade a notch (e.g. from B to B-). We don't do this very often, but we reserve the right to do it.
  2. If you do not complete a lab the week on which it is handed out, complete it at home during the week and show it to your Lab TA the next week.
  3. Labs that are not completed by the next week will not be counted.
  4. Please do not email Profs. Gries or Lee about who to see or what to do if you missed a Lab. Talk to your LAB TA.

Haven't received CS1110 email yet but able to login to to the CS1110 CMS website? The problem may be that you've set email forwarding improperly; we've received a few email bounce messages. Check that you are having mail to <your netID>@cornell.edu forwarded to a valid addresss. (If you also can't login to the CMS website, then the problem is that you aren't entered into the system; email Maria Witlox, as described in the CMS announcement below.)

No serial number/device ID on your iClicker? This number, needed to register the clicker, can be recovered by bringing your clicker to (a) the Academic Technology Center Room 123, Computing and Communications Center on the Ag Quad, open 9-5; (b) the ATC's G27 Stimson Hall office near Day Hall, open 12-5; or (c) Prof. Gries and Lee's office hours, 167 Olin Hall, Tuesdays and Thursday 10:10-10:55.

Register your iClicker, even if it's used. Do so by visiting http://atcsupport.cit.cornell.edu/pollsrvc . You'll login with your netID and password, and you'll need the serial number, or device ID, of your clicker, which can be found, perhaps near a "bar code", on the back (you may wish to put some invisible tape over the serial number or write it down somewhere, since the numbers can rub off). Note that each individual student in CS1110 needs their own clicker.

Complete Quiz 1 ("First Day Survey") on the CMS. It's available by logging in at this URL: http://cms.csuglab.cornell.edu/. If login fails or you don't see the course "CS1110" listed, it may be because you are not entered into the CMS, in which case, email Maria Witlox at mwitlox@cs.cornell.edu, letting her know your netID and that you are in CS1110.

About the CMS (Course management system). We use a CS-designed "course management system" to manage assignments, tests, etc. The CMS for this course is at this URL: http://cms.csuglab.cornell.edu/.

When you visit the site, you will have to give your Cornell netid and password. Then, if you see the course number CS1110, click on it to get to the CMS. If you don't see the course number, that means you are not yet registered in the CMS. Email Maria Witlox mwitlox@cs.cornell.edu and ask her to add you. You must give her your netid.

H1N1 flu preparations. See this link

Fix your PCs so that extensions (like .java and .doc) ALWAYS appear. To do this, do the following: Open an explorer window. Use menu item Tools / Click on Folder Options. Click the view tab. Uncheck the box "Hide extensions for known file types".

Summaries of lectures
Please look courseOutline.html, which summarizes what we did in lecture each time!

Seeing consultants, TAs, Lee, Gries

Check here for office hours of TAs, Lee, and Gries.

The TAs have office hours. If you need some conceptual help of any kind, go the the TAs during their office hours. Choose any TA whose office hours are convenient for you; you don't have to limit yourself to your Section TA.

TAs have a closed office hour and an open office hour. If you want time alone with a TA because you just don't understand or are falling behind, then arrange a closed session contacting a TA individually. If you just have a question, go see a TA during their open office hour; there may be other people there at the same time, and you can all hear each others' questions/answers. The closed hours will act like open hours if no one has made an appointment.

You can make an appointment for a one-on-one session with any TA. Contact the TA.

Consultants for CS1110 hold hours in the green room of the ACCEL Lab, which you get to through the Engineering Library in Carpenter Hall. You may spend a good deal of time programming there. The consultants are there to answer your questions. If you need help downloading and setting up DrJava, if you have a misunderstanding on an assignment, if you are having trouble debugging a program —in all such matters, ask the consultants for a quick answer. However, they will not write your program for you.