Branch sync | [POO] few fixes #59
This commit is contained in:
commit
4c7d002115
|
@ -4,9 +4,9 @@ public enum EngineType {
|
||||||
FUEL, ELECTRIC;
|
FUEL, ELECTRIC;
|
||||||
|
|
||||||
public static EngineType fromString(String string) {
|
public static EngineType fromString(String string) {
|
||||||
return switch (string) {
|
return switch (string.toUpperCase()) {
|
||||||
case "FUEL", "Fuel", "fuel" -> EngineType.FUEL;
|
case "FUEL" -> FUEL;
|
||||||
case "ELECTRIC", "Electric", "electric" -> EngineType.ELECTRIC;
|
case "ELECTRIC" -> ELECTRIC;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -4,11 +4,11 @@ public enum AlimentType {
|
||||||
MEAT, FISH, CEREAL, VEGETABLE;
|
MEAT, FISH, CEREAL, VEGETABLE;
|
||||||
|
|
||||||
public static AlimentType fromString(String string) {
|
public static AlimentType fromString(String string) {
|
||||||
return switch (string) {
|
return switch (string.toUpperCase()) {
|
||||||
case "MEAT", "Meat", "meat" -> MEAT;
|
case "MEAT"-> MEAT;
|
||||||
case "FISH", "Fish", "fish" -> FISH;
|
case "FISH" -> FISH;
|
||||||
case "CEREAL", "Cereal", "cereal" -> CEREAL;
|
case "CEREAL" -> CEREAL;
|
||||||
case "VEGETABLE", "Vegetable", "vegetable" -> VEGETABLE;
|
case "VEGETABLE" -> VEGETABLE;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@ public enum DishType {
|
||||||
NORMAL, VEGAN, DIET;
|
NORMAL, VEGAN, DIET;
|
||||||
|
|
||||||
public static DishType fromString(String string) {
|
public static DishType fromString(String string) {
|
||||||
return switch (string) {
|
return switch (string.toUpperCase()) {
|
||||||
case "NORMAL", "Normal", "normal" -> NORMAL;
|
case "NORMAL" -> NORMAL;
|
||||||
case "VEGAN", "Vegan", "vegan" -> VEGAN;
|
case "VEGAN" -> VEGAN;
|
||||||
case "DIET", "Diet", "diet" -> DIET;
|
case "DIET" -> DIET;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ public enum FishState {
|
||||||
FRESH, FROZEN;
|
FRESH, FROZEN;
|
||||||
|
|
||||||
public static FishState fromString(String string) {
|
public static FishState fromString(String string) {
|
||||||
return switch (string) {
|
return switch (string.toUpperCase()) {
|
||||||
case "FRESH", "Fresh", "fresh" -> FRESH;
|
case "FRESH"-> FRESH;
|
||||||
case "FROZEN", "Frozen", "frozen" -> FROZEN;
|
case "FROZEN" -> FROZEN;
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package aula08.ex2.Enums;
|
package aula08.ex2.Enums;
|
||||||
|
|
||||||
public enum MeatType {
|
public enum MeatType {
|
||||||
COW, PORK, TURKEY, CHICKEN;
|
COW, PORK, TURKEY, CHICKEN, OTHER;
|
||||||
|
|
||||||
public static MeatType fromString(String string) {
|
public static MeatType fromString(String string) {
|
||||||
return switch (string) {
|
return switch (string.toUpperCase()) {
|
||||||
case "COW", "Cow", "cow" -> COW;
|
case "COW" -> COW;
|
||||||
case "PORK", "Pork", "pork" -> PORK;
|
case "PORK" -> PORK;
|
||||||
case "TURKEY", "Turkey", "turkey" -> TURKEY;
|
case "TURKEY" -> TURKEY;
|
||||||
case "CHICKEN", "Chicken", "chicken" -> CHICKEN;
|
case "CHICKEN" -> CHICKEN;
|
||||||
default -> null;
|
default -> OTHER;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ public enum MeatType {
|
||||||
case PORK -> "PORK";
|
case PORK -> "PORK";
|
||||||
case TURKEY -> "TURKEY";
|
case TURKEY -> "TURKEY";
|
||||||
case CHICKEN -> "CHICKEN";
|
case CHICKEN -> "CHICKEN";
|
||||||
|
default -> "OTHER";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue