Basically, I want to throw a new TruckException if the String array parameter materials is null when we create a new Truck via its constructor. What should I do in the if statement to verify if the String array materials is null?
{
private String[] materials = new String[5];
private long permit = 0;
private String company = "";
public Truck(String[] materials, long permit, String company, String ownerName, String ownerAddress, String brand, String model, String licencePlate, float value) throws TruckException, VehicleException
{
super(ownerName, ownerAddress, brand, model, licencePlate, value);
setMaterials(materials); //on ne fait pas setMaterial(this.materials) car setMaterials modifie this.materials
if(materials.length == 0 || materials.length>5 // ||???) //this if statement
throw new TruckException("materials");
this.company = company;
if(company.equals(""))
throw new VehicleException("company");
//rest of code...
}```
materials == null. Not sure what the question is.if (materials == null || materials.length == 0) { throw new TruckException(); }<-- Obviously this check must be done before you try to use the array.