In my task I need to store class Car into setOfCars. Reading must be done from file. I have id, nameOfCar, noOfSeats.
Input:
1
Mercedes
GTR 2
In main I have this:
Set<Car> listOfCars= eneterCars();
But intellij cast it to:
Set<Cars> listOfCars= (Set<Car>) eneterCars();
And this doesnt work.
Method I call is also in main:
File cars= new File("dat/cars.txt");
try(FileReader fileReader = new FileReader(cars);
BufferedReader reader = new BufferedReader(fileReader)){
String readLine;
List<Car> listOfCars= new ArrayList<>();
while((readLine= reader.readLine()) != null){
Long id = Long.parseLong(readLine);
String name= reader.readLine();
Integer noOfSeats=Integer.parseInt(reader.readLine());
listOfCars.add(new Car(id, name, noOfSeats));
//System.out.println(id + " name" + name+ " " + noOfSeats);
}
return cars;
I want to store information from file to set so that I could use it later. But I get that cast error when I call this function.
return carsactually returns the file not the list.