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.
Line 1: public static String MultipleOccur(String str, Character key)
Line 2: {
Line 3: if (str == null || key == null)
Line 4: throw new IllegalArgumentException("can't pass in null"); // IAE
Line 5:
Line 6: int occurrences = 0;
Line 7: for (int i = 0; i < str.length(); i++)
Line 8: {
Line 9: var currChar = str.charAt(i);
Line 10:
Line 11: if (key.equals(currChar))
Line 12: occurrences += 1;
Line 13: }
Line 14:
Line 15: if (occurrences > 1)
Line 16: return "yes";
Line 17: else
Line 18: return "no";
Line 19: }
The given tests (t1 - t8):
t1: str = "occurrence", key = 'c' t2: str = "", key = 'c' t3: str = "occurrence", key = 'r' t4: str = "occurrence", key = 'z' t5: str = null, key = null t6: str = null, key = 'y' t7: str = "occurrence", key = null t8: str = "occurrence", key = 'n'
[optional] You may start by filling out the following table. The first row is filled for you. This table will not be graded but it may be helpful when you answer the questions below.
Due to the space limitation, let's label the following with letters
str == null – we will call it "a" (column a, below) key == null – we will call it "b" (column b, below) i < str.length() – we will call it "c" (column c, below) key.equals(currChar) – we will call it "d" (column d, below) occurrences > 1 – we will call it "e" (column e, below)
| test# | str | key | MultipleOccur(str,key) | a | b | c | d | e |
| t1 | "occurrence" | 'c' | "yes" | F | F | T | T | T |
| t2 | "" | 'c' | ||||||
| t3 | "occurrence" | 'r' | ||||||
| t4 | "occurrence" | 'z' | ||||||
| t5 | null | null | ||||||
| t6 | null | 'y' | ||||||
| t7 | "occurrence" | null | ||||||
| t8 | "occurrence" | 'n' |
You must use tests from the list of eight tests (t1, t2, …, t8) given above, for credit.
Show your analysis and thought process.
You must use tests from the list of eight tests (t1, t2, …, t8) given above, for credit.
Show your analysis and thought process.
Note that the Logic Coverage Web App on the book web site will let you check (most of) your work. However, you should be able to apply the concept on a given software artifact without the tool.
[Total: 20 points] Complete the tasks. Provide correct and clear solutions. Properly document your solutions.
( -5 points) for 24 hours late (submitted after 10-November 11am EST, by 11-November 11am EST)
(-10 points) for 48 hours late (submitted after 11-November 11am EST, by 12-November 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 5 on Gradescope. Make sure you connect your partner to your group on Gradescope so that everyone receives credit.
Make sure that you submit all file(s).
Verify that you submit the correct file(s).
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.