Question: CAN YOU WRITE A DRIVER JAVA CODE FOR PART 5. I WILL PROVIDE THE JAVA CODES FOR PART 1 - 4 AND THE INTERFACES. TESTTIMES

CAN YOU WRITE A DRIVER JAVA CODE FOR PART 5. I WILL PROVIDE THE JAVA CODES FOR PART 1 - 4 AND THE INTERFACES.

CAN YOU WRITE A DRIVER JAVA CODE FOR PART 5. I WILL

TESTTIMES INTERFACE:

PROVIDE THE JAVA CODES FOR PART 1 - 4 AND THE INTERFACES.

TESTIMES 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;

}

}

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SORTINTERFACE:

TESTTIMES INTERFACE: TESTIMES JAVA CODE: public class TestTimes implements TestTimesInterface { privateBUBBLESORT JAVA CODE:

public class BubbleSort extends TestTimes implements SortInterface {

public void sort(int[] arrayToSort) {

int n = arrayToSort.length;

int temp = 0;

long startTime = System.currentTimeMillis(); // This variable will record the starting time

// Bubble Sort

for (int i = 0; i

for (int j = 1; j

if (arrayToSort[j - 1] > arrayToSort[j]) {

temp = arrayToSort[j - 1];

arrayToSort[j - 1] = arrayToSort[j];

arrayToSort[j] = temp;

}

}

}

long stopTime = System.currentTimeMillis(); // This variable will record the ending time

long elapsedTime = stopTime - startTime; // Total Time taken for the Sorting Algorithm

addTestTime(elapsedTime);

}

@Override

public void sort(Integer[] arrayToSort) {

// TODO Auto-generated method stub

}

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

INSERTION JAVA CODE:

public class InsertionSort extends TestTimes implements SortInterface{

public void sort(int[] arrayToSort) {

int n = arrayToSort.length;

long startTime = System.currentTimeMillis(); //This variable will record the starting time

//Insertion Sort

for (int j=1;j

int key = arrayToSort[j];

int i = j-1;

while ((i>-1) && (arrayToSort[i]>key)){

arrayToSort[i+1] = arrayToSort[i];

i--;

}

arrayToSort[i+1] = key;

}

long stopTime = System.currentTimeMillis(); //This variable will record the ending time

long elapsedTime = stopTime-startTime; //Total Time taken for the Sorting Algorithm

addTestTime(elapsedTime);

}

@Override

public void sort(Integer[] arrayToSort) {

// TODO Auto-generated method stub

}

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

SELECTIONSORT JAVA CODE:

public class SelectionSort extends TestTimes implements SortInterface{

public void sort(int[] arrayToSort) {

int n = arrayToSort.length;

long startTime = System.currentTimeMillis(); //This variable will record the starting time

// Selection Sort

for (int i=0;i

int index = i;

for (int j=i+1;j

if (arrayToSort[j]

index = j;

}

int small = arrayToSort[index];

arrayToSort[index] = arrayToSort[i];

arrayToSort[i] = small;

}

long stopTime = System.currentTimeMillis(); //This variable will record the ending time

long elapsedTime = stopTime-startTime; //Total Time taken for the Sorting Algorithm

addTestTime(elapsedTime);

}

@Override

public void sort(Integer[] arrayToSort) {

// TODO Auto-generated method stub

}

}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

DRIVER INTERFACE:

long[] testTimes = new long[10]; private int index = -1; @Override publiclong getLastTestTime() { if (index != -1) { return this.testTimes[index]; } elsePLEASE WRITE A JAVA CODE FOR DRIVER CLASS!!!!!!!!!!!!!!!!!!!

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 TestTimesInterface All known Implementing Classes: BinarySearch, LinearSearch, TestTimes public interface TestTimes Interface This interface will be used to organize and manage test times that are measured for specific operations. The user will utilze System.nanoTime) to measure the time it takes to complete an operation. Before the operation is started, you can obtain the start time: startTime = System.nanoTime(). After the operation is completed, you can obtain the end time: endtime = System.nanoTime(). Test Time is then: testTime = endTime - startTime. Author: Sameh A. Fakhouri Method Summary All Methods Instance Methods Abstract Methods Modifier and Type void Method and Description addTestTime(long testTime) This method is used to add a test time. double getAverageTestTime() This method is used to obtain the average test time. long getLast TestTime() This method is used to retrieve the last test time. long get TestTimes() This method returns an array of long values representing the last 10 test times. resetTestTimes() This method is used to reset all 10 linear search times to zero. void 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!