Question: This program is called Bug Hunter. It searches for the String bug inside of other Strings. Unfortunately, Bug Hunter has several compile time errors, so
This program is called Bug Hunter. It searches for the String bug inside of other Strings.
Unfortunately, Bug Hunter has several compile time errors, so it wont run.
Your job is to find all the compile time errors in the Bug Hunter program and fix them so that the program runs!
When the program is successfully debugged, it should output:
Debug has a bug at index 2 bugs bunny has a bug at index 0 boogie has no bugs baby buggie has a bug at index 5
public class BugHunter extends ConsoleProgram { public void run() { String test1 = "Debug"; String test2 = "bugs bunny"; String test3 = "boogie"; String test4 = 'baby buggie'; int index1 = findBug(test1); int index2 = findBug(test2); int index3 = findBug(test3); int index4 = findBug(test4); printBug(test1, index1); printBug(test2, index2) printBug(index3, test3); printBug(test4, index4); } // Returns the index of the String "bug" inside the String str // If str does not contain the String "bug", returns -1 public String findBug(String str) { return str.indexOf("bugs") } public void printBug(String test, int index) { if(index != -1) { System.out.println(test + " has a bug at index " + index); } else { System.out.println(test + " has no bugs"); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
