Alright I know the title is really vague but I can't wrap my head around how to word my problem and therefore I can't google it; that's why I'm asking you guys
Basically I have a constructor that takes a file input and depending on the file name (in my example we're using file.txt or employees.txt) we do something to it. Now I have no idea if this is even a good idea or not or if there is another way to do multiple duplicate constructors. Here's my code so far and thanks for helping me out!:
public class CarDealershipSystem {
public CarDealershipSystem(File file) {
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
ArrayList<Car> carObjectArray = new ArrayList<Car>();
while((br.readLine()) != null) {
if (file == cars.txt) {
String line = br.readLine();
String[] lineArray = line.split(",");
Car car = new Car();
car.setMake(lineArray[0]);
car.setModel(lineArray[1]);
carObjectArray.add(car);
}
else if (file == employees.txt) {
;
}
}
}catch(IOException e) {
e.getLocalizedMessage();
e.printStackTrace();
}
}
}