Pro192 HW w3 SE17B04
Pro192 HW w3 SE17B04
Employee.java
package de170737.htdt;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public Employee() {
name = null;
age = 0;
address = null;
salary = 0;
salaryCoefficient = 0;
}
System.out.println("Input: ");
do{
System.out.println("Enter name: ");
cmd = sc.nextLine();
if(cmd.equals(""))
System.out.println("[Error] Invalid name!");
} while (cmd.equals(""));
employee.setName(cmd);
do{
System.out.println("Enter age: ");
cmd = sc.nextLine();
if(cmd.equals(""))
System.out.println("[Error] Invalid age!");
} while (cmd.equals(""));
employee.setAge(Integer.parseInt(cmd));
do{
System.out.println("Enter adress: ");
cmd = sc.nextLine();
if(cmd.equals(""))
System.out.println("[Error] Invalid address!");
} while (cmd.equals(""));
employee.setAddress(cmd);
do{
System.out.println("Enter salary: ");
cmd = sc.nextLine();
if(cmd.equals(""))
System.out.println("[Error] Invalid salary!");
} while (cmd.equals(""));
employee.setSalary(Double.parseDouble(cmd));
do{
System.out.println("Enter salary coefficient: ");
cmd = sc.nextLine();
if(cmd.equals(""))
System.out.println("[Error] Invalid salary coefficient!");
} while (cmd.equals(""));
employee.setSalaryCoefficient(Double.parseDouble(cmd));
list.add(employee);
}
@Override
public String toString() {
return name + " - " + age + " - " + address + " - " +
Employee.format((long) salary) + " - " + salaryCoefficient + " - " +
Employee.format(caculateSalary());
}
}
HTDH.java
package de170737.htdt;
Employee cmd;
for (int i = 0; i < list.length - 1; i++) {
for (int j = 0; j < list.length; j++) {
if(list[i].getName().compareTo(list[j].getName()) < 0){
cmd = list[i];
list[i] = list[j];
list[j] = cmd;
}
}
}
for(Employee employee : list) {
System.out.println(employee);
}
}
}
HOMEWORK
package DE170737.hang;
import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public Homework1() {
}