from /proj/asl/lieber/java/java-envs/jk-sys-simpler/questions -------------------------------------------------------------------------- Software Design and Development Fall 1996 COM 1205 --------------------------------------------------------------------------- Final exam Question 1: 7 UNKNOWNs, 9 points each : 63 Question 2: 21 UNKNOWNs, 8 points each : 168 Question 3: 50 points Question 4: 64 UNKNOWNs, 1 point each: 64 345 points total --------------------------------------------------------------------------- Open book and open notes. 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. --- HAPPY HOLIDAYS --- Question 1: ================================================================= 7 UNKNOWNs, 9 points each : 63 /proj/asl/lieber/java/java-envs/jk-smallest Consider the following behavior file program.beh. Find the SMALLEST (in terms of number of characters) class dictionary program.cd so that program.beh and program.cd result in an executable Java program. program.beh ============================ A{ traversal t(V v) { to D;} } ClassGraph { traversal f() { to *;} } V { before B (@ set_i(new Integer(5)); @) before C (@ System.out.println(get_i()); @) before D (@ Q q = new R(); @) } Main { (@ static public void main(String args[]) throws Exception { ClassGraph a = ClassGraph.parse(System.in); a.f(); A a1 = A.parse(System.in); V v = new V(); a1.t(v); System.out.println("done "); } @) } Fill in the UNKNOWNS below in file program.cd: A = UNKNOWN1. B = UNKNOWN2. C = UNKNOWN3. D = . V = UNKNOWN4 . UNKNOWN5 = . Main = . UNKNOWN6 : UNKNOWN7. R = . Question 2: ================================================================= 21 UNKNOWNs, 8 points each : 168 /proj/asl/lieber/java/java-envs/jk-sys-simpler Consider files program.beh, program.cd and program.input below. Find the unknowns in the output shown after program.input. program.beh ------------------------------------------ EquationSystem{ (@ void f() { V1 v1 = new V1(); t1(v1); } @) (@ void g(Variable w) { // creates a new visitor object for each call V2 v2 = new V2(new Equation(), w); t2(v2); } @) traversal t1(V1 v1) { bypassing Exp to Variable;} traversal t2(V2 v2) { bypassing {-> Equation,var,Variable} to Variable;} } V1{ before EquationSystem (@ e = host; @) before Variable (@ // find out where used System.out.println(" V1 " + host.get_variableName().toString()); e.g(host); @) } V2{ before * (@ System.out.println("V2 is in " +host.getClass().toString()); @) before Equation (@ equation = host; @) before Variable (@ System.out.println(" V2 variable " + host.get_variableName().toString()); if (host.get_variableName().equals(variable.get_variableName())) { System.out.println(" V2 " + host.get_variableName().toString() + " is used in an equation"); } @) } Main { (@ static public void main(String args[]) throws Exception { EquationSystem e = EquationSystem.parse(System.in); e.f(); System.out.println("done: "); } @) } program.cd -------------------------------------------------- EquationSystem = List(Equation). Equation = Variable "=" Exp "." . Exp : FunctionCall | Variable | Numbe. FunctionCall = "call" Function CommaList(Variable) . Variable = Ident. Function = Ident. Numbe = Integer. List(S) ~ {S}. CommaList(S) ~ "(" S {"," S} ")". Main = . // visitors V1 = EquationSystem. V2 = Equation Variable. program.input -------------------------------------------- A = B. B = 2. C = 3. Z = call f(A, B, C). The output is below java Main < program.input UNKNOWN1 V2 is in class EquationSystem V2 is in class Equation_List V2 is in class Nonempty_Equation_List UNKNOWN2 V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class FunctionCall V2 is in class Variable_CommaList V2 is in class Nonempty_Variable_CommaList UNKNOWN3 UNKNOWN4 V2 is in class Nonempty_Variable_CommaList UNKNOWN5 V2 is in class Nonempty_Variable_CommaList UNKNOWN6 UNKNOWN7 V2 is in class EquationSystem V2 is in class Equation_List V2 is in class Nonempty_Equation_List UNKNOWN8 UNKNOWN9 V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class FunctionCall V2 is in class Variable_CommaList V2 is in class Nonempty_Variable_CommaList UNKNOWN10 V2 is in class Nonempty_Variable_CommaList UNKNOWN11 UNKNOWN12 V2 is in class Nonempty_Variable_CommaList UNKNOWN13 UNKNOWN14 V2 is in class EquationSystem V2 is in class Equation_List V2 is in class Nonempty_Equation_List UNKNOWN15 V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class FunctionCall V2 is in class Variable_CommaList V2 is in class Nonempty_Variable_CommaList UNKNOWN16 V2 is in class Nonempty_Variable_CommaList UNKNOWN17 V2 is in class Nonempty_Variable_CommaList UNKNOWN18 UNKNOWN19 UNKNOWN20 V2 is in class EquationSystem V2 is in class Equation_List V2 is in class Nonempty_Equation_List UNKNOWN21 V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class Numbe V2 is in class Nonempty_Equation_List V2 is in class FunctionCall V2 is in class Variable_CommaList V2 is in class Nonempty_Variable_CommaList UNKNOWN22 V2 is in class Nonempty_Variable_CommaList UNKNOWN23 V2 is in class Nonempty_Variable_CommaList UNKNOWN24 done: Question 3: ================================================================= 50 points Write a class dictionary for your favorite video store. You will use the class dictionary to keep track of customers, rentals and returns and of fines. Write a program for your video store which prints the list of videos which have been checked-out. Question 4: ================================================================= 64 UNKNOWNs, 1 point each: 64 Consider the following sentence describing an object (program.input): A = call f1(A,B). B = call f2(C,A). C = 3. D = call f(A, B, C). The class dictionary is program.cd (same as in question 3): program.cd EquationSystem = List(Equation). Equation = Variable "=" Exp "." . Exp : FunctionCall | Variable | Numbe. FunctionCall = "call" Function CommaList(Variable) . Variable = Ident. Function = Ident. Numbe = Integer. List(S) ~ {S}. CommaList(S) ~ "(" S {"," S} ")". Main = . // visitors V1 = EquationSystem. V2 = Equation Variable. Find the unknowns in the following object: : UNKNOWN1 ( < UNKNOWN2 > : UNKNOWN3 { : UNKNOWN4 ( < UNKNOWN5 > : UNKNOWN6 ( < UNKNOWN7 > : Ident "A" ) < UNKNOWN8 > : UNKNOWN9 ( < UNKNOWN10 > : UNKNOWN11 ( < UNKNOWN12 > : Ident "f1" ) < UNKNOWN13 > : Variable_CommaList { : UNKNOWN14 ( < UNKNOWN15 > : Ident "A" ) , : UNKNOWN16 ( < UNKNOWN17 > : Ident "B" ) } ) ) , : UNKNOWN18 ( < UNKNOWN19 > : UNKNOWN20 ( < UNKNOWN21 > : Ident "B" ) < UNKNOWN22 > : UNKNOWN23 ( < UNKNOWN24 > : UNKNOWN25 ( < UNKNOWN26 > : Ident "f2" ) < UNKNOWN27 > : UNKNOWN28 { : UNKNOWN29 ( < UNKNOWN30 > : Ident "C" ) , : UNKNOWN31 ( < UNKNOWN32 > : Ident "A" ) } ) ) , : UNKNOWN33 ( < UNKNOWN34 > : UNKNOWN35 ( < UNKNOWN36 > : Ident "C" ) < UNKNOWN37 > : UNKNOWN38 ( < UNKNOWN39 > : Integer "3" ) ) , : UNKNOWN40 ( < UNKNOWN41 > : UNKNOWN42 ( < UNKNOWN43 > : UNKNOWN44 "D" ) < UNKNOWN45 > : UNKNOWN46 ( < UNKNOWN47 > : UNKNOWN48 ( < UNKNOWN49 > : UNKNOWN50 "f" ) < UNKNOWN51 > : UNKNOWN52 { : UNKNOWN53 ( < UNKNOWN54 > : UNKNOWN55 "UNKNOWN56" ) , : UNKNOWN57 ( < UNKNOWN58 > : UNKNOWN59 "UNKNOWN60" ) , : UNKNOWN61 ( < UNKNOWN62 > : UNKNOWN63 "UNKNOWN64" ) } ) ) } )