Question: ANSWER QUESTIONS 2,3,4,5,6 IN JAVA PROGRAMMING. TESTTIMES JAVA CODE INCLUDED DOWN BELOW. INTERFACES ARE ALSO INCLUDED TESTTIMES JAVA CODE: public class TestTimes implements TestTimesInterface {

ANSWER QUESTIONS 2,3,4,5,6 IN JAVA PROGRAMMING. TESTTIMES JAVA CODE INCLUDED DOWN BELOW. INTERFACES ARE ALSO INCLUDED

TESTTIMES JAVA CODE:

public class TestTimes implements TestTimesInterface {

private long[] testTimes = new long[10];

private int index = -1;

@Override

public long getLastTestTime() {

if (index != -1) {

return this.testTimes[index];

} else {

return -1;

}

}

@Override

public long[] getTestTimes() {

long[] array = new long[10];

for ( int i = 0 ; i

array[i] = this.testTimes[i];

}

return array;

}

@Override

public void resetTestTimes() {

for ( int i = 0 ; i

this.testTimes[i] = 0;

}

this.index = -1;

}

@Override

public void addTestTime(long testTime) {

if (index == 9) {

for ( int i = 0 ; i

this.testTimes[i] = this.testTimes[i+1];

}

testTimes[9] = testTime;

} else {

testTimes[++index] = testTime;

}

}

@Override

public double getAverageTestTime() {

if (this.index != -1) {

double total = 0;

for ( int i = 0 ; i

total += this.testTimes[i];

}

double average = total/(this.index + 1);

return average;

} else {

return 0.0;

}

}

}

ANSWER QUESTIONS 2,3,4,5,6 IN JAVA PROGRAMMING. TESTTIMES JAVA CODE INCLUDED DOWN BELOW.

INTERFACES ARE ALSO INCLUDED TESTTIMES JAVA CODE: public class TestTimes implements TestTimesInterface{ private long[] testTimes = new long[10]; private int index = -1;@Override public long getLastTestTime() { if (index != -1) { return this.testTimes[index];

1. Test Times Class You will copy the TestTimes class that you created in Homework 1 to the project you are using for this assignment. 2. BubbleSort Class You will write the BubbleSort.java class which will inherit from TestTimes.java and implement the Sort Interface using the Bubble Sort algorithm. The interface may be downloaded from SortInterface.java Please note that your sort method must measure the run time and add it to the TestTimes class by using the addTestTime() method. 3. SelectionSort Class You will write the SelectionSort.java class which will inherit from TestTimes.java and implement the Sort Interface using the Selection Sort algorithm. The interface may be downloaded from SortInterface.java Please note that your sort method must measure the run time and add it to the TestTimes class by using the addTestTime() method. 4. Insertion Sort Class You will write the InsertionSort.java class which will inherit from TestTimes.java and implement the Sort Interface using the Insertion Sort algorithm. The interface may be downloaded from SortInterface.java Please note that your sort method must measure the run time and add it to the TestTimes class by using the addTestTime() method. 5. Driver Class You will write the Driver.java class which will implement the Driver Interface. The interface may be downloaded from DriverInterface.java 6. Output From Driver Main Method Please note that, in addition to implementing the Driver Interface, you are also required to write your own public static main(String[] args) method in Driver.java. Your main() method will have to call the runsort() method to sort each of the following array types ten times for each sort algorithm: 1. 1,000 equal Integers. 2. 1,000 random Integers. 3. 1,000 increasing Integers. 4.1,000 decreasing Integers. 5.1,000 increasing and random Integers. 6.10,000 equal Integers. 7. 10,000 random Integers. 8. 10,000 increasing Integers. 9. 10.000 decreasing Integers. 10. 10,000 increasing and random Integers. For each call to the runSort() method to sort an ArrayType using a SortType ten times, your main() method will produce the following output: SortType, ArrayType, Array Size testTimel testTime2 testTime3 testTime4 testTime 5 testTime6 testTime 7 testTime8 testTime 9 testTime10 --- Average testTime Interface SortInterface All Known Implementing Classes: BubbleSort, Insertion Sort, SelectionSort public interface SortInterface This interface will be used by various classes to sort an array Integer objects. You will write three classes that implement this interface: 1. BubbleSort 2. InsertionSort 3. SelectionSort Author: Sameh A. Fakhouri Method Summary All Methods Instance Methods Abstract Methods Modifier and Type void Method and Description sort(java.lang. Integer[] arrayToSort) This method is called to sort the given array of Integer objects. Method Detail sort void sort (java.lang. Integer[] arrayToSort) This method is called to sort the given array of Integer objects. At the completion of this method, the array will be sorted. Parameters: arrayToSort - This is the array that contains all the Integer objects that need to be sorted. Interface Driverinterface All Known Implementing Classes: Driver public interface Driver Interface Author: Sameh A. Fakhouri Nested Class Summary Nested Classes Modifier and Type Interface and Description static class static class Driver Interface. ArrayType This enum is used to specify the type of Array. DriverInterface. SortType This enum is used to specify the desired sort algorithm: BubbleSort - Indicates the Bubble Sort algorithm. SelectionSort - Indicates the Selection Sort algorithm. InsertionSort - Indicates the Insertion Sort algorithm. Method Summary All Methods Instance Methods Abstract Methods Modifier and Type java.lang. Integer[] Method and Description createArray (Driver Interface. ArrayType arrayType, int arraysize) This method is used to create a new array of Integer objects of the type and size specified. runsort (Driver Interface. SortType sortType, Driver Interface. ArrayType arrayType, int arraysize, int numberOfTimes) This method will run the specified sort type a specified number of times. TestTimes Method Detail createArray java.lang. Integer[] createArray(Driver Interface. ArrayType arrayType, int arraysize) This method is used to create a new array of Integer objects of the type and size specified. Parameters: arrayType - This parameter specifies the type of array to create. See the enum Driver Interface. ArrayType. arraysize - This parameter specifies the size of array to create. Returns: The method will return the array of Integer objects that was created. run Sort TestTimes runSort (Driver Interface. SortType sortType, Driver Interface. ArrayType arrayType, int arraysize, int numberofTimes) This method will run the specified sort type a specified number of times. Each time the sort run the method will obtain a new array to sort. The array will be of the specified type and size. Parameters: sortType - This parameter specifies the sort algorithm that will be used. See Driver Interface. SortType. arrayType - This parameter specifies the type of array to create each time the sort is run. See the enum Driver Interface. ArrayType. arraysize - This parameter specifies the size of array to create each time the sort is run. numberOfTimes - This parameter specifies the number of times to run the specified sort. Returns: The method must return the TestTimes class that was used to save the measured test times for the sort performed

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!