This program is called Bug Hunter. It searches for the Stringbug inside of other Strings. Unfortunately, Bug
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 itwon’t run.
Your job is to find all the compile time errors in the BugHunter program and fix them so that the program runs!
When the program is successfully debugged, it should output:
Debug has a bug at index 2bugs bunny has a bug at index 0boogie has no bugsbaby 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 theString 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");
}
}
}
Business Communication Essentials a skill based approach
ISBN: 978-0132971324
6th edition
Authors: Courtland L. Bovee, John V. Thill