-------------------------------------------------------------------------- Software Design and Development Winter 2002 COM 1205 -------------------------------------------------------------------------- Assignment 3 Due date: Jan. 31, 2002 -------------------------------------------------------------------------- This assignment is stored in file $SD/hw/3 in file assign.txt -------------------------------------------------------------------------- ========= We reuse the abbreviations already introduced in hw 1: ========= On CCS Northeastern machines, SD=/home/lieber/.www/com1205/w02 DemJ=/proj/adaptive/www/DemeterJava DJ=/proj/adaptive/www/DJ D=/proj/adaptive/www/ On the WWW, SD = http://www.ccs.neu.edu/home/lieber/com1205/w02 DemJ = http://www.ccs.neu.edu/research/demeter/DemeterJava DJ = http://www.ccs.neu.edu/research/demeter/DJ D = http://www.ccs.neu.edu/research/demeter/ ========= THEMES: Evolution of Java programs change design, translate to Java READING: Read chapter 7 of the AP book. Read Java book as necessary to understand enough of the Java programs which you need to modify in this homework. This homework requires use of DemeterJ (only a few features) and DJ. Browse the resource guide at: $D/DemeterJava/ Installing: For this homework, you need DemeterJ. Follow the instructions in: http://www.ccs.neu.edu/research/demeter/software/docs/install.html Please note that homework submission is electronic submission using blackboard. This will allow the teaching assistant to run your programs. In ADDITION, please turn in your answers in hardcopy at one of the following places: (1) Bring it to the class room and hand it to me. (2) In 161 Cullinane Hall: Put it into the teaching assistant's mailbox. John Sung's mailbox is about in the center of all the mailboxes. (3) In 161 Cullinane Hall: Put it into my mailbox. (4) If all those possibilities don't work for you, slide it under my office door. For blackboard, the format for files should be: hw3_[last name].zip you can either use winzip or "zip/unzip" on unix to package up your files. Please package up your whole directory, but without any .class or .java files. I'll be generating them from the DemeterJ files. Question 1: ----------- PART 1.A Motivation: Learn to modify simple adaptive programs. Consider the program in $SD/hw/3/onlyDJ-capacity-with-stack/gen/*.java which has been created from: $SD/hw/3/onlyDJ-capacity-with-stack/*.beh and the statistics.cd file. The *.beh files contain Java methods between {{ and }} that are assigned to various classes. Each *.beh file is of the form: X{ {{ // method 1 // method 2 // etc. }} } Y{ ... } ... and therefore the .beh files are basically 99.99999 % Java code. When you write your own .beh files, use your editor to make sure that the parentheses are balanced inside {{ and }}. NOTE: Please regenerate the gen directory using DemeterJ using "demeterj test". See http://www.ccs.neu.edu/home/lieber/com1205/w02/runningjava.html for set-up information regarding the compiler to use. The *.prj file is set up for javac, the SUN compiler. The purpose of this program is to read in a description of nested containers and to build a Java object. The program then checks whether each container satisfies its capacity restriction. Example: Consider the following container description in $SD/hw/3/onlyDJ-capacity-with-stack/statistics.input ( //begin container 1 apple 1 //item ( //begin container 2 pencil 1 //item ( //begin container 3 apple 1 //item 1) //capacity orange 1 1) //capacity orange 1 kiwi 1 5) //capacity ================= Container 2 is over capacity since it contains three items with a total weight of 3, but the capacity is one. Container 1 is also over capacity. It contains 6 items with a total weight of 6, but the capacity is 5. Container 3 is within capacity. For each container which is over capacity, the program should print a message of the form: total weight 2 but limit is = 1 OVER CAPACITY The program in $SD/hw/3/onlyDJ-capacity-with-stack/ contains a wrinkle: The wrinkle is conceptual in that the program gives wrong results: it does not detect all containers which are over capacity. Your task is to correct one or more of the *.beh files. demeterj test allows you to test the corrected *.beh files after modification. You should find the MINIMAL modification necessary to make the program correct. Turn in the corrected *.beh files (ONLY the corrected ones) and the output produced for file statistics.input. At the BEGINNING of each corrected *.beh file clearly indicate what you corrected. =================== Some technicalities DemeterJ has a project file facility which works pretty much the same on any platform (the file paths need to be adjusted from platform to platform). Typically, the project file is called program.prj A default program.prj file is generated by "demeterj new". I changed three lines in the default file: CDFILE = statistics.cd BEHFILES = statistics.beh TEST_INPUT = statistics.input You can do this much easier by just saying "demeterj new statistics". This creates a project named statistics, i.e., a project file named statistics.prj with these three variables set as shown above. If you use DemeterJ on a PC with Windows and you copy my program.prj, make sure you change the / to \ in the file paths. Also, you need to replace javacc by javacc.bat. PART 1.B Motivation: Learn to modify simple adaptive programs, learn about Java wrapper classes and class java.util.Stack. Learn about benefits of Selective Visitor pattern. Consider the corrected Java program from PART 1.A. The program is written in terms of some usage of the Java wrapper class Integer. Read in your favorite Java book about wrapper classes. You need them, for example, to work with Java hash tables or Java collection classes. Replace throughout the program, as much as possible, all occurences of Integer by int and adapt the Java program. Why cannot you eliminate all occurrences of Integer in the behavior files? You should update the statistics.cd and *.beh files and regenerate the Java code using DemeterJ. Turn in your modified files statistics.cd and *.beh and the output of your modified program (it should be identical to the output from 1.A). Question 2: ----------- The following files and directories refer to $SD/hw/3 Motivation: Learn about how an adaptive program defines a family of object-oriented programs. Learn how to modify one adaptive program instead of two object-oriented programs. Consider the Java programs *.beh in onlyDJ-average-default-list onlyDJ-average-other-list They are identical and you can convince yourself by running check-diff. Basically, I want changes to the *.beh files that are the same to both directories that would give the "correct" result in both directories. The differences between the 2 directories is the class dictionary. One is much simpler than the other. The Java program (in *.beh) is supposed to print out the running average as Weight-objects are encountered during the traversal. Unfortunately, the program is broken and you are asked to repair it with minimal changes to the files. Your task is to correct one or more of the *.beh files so that they work correctly in BOTH onlyDJ-average-default-list onlyDJ-average-other-list demeterj test allows you to test the corrected *.beh files after modification. You should find the MINIMAL modification necessary to make the program correct. Turn in for each behavior file that you changed the corrections that you made. Clearly indicate what you corrected in each *.beh file. ====================== System help: http://www.ccs.neu.edu/research/demeter/DemeterJava/setup.html When you think DemeterJ behaves unexpectedly, use demeterj clean