Question
This program is called Bug Hunter. It searches for the Stringbug inside of other Strings. Unfortunately, Bug Hunter has several compile time errors, so itwont
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");
}
}
}
Step by Step Solution
3.34 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
Answer Question 1 The program Bug Hunter has several compile time errors The errors are l...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started