The following code compiles, but produces unexpected results


1) Write a reversed string replacement method (public String ecalpeResrever(...) ) that takes three String arguments, 'haystack,' 'needle,' and 'replacement'.

The method will perform a left-to-right string replacement, followed by reversing the resultant strings *words*. ie. ("I like cats", "cat", "dog") ◊ "dogs like I"

The method must compile and run under JDK 1.5. The method will be tested for speed and correctness on haystacks up to one megabyte. There is a fast linear solution to this problem. Be aware of edge cases. Please leave all testing code intact so that we may evaluate your testing procedure. If you wish to use JUnit, you can create a separate class with 'Test' appended to the end of your primary class' name, and extending TestCase.


Example Test Cases (you should come up with more edge cases): ecalpeResrever("ABC", "A", "a").equals("aBC"); ecalpeResrever("AAA AAB BAA", "AA", "a").equals("Ba aB aA"); ecalpeResrever("I Work.", "Work", "Play").equals("Play. I");

ecalpeResrever("Tests are the best!","the best!","just ok.").equals("ok. just are Tests");

2) The following code compiles, but produces unexpected results (sub-optimal) even under single-threaded conditions (hint: this is not a threading question). Please debug using any tools or techniques you have at your disposal to isolate the problem. 

The solution should simply be named 'solution.txt' and contain your analysis of the problem. You do not have to write code to fix the problem. 

import java.util.*; 

public class Stack {

private Object[] elements; private int size = 0;

public Stack(int initialCapacity) { this.elements = new Object[initialCapacity];

}

public void push(Object e) { ensureCapacity(); elements[size++] = e;

}

public Object pop() { if (size==0)

throw new EmptyStackException(); Object pop = elements[--size]; return pop;

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: The following code compiles, but produces unexpected results
Reference No:- TGS080606

Expected delivery within 24 Hours