School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,41 @@
package Controller;
import Model.IVehicle;
import Repository.IRepository;
public class Controller {
private IRepository _repository;
public Controller(IRepository repository) {
this._repository = repository;
}
public void addVehicle(IVehicle vehicle) throws IllegalArgumentException {
_repository.add(vehicle);
}
public void removeVehicle(int index) throws IllegalArgumentException {
_repository.remove(index);
}
public IVehicle[] getAllVehicles() {
return _repository.getAll();
}
public IVehicle[] filterVehicles(String color){
IVehicle[] vehicles = _repository.getAll();
IVehicle[] filteredVehicles = new IVehicle[_repository.getSize()];
int index = 0;
for(IVehicle vehicle : vehicles) {
if(vehicle.getColor().equals(color)) {
filteredVehicles[index++] = vehicle;
}
}
IVehicle[] copy = new IVehicle[index];
for(int i = 0; i < index; i++) {
copy[i] = filteredVehicles[i];
}
return copy;
}
}