Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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... 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

Business Communication Essentials a skill based approach

Authors: Courtland L. Bovee, John V. Thill

6th edition

978-0132971324

More Books

Students also viewed these Programming questions

Question

For any S T, 1. int S int T 2.

Answered: 1 week ago

Question

a sin(2x) x Let f(x)=2x+1 In(be)

Answered: 1 week ago