All homeworks are due before class on the due date. All homework assignments must reflect your own understanding of the topic and be communicated in your own words. You may use one of the collaborative options. You may also request help and advice from your classmates on Piazza. Any help not allowed by that policy will be an honor violation.
Purpose: To encourage students to start working on the homework assignments early and recognize students who are actively engaged in the content
You will receiveNote: The final submission timestamp shown on Gradescope will be used.
Consider the following BNF grammar
START ::= EXPRESSION
EXPRESSION ::= CONSTANT | VARIABLE | "(if " EXPRESSION EXPRESSION EXPRESSION ")" | DEFINE
CONSTANT ::= BOOLEAN | NUMBER
VARIABLE ::= IDENTIFIER
DEFINE ::= "(def" VARIABLE EXPRESSION ")"
IDENTIFIER ::= LETTER+
LETTER ::= "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" |
"n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
NUMBER ::= DIGIT+
DIGIT ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
BOOLEAN ::= "true" | "false"
A string is legal if it is in the language defined by the grammar.
A string is illegal if it is not in the language defined by the grammar.
(def ab false) legal? Yes or No?Consider the following methods and answer the questions
// Returns sum of all even integers in the given array.
// If there is no even integer inside the given array, return 0.
Line 1: public static int getSumEven(ArrayList<Integer> arr)
Line 2: {
Line 3: int result = 0;
Line 4: for (int i=0; i<=arr.size()-1; i++) // original
Line 4': for (int i=0; i<arr.size()-1; i++) // mutant 1
Line 5: {
Line 6: int current = arr.get(i);
Line 7: if (current % 2 == 0)
Line 8: {
Line 9: result = result + current;
Line 10: }
Line 11: }
Line 12: return result;
Line 13: }
// Returns sum of all even integers in the given array.
// If there is no even integer inside the given array, return 0.
Line 1: public static int getSumEven(ArrayList<Integer> arr)
Line 2: {
Line 3: int result = 0;
Line 4: for (int i=0; i<=arr.size()-1; i++)
Line 5: {
Line 6: int current = arr.get(i); // original
Line 6': int current = arr.get(0); // mutant 2
Line 7: if (current % 2 == 0)
Line 8: {
Line 9: result = result + current;
Line 10: }
Line 11: }
Line 12: return result;
Line 13: }
// Returns sum of all even integers in the given array.
// If there is no even integer inside the given array, return 0.
Line 1: public static int getSumEven(ArrayList<Integer> arr)
Line 2: {
Line 3: int result = 0;
Line 4: for (int i=0; i<=arr.size()-1; i++)
Line 5: {
Line 6: int current = arr.get(i);
Line 7: if (current % 2 == 0)
Line 8: {
Line 9: result = result + current; // original
Line 9': result = result - current; // mutant 3
Line 10: }
Line 11: }
Line 12: return result;
Line 13: }
Consider the following Java method with the mutated statement:
// Determine if the difference between sums of 2 integer arrays is big enough.
// Return true if the difference is greater than 14 (i.e., big enough)
// Return false, otherwise.
Line 1: static Boolean bigDiff( ArrayList<Integer> arr1, ArrayList<Integer> arr2)
Line 2: {
Line 3: if (arr1 == null || arr2 == null)
Line 4: throw new NullPointerException("arr1 and/or arr2 is null");
Line 5: if (arr1.contains(null) || arr2.contains(null))
Line 6: throw new NullPointerException("array contains null element");
Line 7:
Line 8: int sum1 = 0;
Line 9: for (int i=0; i<arr1.size(); i++)
Line 10: sum1 = sum1 + arr1.get(i);
Line 11:
Line 12: int sum2 = 0;
Line 13: for (int i=0; i<arr2.size(); i++)
Line 14: {
Line 15: // sum2 = sum2 + arr2.get(i); // original
Line 15': sum2 = sum2 + arr2.get(0); // mutant
Line 16: }
Line 17:
Line 18: int result = Math.abs(sum1 - sum2); // abs() return absolute value
Line 19: if (result > 14)
Line 20: return true;
Line 21:
Line 22: return false;
Line 23: }
bigDiff(_______________________, _______________________) If a test cannot be created, explain why.
bigDiff(_______________________, _______________________) Expected output (original): ___________________________ Expected output (mutant): _____________________________ If a test cannot be created, explain why.
[Total: 20 points] Complete the tasks. Provide correct and clear solutions. Properly document your solutions.
( -5 points) for 24 hours late (submitted after 15-April 11am EST, by 16-April 11am EST)
(-10 points) for 48 hours late (submitted after 16-April 11am EST, by 17-April 11am EST)
(-2 points) for submitting a Word document or handwriting, or a write-up that is not a typed PDF file.
Save your write-up as a PDF file (only typed PDF is accepted) — No handwriting. No hand-drawing. No Word document.
Each team submits only one copy.
Upload your report as a PDF to Assignment 6 on Gradescope. Make sure you connect your partner to your group on Gradescope so that everyone receives credit.
Making your submission available to instructor and course staff is your responsibility; if we cannot access or open your file, you will not get credit. Be sure to test access to your file before the due date.
CC-BY-NC-SA 4.0 license.