From da5808a180b4d3ae1280b91bc226b50453b5ab88 Mon Sep 17 00:00:00 2001 From: TiagoRG <35657250+TiagoRG@users.noreply.github.com> Date: Fri, 7 Apr 2023 23:36:02 +0100 Subject: [PATCH] [POO] aula08 ex1 refactoring --- .../poo/src/aula08/ex1/{ => Enums}/EngineType.java | 6 +++--- .../poo/src/aula08/ex1/IEletricVehicle.java | 6 ------ .../aula08/ex1/Interfaces/IElectricVehicle.java | 6 ++++++ .../aula08/ex1/{ => Interfaces}/IFuelVehicle.java | 2 +- .../aula08/ex1/{ => Interfaces}/IKmTravelled.java | 2 +- 1ano/2semestre/poo/src/aula08/ex1/Main.java | 3 +++ 1ano/2semestre/poo/src/aula08/ex1/VehicleComp.java | 7 +++++-- .../poo/src/aula08/ex1/{ => Vehicles}/Bus.java | 10 +++++++--- .../poo/src/aula08/ex1/{ => Vehicles}/Car.java | 10 +++++++--- .../src/aula08/ex1/{ => Vehicles}/Motorcycle.java | 4 +++- .../poo/src/aula08/ex1/{ => Vehicles}/Taxi.java | 4 +++- .../poo/src/aula08/ex1/{ => Vehicles}/Truck.java | 4 +++- .../poo/src/aula08/ex1/{ => Vehicles}/Vehicle.java | 14 ++++++++------ 13 files changed, 50 insertions(+), 28 deletions(-) rename 1ano/2semestre/poo/src/aula08/ex1/{ => Enums}/EngineType.java (64%) delete mode 100644 1ano/2semestre/poo/src/aula08/ex1/IEletricVehicle.java create mode 100644 1ano/2semestre/poo/src/aula08/ex1/Interfaces/IElectricVehicle.java rename 1ano/2semestre/poo/src/aula08/ex1/{ => Interfaces}/IFuelVehicle.java (73%) rename 1ano/2semestre/poo/src/aula08/ex1/{ => Interfaces}/IKmTravelled.java (76%) rename 1ano/2semestre/poo/src/aula08/ex1/{ => Vehicles}/Bus.java (90%) rename 1ano/2semestre/poo/src/aula08/ex1/{ => Vehicles}/Car.java (90%) rename 1ano/2semestre/poo/src/aula08/ex1/{ => Vehicles}/Motorcycle.java (96%) rename 1ano/2semestre/poo/src/aula08/ex1/{ => Vehicles}/Taxi.java (96%) rename 1ano/2semestre/poo/src/aula08/ex1/{ => Vehicles}/Truck.java (96%) rename 1ano/2semestre/poo/src/aula08/ex1/{ => Vehicles}/Vehicle.java (84%) diff --git a/1ano/2semestre/poo/src/aula08/ex1/EngineType.java b/1ano/2semestre/poo/src/aula08/ex1/Enums/EngineType.java similarity index 64% rename from 1ano/2semestre/poo/src/aula08/ex1/EngineType.java rename to 1ano/2semestre/poo/src/aula08/ex1/Enums/EngineType.java index 3358d13..743da2c 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/EngineType.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Enums/EngineType.java @@ -1,12 +1,12 @@ -package aula08.ex1; +package aula08.ex1.Enums; public enum EngineType { - FUEL, ELETRIC; + FUEL, ELECTRIC; public static EngineType fromString(String string) { return switch (string) { case "FUEL", "Fuel", "fuel" -> EngineType.FUEL; - case "ELETRIC", "Eletric", "eletric" -> EngineType.ELETRIC; + case "ELECTRIC", "Electric", "electric" -> EngineType.ELECTRIC; default -> null; }; } diff --git a/1ano/2semestre/poo/src/aula08/ex1/IEletricVehicle.java b/1ano/2semestre/poo/src/aula08/ex1/IEletricVehicle.java deleted file mode 100644 index 561c874..0000000 --- a/1ano/2semestre/poo/src/aula08/ex1/IEletricVehicle.java +++ /dev/null @@ -1,6 +0,0 @@ -package aula08.ex1; - -public interface IEletricVehicle { - int currentBatteryLvl(); - void charge(int percentage); -} diff --git a/1ano/2semestre/poo/src/aula08/ex1/Interfaces/IElectricVehicle.java b/1ano/2semestre/poo/src/aula08/ex1/Interfaces/IElectricVehicle.java new file mode 100644 index 0000000..6538386 --- /dev/null +++ b/1ano/2semestre/poo/src/aula08/ex1/Interfaces/IElectricVehicle.java @@ -0,0 +1,6 @@ +package aula08.ex1.Interfaces; + +public interface IElectricVehicle { + int currentBatteryLvl(); + void charge(int percentage); +} diff --git a/1ano/2semestre/poo/src/aula08/ex1/IFuelVehicle.java b/1ano/2semestre/poo/src/aula08/ex1/Interfaces/IFuelVehicle.java similarity index 73% rename from 1ano/2semestre/poo/src/aula08/ex1/IFuelVehicle.java rename to 1ano/2semestre/poo/src/aula08/ex1/Interfaces/IFuelVehicle.java index c04d95a..93e9467 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/IFuelVehicle.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Interfaces/IFuelVehicle.java @@ -1,4 +1,4 @@ -package aula08.ex1; +package aula08.ex1.Interfaces; public interface IFuelVehicle { int fuelLevel(); diff --git a/1ano/2semestre/poo/src/aula08/ex1/IKmTravelled.java b/1ano/2semestre/poo/src/aula08/ex1/Interfaces/IKmTravelled.java similarity index 76% rename from 1ano/2semestre/poo/src/aula08/ex1/IKmTravelled.java rename to 1ano/2semestre/poo/src/aula08/ex1/Interfaces/IKmTravelled.java index 905795b..cc7f815 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/IKmTravelled.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Interfaces/IKmTravelled.java @@ -1,4 +1,4 @@ -package aula08.ex1; +package aula08.ex1.Interfaces; public interface IKmTravelled { void trip(int km); diff --git a/1ano/2semestre/poo/src/aula08/ex1/Main.java b/1ano/2semestre/poo/src/aula08/ex1/Main.java index 82f3784..48684cf 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/Main.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Main.java @@ -1,5 +1,8 @@ package aula08.ex1; +import aula08.ex1.Enums.EngineType; +import aula08.ex1.Vehicles.*; + import java.util.Scanner; public class Main { diff --git a/1ano/2semestre/poo/src/aula08/ex1/VehicleComp.java b/1ano/2semestre/poo/src/aula08/ex1/VehicleComp.java index 2806086..c8da03d 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/VehicleComp.java +++ b/1ano/2semestre/poo/src/aula08/ex1/VehicleComp.java @@ -1,5 +1,8 @@ package aula08.ex1; +import aula08.ex1.Enums.EngineType; +import aula08.ex1.Vehicles.*; + import java.util.Scanner; public class VehicleComp { @@ -85,7 +88,7 @@ public class VehicleComp { case 2, 3 -> { System.out.print("Car's trunk size: "); int trunkSize = Integer.parseInt(sin.nextLine()); - System.out.print("What's the engine type? (FUEL/ELETRIC): "); + System.out.print("What's the engine type? (FUEL/ELECTRIC): "); EngineType engineType = EngineType.fromString(sin.nextLine()); Car car = new Car(plate, brand, model, potency, boardNumber, trunkSize, engineType); if (vehicleType == 2) @@ -102,7 +105,7 @@ public class VehicleComp { if (vehicleType == 4) { System.out.print("Bus passenger limit: "); int maxPassengers = Integer.parseInt(sin.nextLine()); - System.out.print("What's the engine type? (FUEL/ELETRIC): "); + System.out.print("What's the engine type? (FUEL/ELECTRIC): "); EngineType engineType = EngineType.fromString(sin.nextLine()); addVehicle(new Bus(plate, brand, model, potency, boardNumber, weight, maxPassengers, engineType)); } else { diff --git a/1ano/2semestre/poo/src/aula08/ex1/Bus.java b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Bus.java similarity index 90% rename from 1ano/2semestre/poo/src/aula08/ex1/Bus.java rename to 1ano/2semestre/poo/src/aula08/ex1/Vehicles/Bus.java index 8882217..5abbe76 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/Bus.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Bus.java @@ -1,8 +1,12 @@ -package aula08.ex1; +package aula08.ex1.Vehicles; + +import aula08.ex1.Enums.EngineType; +import aula08.ex1.Interfaces.IElectricVehicle; +import aula08.ex1.Interfaces.IFuelVehicle; import java.util.Objects; -public class Bus extends Vehicle implements IFuelVehicle, IEletricVehicle { +public class Bus extends Vehicle implements IFuelVehicle, IElectricVehicle { private final int boardNumber; private final int weight; private final int maxPassengers; @@ -84,7 +88,7 @@ public class Bus extends Vehicle implements IFuelVehicle, IEletricVehicle { @Override public void fillTank(int level) { - if (this.engineType == EngineType.ELETRIC) + if (this.engineType == EngineType.ELECTRIC) return; this.fuelLevel = level; } diff --git a/1ano/2semestre/poo/src/aula08/ex1/Car.java b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Car.java similarity index 90% rename from 1ano/2semestre/poo/src/aula08/ex1/Car.java rename to 1ano/2semestre/poo/src/aula08/ex1/Vehicles/Car.java index 7fbe39e..86504ef 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/Car.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Car.java @@ -1,8 +1,12 @@ -package aula08.ex1; +package aula08.ex1.Vehicles; + +import aula08.ex1.Enums.EngineType; +import aula08.ex1.Interfaces.IElectricVehicle; +import aula08.ex1.Interfaces.IFuelVehicle; import java.util.Objects; -public class Car extends Vehicle implements IEletricVehicle, IFuelVehicle { +public class Car extends Vehicle implements IElectricVehicle, IFuelVehicle { private final int boardNumber; private final int trunkSize; private final EngineType engineType; @@ -84,7 +88,7 @@ public class Car extends Vehicle implements IEletricVehicle, IFuelVehicle { @Override public void fillTank(int level) { - if (this.engineType == EngineType.ELETRIC) + if (this.engineType == EngineType.ELECTRIC) return; this.fuelLevel = level; } diff --git a/1ano/2semestre/poo/src/aula08/ex1/Motorcycle.java b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Motorcycle.java similarity index 96% rename from 1ano/2semestre/poo/src/aula08/ex1/Motorcycle.java rename to 1ano/2semestre/poo/src/aula08/ex1/Vehicles/Motorcycle.java index f014525..e50f3c7 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/Motorcycle.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Motorcycle.java @@ -1,4 +1,6 @@ -package aula08.ex1; +package aula08.ex1.Vehicles; + +import aula08.ex1.Interfaces.IFuelVehicle; import java.util.Objects; diff --git a/1ano/2semestre/poo/src/aula08/ex1/Taxi.java b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Taxi.java similarity index 96% rename from 1ano/2semestre/poo/src/aula08/ex1/Taxi.java rename to 1ano/2semestre/poo/src/aula08/ex1/Vehicles/Taxi.java index f5f3f1f..6e35879 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/Taxi.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Taxi.java @@ -1,4 +1,6 @@ -package aula08.ex1; +package aula08.ex1.Vehicles; + +import aula08.ex1.Enums.EngineType; import java.util.Objects; diff --git a/1ano/2semestre/poo/src/aula08/ex1/Truck.java b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Truck.java similarity index 96% rename from 1ano/2semestre/poo/src/aula08/ex1/Truck.java rename to 1ano/2semestre/poo/src/aula08/ex1/Vehicles/Truck.java index 62e320f..17738d5 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/Truck.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Truck.java @@ -1,4 +1,6 @@ -package aula08.ex1; +package aula08.ex1.Vehicles; + +import aula08.ex1.Interfaces.IFuelVehicle; import java.util.Objects; diff --git a/1ano/2semestre/poo/src/aula08/ex1/Vehicle.java b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Vehicle.java similarity index 84% rename from 1ano/2semestre/poo/src/aula08/ex1/Vehicle.java rename to 1ano/2semestre/poo/src/aula08/ex1/Vehicles/Vehicle.java index 4f6e813..a3edf88 100644 --- a/1ano/2semestre/poo/src/aula08/ex1/Vehicle.java +++ b/1ano/2semestre/poo/src/aula08/ex1/Vehicles/Vehicle.java @@ -1,4 +1,6 @@ -package aula08.ex1; +package aula08.ex1.Vehicles; + +import aula08.ex1.Interfaces.IKmTravelled; import java.util.Objects; @@ -11,7 +13,7 @@ public abstract class Vehicle implements IKmTravelled { private int lastTripKm; private int km; - protected Vehicle(String plate, String brand, String model, int potency) { + public Vehicle(String plate, String brand, String model, int potency) { this.plate = plate; this.brand = brand; this.model = model; @@ -20,19 +22,19 @@ public abstract class Vehicle implements IKmTravelled { this.km = 0; } - protected String getPlate() { + public String getPlate() { return this.plate; } - protected String getBrand() { + public String getBrand() { return this.brand; } - protected String getModel() { + public String getModel() { return this.model; } - protected int getPotency() { + public int getPotency() { return this.potency; }