Midterm Lab Exam Practice

This is a an ungraded practice exam for the midterm. In the practice environment, you are given 45 minutes to answer these questions. In a real exam environment, you will have the entire class, though there will be more questions.

You might not have enough time to complete all the questions. If you have to prioritize your time, it is better to get one problem working than it is to attempt two problems and have them both broken. With that in mind, it is recommended to read all the problems first, determine which are easiest to solve, and then solve them.

Unlike the normal assignment environment, you may NOT discuss with anyone else, and you may NOT access the Internet, your old labs, or any other materials. The point of this practice exam is to simulate a real exam environment.

Provided files:

Problem 1: IndexInRange.java

Download IndexInRange.java. In this file, you must write a method which will take an array of integers, along with an index into that array. The method should return true if the index is in the bounds of the array (i.e., it's a valid index for the given array), else false.

You may write your own main method in the file to test this, along with writing your own tests in the provided IndexInRangeTest.java file. You do not need to write your own tests, but you're welcome to do so if they'd help your development process.

Problem 2: SumSubsetArray.java

Download SumSubsetArray.java. In this file, you must write a method which takes the following:

Given the above information, the method will return the sum of the elements of the array between the given indicies, including the values at the indicies themselves. For example, consider the following array:

Value 5 27 14 -2 12 1
Index 0 1 2 3 4 5

Given the above array along with the input indecies of 1 and 4, the method you write should return 51 (27 + 14 + (-2) + 12). You may assume that the given indicies will always be in the bounds of the given array.

You may write your own main method in the file to test this, along with writing your own tests in the provided SumSubsetArrayTest.java file. You do not need to write your own tests, but you're welcome to do so if they'd help your development process.

Problem 3: ArgsGreaterThan5.java

Download ArgsGreaterThan5.java. In this file, you must write all your code in the main method. This code will print out all the command-line arguments a program has been given which are greater than 5, one per line. For example, if given the following command-line arguments:

12 5 2 -1 0 15

...then your code should print:

12
15

If no command-line arguments are given, then your code should not print anything.

When Done

If you complete all the above problems before the time is up, go ahead and begin the written portion of the practice exam.