0
여기에 CreateEmployee 클래스가 있는데이 클래스를 Company 클래스 내부에서 사용하고 싶습니다. 내가 어떻게 그 일을하는거야?Java. ArrayList를 다른 클래스로 이식
내가 시도한 것은 회사 클래스 내에 직원 클래스 코드를 작성하는 것이 었습니다. 일 것이다, 그러나, 나는 다른 클래스는 ArrayList를
public class CreateEmployee {
private ArrayList<Employee> employeeList;
Scanner fileScanner;
String name;
String pw;
String [] dataArray;
String data;
int salary;
public CreateEmployee(){
try
{
fileScanner = new Scanner(new File("employee.dat"));
}
catch (FileNotFoundException ex)
{
System.out.println("FileNotFoundException caught");
}
employeeList = new ArrayList<Employee>();
while(fileScanner.hasNextLine())
{
//reset the array for every new line
dataArray = new String [10];
//take the file line and split into 3 different parts
data = fileScanner.nextLine();
dataArray = data.split("\\|");
//assign the 3 different parts to the variables.
name = dataArray[0];
pw = dataArray[1]; // this is a error. only after first run.
salary = Integer.parseInt(dataArray[2]);
//create a player object, add to playerList
Employee employee = new Employee(name, pw, salary);
employeeList.add(employee);
}
}
public ArrayList getEmployeeList(){
return employeeList;
}
public void funcA(){
//sample method to be executed at Company class
}
}
public class Company{
public Company{
//i would like to call the CreateEmployee constructor here.
// how should i go about it?
}
public static void main(String[] args){
new Company().run();
}
public void run(){
//i would like to call a function of CreateEmployee class here.
// how should i go about it?
{
}
왜 'CreateEmployee' 생성자에서 모든 작업을 수행하고 있습니까? '새로운 CreateEmployee();'? –