-------------------------------------------------------------------------- Adaptive Object-Oriented Development Fall 1997 COM 3360 --------------------------------------------------------------------------- Assignment 2 Due date: Thursday, Oct. 9 --------------------------------------------------------------------------- This assignment is stored in file $AOO/hw/2 in file assign.txt -------------------------------------------------------------------------- You may turn in your hw for full credit up to two working days late. This means, if it is due on Thursday, you can turn it in the following Monday. If it is due on day x, it means midnight of day x. For late homework we will deduct 10% per day late, unless you present a very good reason to Alexey. I am sorry for having such a rule, but it is better to have a clear policy with a class of 40 students. I am very pleased to report that the NTU section has grown 600% since last year. NTU students, often with extensive experience in OO, are often very valuable class members. Here is a writing of a former NTU student, Brad Appleton from Motorola, which he posted on a news group. http://www.ccs.neu.edu/research/demeter/demeter-method/LawOfDemeter/AppletonExplainsDemeterNEW.txt Last year, Debra Bacon from HP contributed: http://www.ccs.neu.edu/research/demeter/evaluation/conventional-env/hp.html ========= On CCS Northeastern machines, D=/proj/adaptive/www/ OO=$D/course/ AOO=/proj/adaptive/www/course/f97/ On the WWW, D = http://www.ccs.neu.edu/research/demeter/ On the WWW, OO = http://www.ccs.neu.edu/research/demeter/course/ On the WWW, AOO = http://www.ccs.neu.edu/research/demeter/course/f97 Further useful URLs are on page 589 of the AP book. ========= THEMES: Evolution of Java programs change design, translate to Java Applets and reuse versus rewrite 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 Demeter/Java. Browse the resource guide at: $D/DemeterJava/use Read about related tools which promote a traversal/visitor style to programming at: http://www.ccs.neu.edu/home/lieber/suntest.html Read about Java packages in your favorite Java book. ================= TO TURN IN YOUR HW, please use the submit3360 command (or equivalent on your PC) which packages your directories and mails them to: com3360-grader@ccs.neu.edu Question 1: ----------- PART 1.A Consider the program gen/*.java in $AOO/hw/2/capacity-check NOTE: Please regenerate the gen directory using Demeter/Java. 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 $AOO/hw/2/capacity-check/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 capacity-check/gen/*.java 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 make the Java program capacity-check/gen/*.java work and to figure out what is wrong. However, you don't turn in the corrected Java program, but instead the corrected program statistics.beh. In other words, you have to "lift" the correction you did to the Java program to the adaptive Java program in statistics.beh. On Unix, make test allows you to test the statistics.beh file after modification. On a PC, call demjava to regenerate and compile everything. Turn in the corrected program statistics.beh and the output produced for file statistics.input. If you are unable to perform the reverse enginering (going from capacity-check/gen/*.java to statistics.beh), you may hand in the capacity-check/gen/*.java files for partial credit. PART 1.B Consider the Java program in directory capacity-with-stack. This program solves the capacity checking problem correctly using a Java stack and the program is a Java package called RecursiveContainer (see class dictionary; note that in the Makefile the package name also has to be set to RecursiveContainer.). The program is written in terms 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. This program uses a wrapper class since earlier versions of Demeter/Java required this. Now you can use type int instead of type Integer. 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 file? You should update the statistics.cd and statistics.beh files and regenerate the Java code using Demeter/Java. Turn in your modified files statistics.cd and statistics.beh. (statistics.beh solves the problem in two different ways (checkCapacity() and checkCapacity2()). Rewrite both without wrapper classes, as much as possible.) Question 2: ----------- Consider the Java programs gen/*.java in average-default-list/ average-other-list/ They both do the same "thing" which is described in the design statistics.beh which is the same in both directories (linked). Both Java programs print out the running average as Weight-objects are encountered during the traversal. Change the programs so that they print the average for each subcontainer. Example: For input: ( apple 12 ( apple 10 10) pear 9 ( apple 8 10) kiwi 6 50) the program should print three partial results. However, you don't turn in the two corrected Java programs but you lift the corrections in the two changed programs average-default-list/gen/*.java average-other-list/gen/*.java to the file: statistics.beh which is the same for both programs. Turn in the modified file statistics.beh. If you are unable to perform the reverse enginering (going from *.java to *.beh), you may hand in the *.java files for partial credit. Question 3: ----------- The purpose of this part is to familiarize yourself with a simple applet. Go to the following URL: http://www.ccs.neu.edu/research/demeter/course/f97/hw/2/hello-applet/HelloWorld.html using Netscape version 2 or later. The applet you run is defined by the following Java code: import java.applet.Applet; import java.awt.Graphics; public class HelloWorld extends Applet { public void paint(Graphics g) { g.drawString("Hello world!", 50, 25); } } Answer the following questions: In which class is method drawString defined? List all superclasses of class HelloWorld. List all superclasses of class Graphics.