CSC 455: Assignment 02 | Due date: See Blackboard Instructor: Dr. Razib Iqbal | www.razib.info

Q1: 5 points There is a faulty program/code snippet in the following textbox.

Answer the following questions: (1 point each) a) Identify the fault. b) Identify a test case that does NOT execute the fault. c) Identify a test case that executes the fault, but does not result in an error state. d) Identify a test case that results in an error, but not a failure. (Hint: Error results in

failure if not handled by the program) e) For the given test case in the textbox, identify the first error state during runtime.

Describe the complete state including the values of each of the variables, expected and actual results.

Q2: 10 points Download the A02_Codes.zip. Do not modify the attached java files (except package name). Create a driver to test the attached java files in Eclipse. Name and save the driver as: TestDriver.java.

a) (7 points) Add a main method and additional methods (as appropriate) in the driver to test the attached java files. Add comments to your code as necessary for me to understand it. Driver will read user inputs from console in the following format: Enter user ID: 3224400 Result: 3224400 is a local prepaid user. Do you want to continue? (y/n): n Bye.

b) (3 points) Answer the following questions based on Q2a:

i. Identify any debugging strategy you used. ii. Explain why did you use/choose that debugging strategy. iii. Which other debugging strategy could be used? And why?

Q3: 5 points a) After solving Q2a, run the driver for one sample input. What is the initial code

coverage for PolicyUser, LocalUser, and RoamingUser classes using EclEmma code coverage tool? Submit a screen capture. (1 point)

b) Add additional codes in the driver to increase code coverage for the attached java classes to ~100%. Save the driver as TestDriverM.java, and submit a screen capture showing the increased code coverage in EclEmma. (4 Points)

Q4: 10 points See the JAVA code on the next few pages. Use this code in a new JAVA project (name the Project/File as FindBugsGroupNumber.java), and perform a static code analysis using the SpotBugs tool. a) Identify the reported bugs from the tool, and give an overview of these bugs. b) Identify the given solutions/fixes in the code, and explain the solutions. c) Use a table to answer a) and b)

Submit your assignment in Blackboard only: 1. Submit the java files (including your driver) from Q2a & Q3b, and the written

answers (along with related screen captures) in a MS Word document. a. Include your full name(s) on the first page b. Answer chronologically in an organized manner c. Name your “zip” file containing java files and MS Word file:

455_A02_FirstNameLastName

//Codes for Q4 import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.UnknownFormatConversionException; public class Findbugs1 { public static void main(final String[] args) { System.out.println(“Findbugs Sample 001 for BC_IMPOSSIBLE_CAST”); try { Findbugs1.bcImpossibleCastWRONG(); } catch (final ClassCastException e) { System.out.println(” – ERROR:” + e.getMessage()); } System.out.println(“Findbugs Sample 002 for BC_IMPOSSIBLE_DOWNCAST”); try { Findbugs1.bcImpossibleDowncastWRONG(); } catch (final ClassCastException e) { System.out.println(” – ERROR:” + e.getMessage()); } System.out.println(“Findbugs Sample 003 for BC_IMPOSSIBLE_INSTANCEOF”); Findbugs1.bcImpossibleInstanceOfWRONG(); System.out.println(“Findbugs Sample 004 for BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY”); try { Findbugs1.bcImpossibleDowncastOfArrayWRONG(); } catch (final ClassCastException e) { System.out.println(” – ERROR:” + e.getMessage()); } System.out.println(“Findbugs Sample 005 for DMI_BIGDECIMAL_CONSTRUCTED_FROM_DOUBLE”); Findbugs1.dmiBigDecimalConstructedFromDoubleWRONG(); System.out.println(“Findbugs Sample 006 for ES_COMPARING_STRINGS_WITH_EQ”); Findbugs1.esComparingStringsWithEqWRONG(); System.out.println(“Findbugs Sample 007 for VA_FORMAT_STRING_ILLEGAL”); try { Findbugs1.vaFormatStringIllegalWRONG(); } catch (final UnknownFormatConversionException e) { System.out.println(” – ERROR:” + e.getMessage()); } System.out.println(“Findbugs Sample 008 for RV_RETURN_VALUE_IGNORED”); Findbugs1.rvReturnValueIgnoredWRONG(); System.out.println(“Findbugs Sample 009 for NP_ALWAYS_NULL”); try { Findbugs1.npAlwaysNullWRONG(); } catch (final NullPointerException e) { System.out.println(” – ERROR:” + e.getMessage()); } System.out.println(“Findbugs Sample 010 for QBA_QUESTIONABLE_BOOLEAN_ASSIGNMENT”); Findbugs1.qabQuestionableBooleanAssignmentWRONG(); } private static void bcImpossibleCastWRONG() { final Object doubleValue = Double.valueOf(1.0); final Long value = (Long) doubleValue; System.out.println(” – ” + value); }

