Dear Experts Pls correct this program in order to get output
Dear Experts,
Pls correct this program in order to get output. Thanks.
package bignotation;
import java.util.*;
/**
*
* @author thana
*/
public class Bignotation {
private int[] theArray;
private int arraySize;
private int itemsInArray = 0;
static long startTime;
static long endTime;
public static void main(String[] args) {
// TODO code application logic here public void bubbleSort() {
startTime = System.currentTimeMillis();
for (int i = arraySize - 1; i > 1; i--) {
for (int j = 0; j < i; j++) {
if (theArray[j] > theArray[j + 1]) {
swapValues(j, j + 1);
}
}
}
endTime = System.currentTimeMillis();
System.out.println(\"Bubble Sort Took \" + (endTime - startTime));
}
Bignotation(int size) {
arraySize = size;
theArray = new int[size];
}
public void generateRandomArray() {
for (int i = 0; i < arraySize; i++) {
theArray[i] = (int) (Math.random() * 1000) + 10;
}
itemsInArray = arraySize - 1;
}
public void swapValues(int indexOne, int indexTwo) {
int temp = theArray[indexOne];
theArray[indexOne] = theArray[indexTwo];
theArray[indexTwo] = temp;
}
}
Solution
package BigNotation ;
import java.util.*;
/**
*
* @author thana
*/
public class BigNotation {
//private variables are used with in the class
private int[] theArray;
private int arraySize;
private int itemsInArray = 0;
static long startTime;
static long endTime;
public static void main(String[] args) {
startTime = System.currentTimeMillis();
//creating object of class with parameterised constructor
BigNotation b=new BigNotation(10);
//calling method generateRandomArray for generating array
b.generateRandomArray();
b. bubbleSort() ;
endTime = System.currentTimeMillis();
System.out.println(\"Bubble Sort Took \" + (endTime - startTime));
}//main
BigNotation (int size) {
arraySize = size;
theArray = new int[size];
}
public void generateRandomArray() {
for (int i = 0; i < arraySize; i++) {
theArray[i] = (int) (Math.random() * 1000) + 10;
}
itemsInArray = arraySize - 1;
}
/* public void swapValues(int indexOne, int indexTwo) {
int temp = theArray[indexOne];
theArray[indexOne] = theArray[indexTwo];
theArray[indexTwo] = temp;
}*/
public void bubbleSort()
{
for (int i = arraySize - 1; i > 1; i--)
{
for (int j = 0; j < i; j++)
{
if (theArray[j] > theArray[j + 1])
{ int temp = theArray[j];
theArray[j] = theArray[j + 1];
theArray[j + 1] = temp;
}
// b.swapValues(j, j + 1);
}
}//for
}//method
}//class


