OOP-Question
OOP-Question
*;
import java.util.Scanner;
// Constructor
public Car(String name, double price, int speed) {
this.name = name;
this.price = price;
this.speed = speed;
}
// Getters
public String getName() {
return name;
}
@Override
public String toString() {
return "Car{name='" + name + '\'' + ", price=" + price + ", speed=" + speed
+ '}';
}
}
} catch (IOException e) {
System.err.println("Error during file operations: " + e.getMessage());
} catch (ClassNotFoundException e) {
System.err.println("Error: Class not found during deserialization: " +
e.getMessage());
}
}
while (true) {
try {
Car car = (Car) ois.readObject();
if (car.getName().equalsIgnoreCase(searchName)) {
System.out.println("Car found: " + car);
found = true;
break;
}
} catch (EOFException e) {
break; // End of file reached
}
}
if (!found) {
System.out.println("Car with name '" + searchName + "' not
found.");
}
}
}
}