private static void bcImpossibleCastCORRECT() { final Object doubleValue = Double.valueOf(1.0); final Double value = (Double) doubleValue; System.out.println(” – ” + value); } private static void bcImpossibleDowncastWRONG() { final Object exception = new RuntimeException(“abc”); final SecurityException value = (SecurityException) exception; System.out.println(” – ” + value.getMessage()); } private static void bcImpossibleDowncastCORRECT() { final Object exception = new RuntimeException(“abc”); final RuntimeException value = (RuntimeException) exception; System.out.println(” – ” + value.getMessage()); } private static void bcImpossibleInstanceOfWRONG() { final Object value = Double.valueOf(1.0); System.out.println(” – ” + (value instanceof Long)); } private static void bcImpossibleInstanceOfCORRECT() { final Object value = Double.valueOf(1.0); System.out.println(” – ” + (value instanceof Double)); } private static void bcImpossibleDowncastOfArrayWRONG() { final Collection<String> stringVector = new ArrayList<String>(); stringVector.add(“abc”); stringVector.add(“xyz”); final String[] stringArray = (String[]) stringVector.toArray(); System.out.println(” – ” + stringArray.length); } private static void bcImpossibleDowncastOfArrayCORRECT() { final Collection<String> stringVector = new ArrayList<String>(); stringVector.add(“abc”); stringVector.add(“xyz”); final String[] stringArray = stringVector.toArray(new String[stringVector.size()]); System.out.println(” – ” + stringArray.length); } private static void dmiBigDecimalConstructedFromDoubleWRONG() { final BigDecimal bigDecimal = new BigDecimal(3.1); System.out.println(” – ” + bigDecimal.toString()); } private static void dmiBigDecimalConstructedFromDoubleCORRECT() { final BigDecimal bigDecimal = new BigDecimal(“3.1″); System.out.println(” – ” + bigDecimal.toString()); } private static void esComparingStringsWithEqWRONG() { final StringBuilder sb1 = new StringBuilder(“1234”); final StringBuilder sb2 = new StringBuilder(“1234″); final String string1 = sb1.toString(); final String string2 = sb2.toString(); System.out.println(” – ” + (string1 == string2)); } private static void esComparingStringsWithEqCORRECT() { final StringBuilder sb1 = new StringBuilder(“1234”); final StringBuilder sb2 = new StringBuilder(“1234”);

final String string1 = sb1.toString(); final String string2 = sb2.toString(); System.out.println(” – ” + string1.equals(string2)); } private static void vaFormatStringIllegalWRONG() { System.out.println(String.format(” – %>s %s”, “10”, “9”)); } private static void vaFormatStringIllegalCORRECT() { System.out.println(String.format(” – %s > %s”, “10”, “9”)); } private static void rvReturnValueIgnoredWRONG() { final BigDecimal bigDecimal = BigDecimal.ONE; bigDecimal.add(BigDecimal.ONE); System.out.println(String.format(” – ” + bigDecimal)); } private static void rvReturnValueIgnoredCORRECT() { final BigDecimal bigDecimal = BigDecimal.ONE; final BigDecimal newValue = bigDecimal.add(BigDecimal.ONE); System.out.println(String.format(” – ” + newValue)); } private static void npAlwaysNullWRONG() { final String value = null; if (null != value & value.length() > 2) { System.out.println(String.format(” – ” + value)); } else { System.out.println(String.format(” – value is invalid”)); } } private static void npAlwaysNullCORRECT() { final String value = null; if (null != value && value.length() > 2) { System.out.println(String.format(” – ” + value)); } else { System.out.println(String.format(” – value is invalid”)); } } private static void qabQuestionableBooleanAssignmentWRONG() { boolean value = false; if (value = true) { System.out.println(String.format(” – value is true”)); } else { System.out.println(String.format(” – value is false”)); } } private static void qabQuestionableBooleanAssignmentCORRECT() { final boolean value = false; if (value == true) { System.out.println(String.format(” – value is true”)); } else { System.out.println(String.format(” – value is false”)); } } }

Found something interesting ?

• On-time delivery guarantee
• PhD-level professional writers
• Free Plagiarism Report

• 100% money-back guarantee
• Absolute Privacy & Confidentiality
• High Quality custom-written papers

Grab your Discount!

25% Coupon Code: SAVE25
get 25% !!