-------------------------------------------------------------------------- Software Design and Development Winter 1997 COM 1205 --------------------------------------------------------------------------- Assignment 2 Due date: Monday, Jan. 20 --------------------------------------------------------------------------- This assignment is stored in file $SD/hw/2 in file assign.txt -------------------------------------------------------------------------- ========= On CCS Northeastern machines, OO=/proj/adaptive/www/course/ AOO=/proj/adaptive/www/course/f96/ On the WWW, OO = http://www.ccs.neu.edu/research/demeter/course/ On the WWW, AOO = http://www.ccs.neu.edu/research/demeter/course/f96 The course directory is: SD=$OO/w97-ug/ 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. > TO TURN IN YOUR HW, please send it to: > > com1205-grader@ccs.neu.edu Question 1: ----------- Consider the program statistics.java in $SD/hw/2/capacity-check 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/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 statistics.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. The reason is that some information is stored in the wrong place. It is stored in the visitor but should instead be stored in the visited object (host object). Your task is to make the Java program statistics.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. make test allows you to test the statistics.beh file after modification. 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 statistics.java to statistics.beh), you may hand in the statistics.java file for partial credit. Question 2: ----------- Consider the Java programs statistics.java in average-default-list/ average-other-list/ They both do the same "thing" which is described in the design statistics.beh. Both programs print out the running average as Weight-objects are encountered during the traversal. Change the programs so that they print only the running average when the computation is done for each container. The last number printed will be the average weight of all the items in the container. FOR FUTURE CLASSES: compute the average for each subcomponent. Example: For input: ( apple 12 ( apple 10 10) pear 9 ( apple 8 10) kiwi 6 50) the program should print three partial results, the last one being the overall average: java Main < statistics.input count sum count sum 11 = partial result count sum count sum 9.75 = partial result count sum 9 = partial result done 9 However, you don't turn in the two corrected Java programs but you lift the corrections in the two changed programs average-default-list/statistics.java average-other-list/statistics.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/f96/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. The Java documentation is local in: /proj/asl/boaz/java-documentation Or you can browse it directly on SUN's page. Start netscape with file: /proj/asl/boaz/java-documentation/preface.htm