Part One

Summary: Implement a program for finding the minimum, average, and maximum values of the columns of a 2D array. An Eclipse project template can be downloaded from the D2L assignment page.

Step 1: Change the project name to Lab8-yourname, substituting yourname with your name.

Step 2: Add appropriate comments before the main method, the processArray method, and the methods created in the following step.

Step 3: Add code to the main method and processArray method. Implement methods for finding the minimum, average, and maximum values of a 2D array, calling these methods from the processArray method. The rest of the Part One description describes what you need to code.

The main method calls the processArray method on three arrays. The assignments to the first and third arrays are already coded. You need to create the second array as a 13x7 array. Use a double loop to fill the array with values from -4.5 to 4.5 in 0.1 increments. The first column should contain the values -4.5, -4.4, and so on to -3.3 (plus or minus floating point roundoff). The second column should start with -3.2, etc. Note that the minimum, average, and maximum of the first column are -4.5, -3.9, and -3.3.

The processArray method should print out the correct numbers of rows and columns. In the loop, instead of assigning 0 to min, avg, and max, there should be three method calls that respectively return the minimum of the column, the average of the column, and the maximum of the column. Only the processArray method should have print statements.

Part Two

Answer the following questions and save your answers in a text file (.txt extension) in your Eclipse project. You can start editing a text file in Eclipse using:

File > New > Untitled Text File

Then do File > Save to start a dialog to save the file in your project.

1. Consider the array {-13, -11, -7, -5, -3, -2, 2, 3, 5, 7, 11, 13}. Trace the values of lo, hi, and mid if the binarySearch method is called with this array to search for the key -3. Your answer should have columns for the three variables.

2. Consider the array {2, -3, 5, -7, 11, -13, 17, -19, 23, -29}. Trace the values of this array if the selectionSort method is called with this array. Your answer should show the values of the array after each exchange of values in the array.

3. Consider the Sudoku puzzle. Write a static method sameBox(row1, col1, row2, col2) that returns true if the row1,col1 square is in the same 3x3 box as the row2,col2 square. This method should return false if either square is not a valid square. Assume that the rows and columns range from 0 to 8.

4. Write a static method hasNegativeValue(table) that returns true if the 2D array table contains a negative value. Assume table is a 2D double array.

5. Consider the TV class in Chapter 9 (Listing 9.3 in Section 9.3, also shown on the next page). Add a comment to the end of each line in the code below that describes the current values of the fields of the objects. Note: there are six columns for the fields of the two objects. Show the value in the column when a field is initialized or changes value.

// tv1 fields tv2 fields
// chan. vol. on chan. vol. on
TV tv1 = new TV();
TV tv2 = new TV();
tv1.setChannel(13);
tv1.setVolume(4);
tv2.turnOn();
tv2.setChannel(13);
tv2.setVolume(5);
tv1.turnOn();
tv1.channelUp();
tv1.volumeUp();
tv2.turnOff();
tv2.channelDown();
tv2.volumeDown();

public class TV {
int channel = 1; // Default channel is 1
int volumeLevel = 1; // Default volume level is 1
boolean on = false; // By default TV is off
public TV() {
}
public void turnOn() {
on = true;
}
public void turnOff() {
on = false;
}
public void setChannel(int newChannel) {
if (on && newChannel >= 1 && newChannel <= 120)
channel = newChannel;
}
public void setVolume(int newVolumeLevel) {
if (on && newVolumeLevel >= 1 && newVolumeLevel <= 7)
volumeLevel = newVolumeLevel;
}
public void channelUp() {
if (on && channel < 120)
channel++;
}
public void channelDown() {
if (on && channel > 1)
channel--;
}
public void volumeUp() {
if (on && volumeLevel < 7)
volumeLevel++;
}
public void volumeDown() {
if (on && volumeLevel > 1)
volumeLevel--;
}
}
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.