S A M P L E Quiz #4 Name ___________________ Honor Code________________________ Section _____ (Note: Getting your Name and Section right is worth one point. If we can't decipher your name or section, it's wrong.) A. Assume you have the following Java code fragment (part of the action method) and it runs. What is the value of total when it completes? _____6____ (doing a trace should help you...) int k, total = 0, start = 4, stop = 1; ... k = start; while (k > stop) { k = k - 1; total = total + k; } ... Safest way to do (note that the trace below is NOT required, but it might keep you from making a silly error.) (1) int k, total = 0, start = 4, stop = 1; ... (2) k = start; (3) while (k > stop) { (4) k = k - 1; (5) total = total + k; } # k total T/F 1 ? 0 ? 2 4 3 T 4 3 5 3 3 T 4 2 5 5 3 T 4 1 5 6 3 F B. Here are some simple rules defining Java syntax. 1. -> //any string of alphanumeric symbols that begins with a letter// 2. -> = ; 3. -> = new (); 4. -> .() | () ; 5. -> //possibly empty list of s separated by commas// 6. -> | | 7. -> + 8. -> 9. -> " any sequence of characters " 10. -> 11. -> setText|getText|getInt|setInt|add|actionPerformed|init 12. -> { //list of s// } In the style shown in the lectures, show how these rules can be used to generate the following Java program fragment (thus verifying that it is syntactically correct). Identify the rule used at each stage. Continue on back (don't squeeze it all on this side). { memo = text + "water" ; next = "birth" + "day"; } Start with: #12 12 -> { } -> { 2 = ; 2 = ; } -> { 1 memo = ; 1 next = ; } -> { 6 memo = ; 6 next = ; -> { 7 memo = + ; 7 next = + ; -> { 8 memo = + ; 8 next = + ; -> { 10 memo = + ; 9 next = "birth" + ; -> { 1 memo = text + ; next = "birth" + ; -> { 8 memo = text + ; 8 next = "birth" + ; -> { 9 memo = + "water" ; 9 next = "birth" + "day" ; }