[POO] added verifications to Vehicle.java
This commit is contained in:
parent
7e9b485fc8
commit
f17880dd81
|
@ -7,7 +7,7 @@ import java.util.Scanner;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private static final Scanner sin = new Scanner(System.in);
|
private static final Scanner sin = new Scanner(System.in);
|
||||||
private static VehicleComp[] vehicleComps;
|
public static VehicleComp[] vehicleComps;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package aula08.ex1.Vehicles;
|
package aula08.ex1.Vehicles;
|
||||||
|
|
||||||
import aula08.ex1.Interfaces.IKmTravelled;
|
import aula08.ex1.Interfaces.IKmTravelled;
|
||||||
|
import aula08.ex1.VehicleComp;
|
||||||
|
import aula08.ex1.Main;
|
||||||
import utils.Validations;
|
import utils.Validations;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -17,6 +19,13 @@ public abstract class Vehicle implements IKmTravelled {
|
||||||
public Vehicle(String plate, String brand, String model, int potency) {
|
public Vehicle(String plate, String brand, String model, int potency) {
|
||||||
if (!Validations.validateVehiclePlate(plate))
|
if (!Validations.validateVehiclePlate(plate))
|
||||||
throw new IllegalArgumentException("Invalid plate!");
|
throw new IllegalArgumentException("Invalid plate!");
|
||||||
|
for (VehicleComp vehicleComp : Main.vehicleComps)
|
||||||
|
if (vehicleComp.getVehicleByPlate(plate) != null)
|
||||||
|
throw new IllegalArgumentException("Plate already exists!");
|
||||||
|
if (brand == null || brand.isEmpty())
|
||||||
|
throw new IllegalArgumentException("Brand must not be empty");
|
||||||
|
if (model == null || model.isEmpty())
|
||||||
|
throw new IllegalArgumentException("Model must not be empty");
|
||||||
if (potency <= 0)
|
if (potency <= 0)
|
||||||
throw new IllegalArgumentException("Potency must be positive");
|
throw new IllegalArgumentException("Potency must be positive");
|
||||||
this.plate = plate;
|
this.plate = plate;
|
||||||
|
|
Loading…
Reference in New Issue