Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Ex . 1 . Debugging a Class In this lab, we will need to test and debug a program that searches in an array for

Ex.1. Debugging a Class
In this lab, we will need to test and debug a program that searches in an array for the first larger number that follows an element at a given index in the array.
a. Download the following source file:
LargestAfter.java
The program contains several syntax errors and a few conceptual errors. Create a project called lab5 and a package inside it called lab5. Add this class to the package.
b. Fix the compilation errors and run the program.
c. Test the program with multiple test cases, with some arrays that are in ascending or descending order, with the index close to the beginning or close to the end, with an index larger than the size of the array, with an empty array. Add some output statements to guide you while debugging the program. If necessary, run it through the debugger.
Add a comment at the end of the program with all the test cases you found, and which of them worked from the beginning, which of them worked after you fixed the program, and which of them still don't work.
d. In the function largerAfter, add an assertion in the body of the for loop at the top. Figure out a condition that should be true at that point in the program.
LargestAfter.java
public class LargestAfter {
// Finds the first larger number after the given index
boolean largerAfter(int[] a, int start)
{
int i, j;
int n = a.length;
for (i = start; a[i]<= a[start]; i++);
return i;
}
public static void main(String[] args){
int[] numbers ={1,4,3,2,5,7};
int index =1;
System.out.println("Largest after "+ numbers[index]
+": "+ largerAfter(numbers, index));
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago