-------------------------------------------------------------------------- Adaptive Object-Oriented Software Development Fall 1998 COM 3360/NTU SE737 Karl Lieberherr --------------------------------------------------------------------------- Midterm --------------------------------------------------------------------------- Open book and open notes. Question 1: 60 points Question 2: 18 UNKNOWNs: 2 points each 36 points Question 3: 6 UNKNOWNs, 2 points each: 12 points TOTAL: 108 To make the grading easier, please put your values for the unknowns on the enclosed answer sheet. THE GAME OF REDUNDANCY AND UNKNOWNS ----------------------------------- Most of the questions in this exam ask you to determine unknowns of the form UNKNOWN1, UNKNOWN2, ... This makes it easier for you to answer the questions, since you get extra context information. Yet you need to master the behavioral objectives of the course to answer the questions. Guessing an answer is not a successful strategy and therefore a "game of redundancy" test is more interesting than a multiple choice test. The questions have the following pattern: I show you several artifacts which are related by the theory of object-oriented design and programming. Because of the dependencies between the artifacts, some of the information is redundant and can be recovered from the context by applying the objectives covered in the course. The information which you should discover is marked UNKNOWNx. If an unknown is not uniquely determined, mark the answer with *CHOICE*. An unknown may be anything, e.g., a number, an identifier, a character, two identifiers with a blank between them, a string etc. If an unknown is the empty string, give NOTHING as answer, e.g., UNKNOWN = NOTHING. Example: 5 + UNKNOWN1 = 8 UNKNOWN1 = 3 --------------- UNKNOWN2 * UNKNOWN3 = 20 UNKNOWN2 = 4 *CHOICE* UNKNOWN3 = 5 *CHOICE* At the beginning of a question we give the number of points per unknown. Question 1: ==================================================== 60 points The task is to implement a simple project from design through implementation using Adaptive Programming. Write a program that takes as input object descriptions of the following form -> A,b,B by {-> A X -> X B} -> B,c,C by {-> B C bypassing U} => C,D by {-> C Q -> Q D} ~> D,E by {-> D S -> S E} Such a description is called a Mapping and it consists of a list of entries (one per line) each one consisting of a c-edge and a list of s-edges, separated by the keyword "by". There are three kinds of c-edges, as shown in the example. There is one kind of s-edge with an optional part specifying one node to be bypassed. There are four subquestions: 1.a Define a class dictionary for such inputs. 1.b Write an adaptive program for your class dictionary that produces two kinds of outputs for a Mapping-object: The set of sources of the c-edges and the set of sources of the s-edges. For the above input, the output should be: sources of c-edges: className A className B className C className D sources of s-edges: className A className X className B className C className Q className D className S - 1.c How would you change your class dictionary and your language if you wanted to represent the edges by Edge : ConstructionEdge | AlternationEdge | RepetitionEdge *common* Source Target. 1.d IF YOU ARE DONE WITH ANSWERING ALL OTHER QUESTIONS ON THE ENTIRE EXAM: Give a description of the Java code that will be generated from your adaptive program. Question 2: ==================================================================== 18 UNKNOWNs: 2 points each Below is a class dictionary, an adaptive program, an input and corresponding output and the traversal graph. Find the unknowns. CLASS DICTIONARY ================ Container = "(" List(Item) Capacity [ Integer] ")". Item : Container | Simple. List(S) ~ {S}. Simple = Ident Weight. Capacity = Integer. Weight = Integer. SummingVisitor = Integer int. CheckingVisitor = SummingVisitor. Main = . ADAPTIVE PROGRAM ================ Container { traversal allWeights( CheckingVisitor cV, SummingVisitor sV ) { to Weight;} // traverse while counting and summing void checkCapacity() throws Exception (@ SummingVisitor sV = new SummingVisitor(); CheckingVisitor cV = new CheckingVisitor(); cV.set_sV(sV); this.allWeights(cV, sV); @) } SummingVisitor { init (@ UNKNOWN2 = new Integer(0); @) before Weight (@ System.out.println("sum " + total.intValue()); UNKNOWN3 = new Integer(UNKNOWN4.intValue() + UNKNOWN5.get_i().intValue()); @) before Container (@ UNKNOWN6.set_UNKNOWN7(this.get_UNKNOWN8()); System.out.println(" start new container "); @) after Container (@ this.set_tot(this.get_UNKNOWN9().intValue() - UNKNOWN10.get_UNKNOWN11().intValue()); @) } CheckingVisitor { after Container (@ int diff = sV.get_tot(); int cap = UNKNOWN12.get_capacity().get_i().intValue(); if (diff > UNKNOWN13.get_capacity().get_i().intValue()) { System.out.println(" total weight " + diff + " but limit is = " + cap + " OVER CAPACITY "); }; System.out.println(" end container "); @) } Main { (@ static public void main(String args[]) throws Exception { UNKNOWN14 a = UNKNOWN15.parse(System.in); a.UNKNOWN16(); System.out.println("done "); } @) } 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 OUTPUT: ======= start new container sum 0 start new container sum 1 start new container sum 2 end container sum 3 total weight 3 but limit is = 1 OVER CAPACITY end container sum 4 sum 5 total weight 6 but limit is = 5 OVER CAPACITY end container done TRAVERSAL GRAPH: ================ // gen/allWeights_Container.trv Container = UNKNOMN17 Item : Container | Simple . Simple = Weight . Weight = . Item_List UNKNOWN18 Question 3: =============================================================== 6 UNKNOWNs, 2 points each: 12 points Consider the following class dictionary, adaptive program and traversal graph and output. Find the UNKNOWNs. CLASS DICTIONARY: ================= A = B C D. B = R S T. C = Z. T = Z. R = . S = . D = T. Z = . Main = . ADAPTIVE PROGRAM: ================= Main { public static void main(String args[]) throws Exception (@ A m = A.parse(System.in); m.f(); System.out.println(" done "); @) } A { void f() to Z { before Z (@ System.out.println("at Z"); @) } } TRAVERSAL GRAPH: gen/__trav_f_A.trv A = UNKNOWN1. B = UNKNOWN2. C = UNKNOWN3. T = UNKNOWN4. UNKNOWN5 Z = . OUTPUT OF THE PROGRAM (for the only legal input object) UNKNOWN6