Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Below are faulty programs. Each have test inputs that result in failure. Answer the following questions about each program. Find last index of element

Below are faulty programs. Each have test inputs that result in failure. Answer the following questions about each program. image text in transcribed
image text in transcribed
Find last index of element " Find last index of zero @param x aray to search @param x array to search @param y value to look for @return last index of y in x -1 if abaent @return last index of 0 in x; -1 if absent @throws NullPointerException if x is null @throws NullPointerException if x is null public int findLast (int] x, nt y) publie static int lastZero (int] x) for (int i-x.length-1:i>0 - for (int 1-0; 1length: i++) if (xl-y) if (xli]-0) return i return i; retum-1; retum -1: // test: x -[2, 3, 5:y-2: Expected // Book website: FindLast java // Book website: FindLastTest.java /test: x-[0, 1, 0]:Expected 2 //Book webaite: LastZero java //Book webaite: LastZeroTest.java Count posi tive elements Count odd or positive elements @param x array to search @param x aray to search @retum count of odd/positive values in x @return count of positive elements in x @throws NullPointer Exception if x is null @throws NullPointerException if x is null public int count Positive (int] x) public static int oddorPos int] x) int count -0 for (int i-0; 1 0) count++ count++ retum count retum count // test: x -[-4, 2, 0, 2]: Expected-2 // Book website: CountPositive java // test: x -[-3, -2, 0, 1, 4]: Expected 3 // Book webaite: Odd0iPos.java Book website: CountPosi tiveTest.java Book website: Odd0rPosTest (a) Explain what is wrong with the given code. Describe the fault (b) If possible, give a test case that does not execute the fault. If (c) If possible, give a test case that executes the fault, but does not (d) If possible give a test case that results in an error, but not a precisely by proposing a modification to the code. not, briefly explain why not. result in an error state. If not, briefly explain why not. failure. If not, briefly explain why not. Hint: Don't forget about the program counter

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions