i am doing sorts in java and i have ran into an error. The error is stemming from my class file and then the tester i have in turn, wont work. Here is the class
import java.util.*;
public class CompanyDataBase
{
ArrayList<Employee> employee = new ArrayList<Employee>();
}
//Default Constructor
public CompanyDataBase()
{
}
//Methods
//Add Employee
public void addEmployee(Employee newGuy)
{
employee.add(newGuy);
}
//Get the employees
public ArrayList<Employee> getEmployees()
{
return employee;
}
//Sort by name
public ArrayList<Employee> sortByName()
{
Collections.sort(employee, new EmployeeNameComparator());
return employee;
}
//Sort by salary
public ArrayList<Employee> sortBySalary()
{
Collections.sort(employee, new EmployeeSalaryComparator());
return employee;
}
//Bubble Sort
public void bubblesortBySalary(int [] employee)
{
int temp = 0;
boolean arraySorted = false;
for (int i = 0; i < employee.length - 1 && !arraySorted;
i++ )
{
arraySorted = true; // start a new iteration;
// maybe the array is sorted
for ( int j = 0; j < employee.length - i - 1; j++ )
{
if ( employee[j] > employee[j + 1] )
{
// swap the adjacent elements
// and set arraySorted to false
temp = employee[j + 1];
employee[j + 1] = employee[j];
employee[j] = temp;
arraySorted = false;
}
}
}
}
}
Also here is the tester that i am using
public class BubbleSortTester
{
public static void main(String[] args)
{
CompanyDataBase myDb = new CompanyDataBase();
myDb.addEmployee(new Employee("James, John", 34, 45234));
myDb.addEmployee(new Employee("Conroy, Mike", 19, 19234));
myDb.addEmployee(new Employee("Gavigan, Luke", 28, 30234));
myDb.addEmployee(new Manager("Gates, Bill", 28, 44000, 2000));
myDb.bubblesortBySalary();
for(Employee currEmployee: myDb.getEmployees())
{
System.out.println(currEmployee.getDescription());
}
}
}
The problem i am having is that when i attempt to compile my tester it gives me the following error >>>>
BubbleSortTester.java:16: error: method bubblesortBySalary in class CompanyDataBase cannot be applied to given types;
myDb.bubblesortBySalary();
^
required: int[]
found: no arguments
reason: actual and formal argument lists differ in length
1 error
I then tried it in Eclipse instead of jGrasp and that advised me to enter null but when i enter null it returns this error >>> Exception in thread "main" java.lang.NullPointerException at CompanyDataBase.bubblesortBySalary(CompanyDataBase.java:46) at BubbleSortTester.main(BubbleSortTester.java:16)
Sorry for the amount of code but any help would be appreciated, Thanks in advance, Jason