CS 1110 Introduction to Computing using Java Grade: letter or S/U Fall 2008
8546 TR 09:05 Hollister B14 Instructor: David Gries 4 credits
8548 TR 11:15 Hollister B14 Newsgroup:

A7 Questions and Answers
About email
Academic Excellence Workshops
Academic integrity
Staff info
Course material
Times & places
Email Gries

Below are questions asked about A7 and our answers to them. They are ordered chronologically, with the latest ones asked first.

11. The input file topics.txt has several blank between two things on a line. Is that a mistake?

No, it is not a mistake. There are 1 or more blanks between things on a line of the input file. You don't have to write a loop to find the end of the blanks, or anything like that. Look at the function in class String and find one that will help here.

10. Can I write the program to use only the input file topics.txt with the shark and the monkey?

Of course not. This program should work with any input file. There might be 50 different topics in the file, each with its own image. Your program must make up the list of topics from the input file.

9. How can I tell how many pixels a string will take when drawn in the JPanel?

You don't have to know this exactly in order to draw the terms at the end of lines. We will not be too picky about the placement of terms. However one student looked at the API specs and found out how to determine this. He noticed function Graphics.getFontMetrics() and then looked at the spec for class FontMetrics and found a few useful functions, like stringWidth() and getStringBounds(...). This is good! This student has learned to be resourceful and find for themself what they need.

8. My call gui.setUpImage( topic.substring( topic.lastIndexOf(" ") ) ); doesn't make the shark picture appear. topic is the String that contains the line from topics.txt with the topic and image name on it.

You are asking us to debug your program for you. And without complete information. We don't do this. Put some println statements in appropriate places to help youself debug this. You need to know exactly what the value of the argument of the call is.

7. When alphabetizing the terms, what is the best way to go about doing it? Do we have to compare all the characters of each string to see which is lower?

The fact that you asked the question means that you do not yet have the right frame of mind to search for answers yourself. Please look a the API package for class String to see whether there is an appropriate method. "Alphabetically" and "lexicographically" mean the same thing here.

6. In file topics.txt, some of the lines have several blanks between the names and numbers, and not just one. Can I change this? All the weird spacing confuses me.

Sorry, since the specification says that there may be several blanks between the numbers and names, you have to program A7 to accept them.

5. Question: In the handout it says that each item should be on a different line. In the topics.txt file that I downloaded, there were no line breaks.

The application you are using to look at the file is not treating line ends appropriately. Two things are used for line breaks: a carriage return and a line feed. Windows, Mac, and Unix cover all possible usages: one uses one, one uses the other, and one uses both. Macintosh applications generally will allow any combination. Windows applications are often less flexible: do it the windows way or else. This is not very usef friendly.

You can open file topics.txt in DrJava and see it, if you wish. You will see that it consists of several lines. But close it before compiling because it won't compile. In DrJava, when you click open, a dialog window opens. Near the bottom of it, note the pull-down menu, which allows you to select the option to allow all files.

4. Question: Are we allowed to create methods of our own? Must we implement the methods as you have already written? For example, can we change one of them from a procedure into a function?

You can do anything you want, except: You may not change the interface between class A7 and the gui, i.e. the specifications and headers of the 3 methods called by the GUI and the 6 GUI procedures that the A7 calls.

This is because you have no control over class A7GUI and A7Panel.

3. Question: I think procedure "associate terms" should make changes to the colors that method drawLabelLines uses. Is that correct?

We cannot answer such questions, because there is no "correct" way of doing this. Further, it is your job to design, implement, and debug this program.

We can say this. A key to any such program is maintaining the "data structures" used in the program. In this case, the data structures used are: field A7.inputfile (which contains the input) and field A7.items (the dictionary of items for the current topic). Every method should be able to rely on their meanings and constraints on them (i.e. the class invariant), and every method must change these if necessary, so that the class invariant is always true. So, in writing the interface methods (the GUI methods that A7 calls and the A7 methods that the GUI calls) always ask yourself, what do I know about the current state in field items, and how should I change field items?

The comment on field items says that it contains the dictionary of items for the current topic. It would be wise to also put into the comment the details of the format of the dictionary, so you can always look at it.

2. Question: Shouldn't method Item.compare be static?

Yes. Since it doesn't refer to a field or method in class Item, it should be static. But please do not change it! We gave you the specification, and we all have to live with it as it is.

1. I am having trouble understanding what exactly we must do for method associateTerm. Could you please clarify what that method needs to accomplish?

The specification of method associateTerm(t,n) says it all: it has to process the player's request to associate term t with line number n. It is your task to figure out how to accomplish this. Look carefully at the answer to question 3.

0. How is this assignment graded? Will we lost points for the way we write things even if it works?

This assignment is graded not only on correctness but also on your design and implementation. In this assignment, you have a lot more freedom in designing your own methods. You should follow all the principles and strategies that we have talked about over the semester. Do you do the same thing in many places instead of writing a method and calling it in several places? Are the set of methods you write a reasonable way to design this program? Do you have a method that is 100 lines long (you shouldn't)? Have you clearly specified each method you write?

We will be not be overly strict on this issue, but we reserve the right to deduct points for things that are obviously (to us) bad practice.