-------------------------------------------------------------------------- Software Design and Development Fall 2000 COM 1205 -------------------------------------------------------------------------- Assignment 3 Due date: Oct. 19, 2000 -------------------------------------------------------------------------- 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/f00 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/f00 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 chapters 5, 6, 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/ Read about related tools which promote a traversal/visitor style to programming at: http://www.ccs.neu.edu/home/lieber/suntest.html A quote from the above URL: ==================== Visitor Support JJTree provides some basic support for the visitor design pattern. If the VISITOR option is set to true JJTree will insert an jjtAccept() method into all of the node classes it generates, and also generate a visitor interface that can be implemented and passed to the nodes to accept. ==================== Turn in your homework in hardcopy. Installing: For this homework, you need DemeterJ. Follow the instructions in: http://www.ccs.neu.edu/research/demeter/DJ/docs/install.html 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 "demjava test". See http://www.ccs.neu.edu/research/demeter/course/f00/runningjava.html for set-up information regarding the compiler to use. The *.prj file is set up for jikes, the IBM compiler. So you need to set up your account for jikes use. 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. demjava 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 "demjava 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 "demjava 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 statistics.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. 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 demjava 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/course/f00/runningjava.html http://www.ccs.neu.edu/research/demeter/DemeterJava/setup.html When you think DemeterJ behaves unexpectedly, use demjava clean