Com S 100J Introduction to Computer Programming Grade: letter or S/U Spring 2007
341-132 TR 09:05 Olin Hall 255 Instructor: David Gries 4 credits
341-181 TR 11:15 Olin Hall 255 Newsgroup: cornell.class.cs100j

Announcements
Home
About email
Academic Excellence Workshops
Academic integrity
Announcements
DrJava
Exams
Grades
FAQs
Lectures
Assignments
Labs
Quizzes
Links
Staff info
Syllabus
Course material
Times & places
Newsgroup
Email Gries


February 25

About Assignment A4, NaN, etc.

Debugging A4.

January 21 About the course management system
January 21 Make extensions visible on your PC
January 21 How to get a summary of lectures
January 21 Seeing consultants, TAs, and Gries
   
   

About Assignment A4, NaN, etc..

1. NaN. In testing some of your methods, you may get a message saying that the expected value was something but the value produced was NaN. NaN is a constant of type double (just as 1 is a constant of type int and true is a constant of type boolean). It stands for Not a Number. It is the value of an expression that divides by 0, among other things. So it is quite likely that if you see such a method, your program divided by 0.


2. Using if-else statements. Some of the translations between color models are given in terms of exclusive cases. In the descriptions, the cases are often given in order of preference, and the first one that matches should be used. If you implement such situations using a sequence of if-statements, you will likely have an error, because the last if-statement whose condition is true will be the one that is used. Instead, use a sequence of if-else statements.

3. Use K instead of K' in RGB2CMYK. One more point. Some formulas in method RGB2CMYK mention K'. Mistake. Repalce all occurrences of K' in the description of RGB2CMYK by K. Knowing we took this from Wikepedia, you could have found this out by visiting that site.

4. Method toString(HSV hsv). This function should truncate to 5 (five) characters, not 4.


Debugging A4..

2. Debugging. Some of you will find that the CMYK and HSV values that appear in your A4 GUI are not the same as the ones that appear in our solution. This means that you have to debug to find the errors. You are new to this game of debugging, and it can take time at the beginning. You are learning to solve problems, to act like a detective to find the mistakes. This debugging may take time. We give some pointers here.

Note that you SHOULD check your GI against the solution GUI for number of different RGB values. The corresponding CMYK and HSV values should be the same as ours in both the original and the complementary colorpanes.

Function toString. To debug, you have to see output. It would be nice to easily see a representation of CMYK and HSV colors. Unfortunately, classes HSV and CMYK do not have toString methods, so write them! We'll do one here. First, copy function truncate5 from class A4methods to class CMYK. Then, add this method to class CMYK:

/** = string representation of this instance */
public String toString() {
return "(" + truncate5("" + c) + ", " +
truncate5("" + m) + ", " +
truncate5("" + y) + ", " +
truncate5("" + k) + ")";
}

Remember to indent this nicely once it is pasted into the class.

First step in testing.

Suppose an RGB color that is giving the wrong CMYK value is (95, 109, 156). Then type this into the DrJava interactions pane, one line at a time.

> rgb= new java.awt.Color(160, 146, 99);

> res= A4Methods.RGB2CMYK(rgb);

> res

This will cause function res.toString to produce your corresponding CMYK value, and it will be printed. It will probably be wrong. This shows you how to begin looking at what the different functions do without using the GUI.

Second step in testing.

Nw put println statements in function RGB2CMYK to find out what values you are calculating. At the same time, use your little calculator (a hand-held one or one on your computer) to determine what values SHOULD be coming out, based on the formula given in the handout.

For example, function CMYK probably may store a value in a variable Cprime. If so, put this statement in just after it is computed:

System.out.println("CPRIME: " + Cprime);

and then execute the above statements in the interactions pane again.

This can be an arduous, painstaking process or an exciting period of time spent as a detective. It all depends on your attitude. But this kind of debugging HAS to be done in order to find the error.

Avoiding the need to debug

The best way to avoid having to do such debugging is never to make errors. You can avoid lots of errors (but not all, of course) by following all the stratgies and principles that we espouse during the course, like (1) writing specifications before writing methods, (2) compiling and testing often as you write code, (3) writing definitions on variables, and so on.

 

 



Finding the error can often be done by putting print statement in the program to find out what the values of various variables are. It may take several tries to get print statement in the right place, as you hone in on the error. Put a statement like this:

     System.out.println("mx is: " + mx + " mn is: " + mn);

so that your output is appropriately labeled and you can understand it. It would be good to read Section 14.5 of the text at this point.

 

About the CMS (Course management system). We use a CS-designed "course management system" to manage assignments, tests, etc. DON'T DO ANYTHING ABOUT IT UNTIL WE ASK YOU TO! Thanks. The CMS for this course is at this URL: http://cms3.csuglab.cornell.edu/.

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 at handout 0, which summarizes what we did in lecture each time!

Seeing consultants, TAs, and Gries

Please feel free to see Gries during his office hours --or any time that he is there. If he is not working frantically on someting that has a deadline, he will be happy to chat with you. He also looks at email and answers it often.

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 by calling 255-0982 or going to the undergrad office (Upson 303). If you just have a question, go see a TA; 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.

Check here for office hours of TAs and the instructor. You can make an appointment for a one-on-one session with any TA at the undergrad office (Upson 303) between 9:30 and 4:30 M-F, or by emailing: ugrad@cs.cornell.edu--24 HOURS IN ADVANCE.

Consultants for CS100 live in 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.