Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Answe #2 please. the test time java code is down below //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public class TestTimes implements TestTimesInterface { private long[] testTimes = new long[10]; private
Answe #2 please. the test time java code is down below
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
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 Details 1. TestTimes Class You will copy the TestTimes class that you created in Homework. I 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 Sott 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 addrestTime() method. 3. Selection Sort Chaus You will write the selectionsort.java class which will inherit from TestTimes.java and implement the Sort Interface using the Selection Sott 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 addrestTime() 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 Sinterface.ava Please note that your sort method must measure the run time and add it to the TestTimes class by using the addrestTime() 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 textTimel testime2 testTime text Timed test Times test test time text time text Time test Pine! --- Average teatTime Interface SortInterface All Known Implementing Classes: BubbleSort, Insertionsort, 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 Method and Description void 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 static class static class Interface and Description Driver Interface. ArrayType This enum is used to specify the type of Array Driver Interface.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 Method and Description 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. 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. Method Detail create Array java.lang. Integer[] createArray (Driver Interface. ArrayType arrayType, 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. Interface Sortinterface All Known Implementing Classes: BubbleSort, Insertionsort, 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. Selection Sort Author: Sameh A. Fakhouri Method Summary All Methods Instance Methods Abstract Methods Modifier and Type Method and Description void sort(java.lang. Integer 1 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
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 question 2,3,4,5,6
driver interface:
Sort interface:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started