I am creating an employee record with some fields (name, email, phone and salary) in ArrayList
that are written to txt.
After the data is entered into the array (before moving to txt) they need to be sorted by name, which is the first field from left to right.
And here's the problem, because I can not use any sort order sort method. I have to create a quicksort.
I have tried in many ways and I have not been able to. I thought about trying with the string compare, but I do not know how it could do to sort alphabetically.
Will it work? Can someone give me a light?
Main class:
public static void main(String[] args) throws IOException
{
ArrayList<Funcionario> funcionarios = new ArrayList<Funcionario>();
... menu do programa..
case 1:
Funcionario func = new Funcionario();
func.cadastrar();
funcionarios.add(func);
System.in.read();
System.out.println("\n\nFuncionario cadastrado: " + func.toString());
break;
Class registration
public void cadastrar()
{
System.out.println("\n\n\n\n\n\n\n\n\n----- Cadastro de funcionário -----");
System.out.print("\nInforme o nome: ");
String nome = ler.nextLine();
this.setNome(nome);
System.out.print("\nInforme o e-mail: ");
String email = ler.nextLine();
this.setEmail(email);
boolean valida;
do
{
System.out.print("\nInforme o telefone: ");
String telefone = ler.nextLine();
if(telefone.length() != 10)
{
System.out.println("Erro!!\nO formato exige 10 dígitos\n");
valida = false;
}
else
{
valida = true;
this.setTelefone(telefone);
}
}while(!valida);
do
{
System.out.print("\nInforme o salário: R$ ");
float salario = ler.nextFloat();
if(salario <= 0)
{
System.out.println("ERRO!! Valor inválido");
valida = false;
}
else
{
valida = true;
this.setSalario(salario);
}
}while(!valida);
PrintWriter gravarTxt = new PrintWriter(arquivo);
gravarTxt.printf("\r\n"+this.nome+" "+this.email+" "+this.telefone+" R$ "+this.salario);
gravarTxt.flush();
}