-2
선생님이 채워 주신 코드에 문제가 있습니다.정적 클래스 팩터 리 메서드에서 속성 가져 오기
저는 Car 클래스를 가지고 있고 또 다른 두 개의 하위 클래스 인 LightCar와 heavyCar는 Car 클래스를 확장합니다. 이 같은 기본적으로 내가 주어진 일이 :
public abstract class Car{
public static Car newCar(File file) throws FileNotFoundException {
carType = null;
Scanner in = new Scanner(file);
while (in.hasNext()) {
String line = in.nextLine();
String tokens[] = line.split(";");
if (line.contains("Light Weight")) {
LightCar lightC = new LightCar(Long
.valueOf(tokens[1]).longValue(), tokens[3]);
in.close();
carType = lightC;
}
if (line.contains("Heavy Weight")) {
HeavyCar heavyC = new HeavyCar(Long.valueOf(
tokens[1]).longValue(), tokens[3]);
in.close();
carType = heavyC;
}
}
in.close();
return carType;
}
public getLicense(){
return.. // PROBLEM HERE
}
}
public getCarColor(){
return.. PROBLEM HERE
}
}
임은이 모든 정보가 들어있는 파일을 읽을 예정.
내게 큰 의문은 어떻게 그런 정적 팩터드 메소드가있는 경우 그 함수를 사용할 수 있습니까? 해당 정보를 얻으려고 애쓰는 데 어려움을 겪고 있습니다.
나는 예를 들어도 일부 JTestUnits을 받았다 :
Car c = new LightCar(3, "Volvo");
assertEquals(c.getColor(), "Red");
고맙습니다. :) 문제가 해결되어서 문제가 해결되었습니다. – JDev
당신을 환영합니다 ^^ – TheNawaKer