diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/lab-java-interfaces-and-abstract-classes.iml b/.idea/lab-java-interfaces-and-abstract-classes.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/.idea/lab-java-interfaces-and-abstract-classes.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..4eb4f51 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ff55171 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index ce069b6..0c5435c 100644 --- a/README.md +++ b/README.md @@ -30,18 +30,18 @@ Once you finish the assignment, submit a URL link to your repository or your pul
-### Car Inventory System +### CarInventorySystem.Car Inventory System -1. Suppose you are building a car inventory system. All cars have a `vinNumber`, `make`, `model` and `mileage`. But no car is just a car. Each car is either a `Sedan`, a `UtilityVehicle` or a `Truck`. -2. Create an abstract class named `Car` and define the following properties and behaviors: +1. Suppose you are building a car inventory system. All cars have a `vinNumber`, `make`, `model` and `mileage`. But no car is just a car. Each car is either a `CarInventorySystem.Sedan`, a `CarInventorySystem.UtilityVehicle` or a `CarInventorySystem.Truck`. +2. Create an abstract class named `CarInventorySystem.Car` and define the following properties and behaviors: - `vinNumber`: a `String` representing the VIN number of the car - `make`: a `String` representing the make of the car - `model`: a `String` representing the model of the car - `mileage`: an `int` representing the mileage of the car - `getInfo()`: a method that returns a `String` containing all of the car's properties in a readable format -3. Create three classes that extend `Car`: `Sedan`, `UtilityVehicle` and `Truck`. -4. `UtilityVehicle` objects should have an additional `fourWheelDrive` property, a `boolean` that represents whether the vehicle has four-wheel drive. -5. `Truck` objects should have an additional `towingCapacity` property, a `double` that represents the towing capacity of the truck. +3. Create three classes that extend `CarInventorySystem.Car`: `CarInventorySystem.Sedan`, `CarInventorySystem.UtilityVehicle` and `CarInventorySystem.Truck`. +4. `CarInventorySystem.UtilityVehicle` objects should have an additional `fourWheelDrive` property, a `boolean` that represents whether the vehicle has four-wheel drive. +5. `CarInventorySystem.Truck` objects should have an additional `towingCapacity` property, a `double` that represents the towing capacity of the truck.
diff --git a/out/production/lab-java-interfaces-and-abstract-classes/BigDecimalOperations/BigDecimalOperations.class b/out/production/lab-java-interfaces-and-abstract-classes/BigDecimalOperations/BigDecimalOperations.class new file mode 100644 index 0000000..1631d10 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/BigDecimalOperations/BigDecimalOperations.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/BigDecimalOperations/BigDecimalOperationsApplication.class b/out/production/lab-java-interfaces-and-abstract-classes/BigDecimalOperations/BigDecimalOperationsApplication.class new file mode 100644 index 0000000..7673387 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/BigDecimalOperations/BigDecimalOperationsApplication.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/AppCarInventorySystem.class b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/AppCarInventorySystem.class new file mode 100644 index 0000000..2929606 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/AppCarInventorySystem.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/Car.class b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/Car.class new file mode 100644 index 0000000..b021442 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/Car.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/Sedan.class b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/Sedan.class new file mode 100644 index 0000000..ebdf4bb Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/Sedan.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/Truck.class b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/Truck.class new file mode 100644 index 0000000..d8db098 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/Truck.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/UtilityVehicle.class b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/UtilityVehicle.class new file mode 100644 index 0000000..cbc6e8d Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/CarInventorySystem/UtilityVehicle.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntArrayList.class b/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntArrayList.class new file mode 100644 index 0000000..b9c1731 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntArrayList.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntList.class b/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntList.class new file mode 100644 index 0000000..85a0482 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntList.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntListTest.class b/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntListTest.class new file mode 100644 index 0000000..4420091 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntListTest.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntVector.class b/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntVector.class new file mode 100644 index 0000000..5b48e94 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/IntListInterface/IntVector.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/AppVideoStreamingService.class b/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/AppVideoStreamingService.class new file mode 100644 index 0000000..23b85ca Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/AppVideoStreamingService.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/Movie.class b/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/Movie.class new file mode 100644 index 0000000..a5bd952 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/Movie.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/TvSeries.class b/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/TvSeries.class new file mode 100644 index 0000000..c63f270 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/TvSeries.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/Video.class b/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/Video.class new file mode 100644 index 0000000..a6ff3b4 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/VideoStreamingService/Video.class differ diff --git a/src/BigDecimalOperations/BigDecimalOperations.java b/src/BigDecimalOperations/BigDecimalOperations.java new file mode 100644 index 0000000..d6bbb0e --- /dev/null +++ b/src/BigDecimalOperations/BigDecimalOperations.java @@ -0,0 +1,16 @@ +package BigDecimalOperations; +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class BigDecimalOperations { + //METODO1⤵ + public static double roundToDouble(BigDecimal number){ + BigDecimal roundedNumber = number.setScale(2, RoundingMode.HALF_UP); + return roundedNumber.doubleValue(); + } + //METODO2⤵ + public static BigDecimal reverseSignAndRound(BigDecimal number){ + BigDecimal negatedNumber = number.negate(); + return negatedNumber.setScale(1, RoundingMode.HALF_UP); + } +} diff --git a/src/BigDecimalOperations/BigDecimalOperationsApplication.java b/src/BigDecimalOperations/BigDecimalOperationsApplication.java new file mode 100644 index 0000000..82e2cce --- /dev/null +++ b/src/BigDecimalOperations/BigDecimalOperationsApplication.java @@ -0,0 +1,25 @@ +package BigDecimalOperations; + +import java.math.BigDecimal; + +import static BigDecimalOperations.BigDecimalOperations.reverseSignAndRound; +import static BigDecimalOperations.BigDecimalOperations.roundToDouble; + +public class BigDecimalOperationsApplication { + + public static void main(String[] args) { + BigDecimal number1 = new BigDecimal("23.2323232323"); + BigDecimal number2 = new BigDecimal("32.3232323232"); + BigDecimal number3 = new BigDecimal("-32.323232323"); + + System.out.println("TEST METHOD 1 ↪"); + System.out.println("NUMBER TO TEST ➡ " + number1 + "\nResult Method 1 (ROUNDED TO 2 DECIMALS) ➡ " + roundToDouble(number1)); + System.out.println("METHOD 1 TESTED ________________________⤴\n"); + System.out.println("\nTEST METHOD 2 ↪"); + System.out.println("NUMBER TO TEST ➡ " + number2 + "\nResult Method 2 (INVERTED SIGN TO NEGATIVE) ➡ " + reverseSignAndRound(number2)); + System.out.println("METHOD 2 NEGATED NUMBER TESTED _____________⤴\n"); + System.out.println("NUMBER TO TEST ➡ " + number3 + "\nResult Method 2 (INVERTED SIGN TO POSITIVE) ➡ " + reverseSignAndRound(number3)); + System.out.println("METHOD 2 POSITIVE NUMBER TESTED ____________⤴"); + } + +} diff --git a/src/CarInventorySystem/AppCarInventorySystem.java b/src/CarInventorySystem/AppCarInventorySystem.java new file mode 100644 index 0000000..95d7262 --- /dev/null +++ b/src/CarInventorySystem/AppCarInventorySystem.java @@ -0,0 +1,27 @@ +package CarInventorySystem; + +import java.util.ArrayList; +import java.util.List; + +public class AppCarInventorySystem { + static void main(String[] args) { + List cars = new ArrayList<>(); + + + cars.add(new Sedan("1425MXV", "Hyundai", "i30", 35000)); + cars.add(new UtilityVehicle("2323FFF", "Ford", "Kuga", 3000, false)); + cars.add(new Truck("1456GHH", "Chevrolet", "Silverado", 3200, 10000.0)); + cars.add(new UtilityVehicle("4589NGT", "Volkswagen", "Atlas", 14000, true)); + cars.add(new Truck("2555MGT", "Ford", "F-150", 4000, 10000.0)); + cars.add(new Sedan("3345GTX", "BMW", "M3", 1000)); + + + for (Car car : cars) { + System.out.println(car.getInfo()); + System.out.println("<----------------------------------------------->"); + } + + + + } +} \ No newline at end of file diff --git a/src/CarInventorySystem/Car.java b/src/CarInventorySystem/Car.java new file mode 100644 index 0000000..742f4f4 --- /dev/null +++ b/src/CarInventorySystem/Car.java @@ -0,0 +1,54 @@ +package CarInventorySystem; + +public abstract class Car { + + private String vinNumber; + private String make; + private String model; + private int mileage; + + public Car(String vinNumber, String make, String model, int mileage) { + this.vinNumber = vinNumber; + this.make = make; + this.model = model; + this.mileage = mileage; + } + + public String getVinNumber() { + return vinNumber; + } + + public void setVinNumber(String vinNumber) { + this.vinNumber = vinNumber; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public String getMake() { + return make; + } + + public void setMake(String make) { + this.make = make; + } + + public double getMileage() { + return mileage; + } + + public void setMileage(int mileage) { + this.mileage = mileage; + } + + public String getInfo() { + return "🔢Vin:" + vinNumber + "\n🚘Make:" + make + "\nModel:" + model + "\n➡Mileage:" + mileage + " km"; + + } + +} diff --git a/src/CarInventorySystem/Sedan.java b/src/CarInventorySystem/Sedan.java new file mode 100644 index 0000000..82f4182 --- /dev/null +++ b/src/CarInventorySystem/Sedan.java @@ -0,0 +1,8 @@ +package CarInventorySystem; + +public class Sedan extends Car { + public Sedan(String vinNumber, String make, String model, int mileage) { + super(vinNumber, make, model, mileage); + } + +} diff --git a/src/CarInventorySystem/Truck.java b/src/CarInventorySystem/Truck.java new file mode 100644 index 0000000..f52abc9 --- /dev/null +++ b/src/CarInventorySystem/Truck.java @@ -0,0 +1,25 @@ +package CarInventorySystem; + +public class Truck extends Car{ + private double towingCapacity; + + public Truck(String vinNumber, String make, String model, int mileage, double towingCapacity) { + super(vinNumber, make, model, mileage); + this.towingCapacity = towingCapacity; + } + + public double getTowingCapacity() { + + return towingCapacity; + } + + public void setTowingCapacity(double towingCapacity) { + + this.towingCapacity = towingCapacity; + } + @Override + public String getInfo(){ + return ("🔢Vin:" + getVinNumber() + "\nMake:" + getMake() + "\nModel:" + getModel() + "\nMileage:" + getMileage() + " km" + "\nTowing Capacity:" + getTowingCapacity() + " kg"); + } + +} diff --git a/src/CarInventorySystem/UtilityVehicle.java b/src/CarInventorySystem/UtilityVehicle.java new file mode 100644 index 0000000..0591510 --- /dev/null +++ b/src/CarInventorySystem/UtilityVehicle.java @@ -0,0 +1,26 @@ +package CarInventorySystem; + +public class UtilityVehicle extends Car { + + private boolean fourWheelDrive; + + public UtilityVehicle(String vinNumber, String make, String model, int mileage, boolean fourWheelDrive) { + super(vinNumber, make, model, mileage); + this.fourWheelDrive = fourWheelDrive; + } + + public boolean isFourWheelDrive() { + return fourWheelDrive; + } + + public void setFourWheelDrive(boolean fourWheelDrive) { + this.fourWheelDrive = fourWheelDrive; + } + + @Override + public String getInfo(){ + return ("🔢Vin:" + getVinNumber() + "\nMake:" + getMake() + "\nModel:" + getModel() + "\nMileage:" + getMileage() + " km" + "\n4WD" + fourWheelDrive ); + } + + +} diff --git a/src/IntListInterface/IntArrayList.java b/src/IntListInterface/IntArrayList.java new file mode 100644 index 0000000..252df96 --- /dev/null +++ b/src/IntListInterface/IntArrayList.java @@ -0,0 +1,33 @@ +package IntListInterface; + +public class IntArrayList implements IntList { + private int[] array; + private int size; + + public IntArrayList() { + this.array = new int[10]; + this.size = 0; + } + + @Override + public void add(int number) { + if (size == array.length) { + resize(array.length * 1.5); + } + array[size++] = number; + } + + @Override + public int get(int id) { + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException("Index: " + id + ", Size: " + size); + } + return array[id]; + } + + private void resize(double newSize) { + int[] newArray = new int[(int) newSize]; + System.arraycopy(array, 0, newArray, 0, size); + this.array = newArray; + } +} \ No newline at end of file diff --git a/src/IntListInterface/IntList.java b/src/IntListInterface/IntList.java new file mode 100644 index 0000000..4be9486 --- /dev/null +++ b/src/IntListInterface/IntList.java @@ -0,0 +1,6 @@ +package IntListInterface; + +public interface IntList { + void add(int number); + int get(int id); +} diff --git a/src/IntListInterface/IntListTest.java b/src/IntListInterface/IntListTest.java new file mode 100644 index 0000000..de8e2ee --- /dev/null +++ b/src/IntListInterface/IntListTest.java @@ -0,0 +1,38 @@ +package IntListInterface; + +public class IntListTest { + public static void main(String[] args) { + testIntArrayList(); + testIntVector(); + } + + private static void testIntArrayList() { + System.out.println("Testing IntArrayList:"); + IntList intArrayList = new IntArrayList(); + + // Adding elements + for (int i = 0; i < 50; i++) { + intArrayList.add(i); + } + + // Retrieving elements + for (int i = 0; i < 50; i++) { + System.out.println("Element at index " + i + ": " + intArrayList.get(i)); + } + } + + private static void testIntVector() { + System.out.println("\nTesting IntVector:"); + IntList intVector = new IntVector(); + + // Adding elements + for (int i = 0; i < 100; i++) { + intVector.add(i); + } + + // Retrieving elements + for (int i = 0; i < 100; i++) { + System.out.println("Element at index " + i + ": " + intVector.get(i)); + } + } +} \ No newline at end of file diff --git a/src/IntListInterface/IntVector.java b/src/IntListInterface/IntVector.java new file mode 100644 index 0000000..dd2c57d --- /dev/null +++ b/src/IntListInterface/IntVector.java @@ -0,0 +1,31 @@ +package IntListInterface; + +public class IntVector implements IntList { + private int[] array; + private int size; + + public IntVector() { + this.array = new int[20]; + this.size = 0; + } + + @Override + public void add(int number) { + if (size == array.length) { + resize(array.length * 2); + } + array[size++] = number; + } + @Override + public int get(int id) { + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException("Index: " + id + ", Size: " + size); + } + return array[id]; + } + private void resize(double newSize) { + int[] newArray = new int[(int)newSize]; + System.arraycopy(array, 0, newArray, 0, size); + this.array = newArray; + } +} diff --git a/src/IntListInterface/README.md b/src/IntListInterface/README.md new file mode 100644 index 0000000..d2d0ffc --- /dev/null +++ b/src/IntListInterface/README.md @@ -0,0 +1,14 @@ +# IntList Implementation Analysis + +## Efficiency Comparison: IntArrayList vs. IntVector + +This project includes two implementations of the `IntList` interface, each with a different strategy for resizing its internal array when it reaches capacity. + +### When is `IntArrayList` more efficient? +`IntArrayList` grows by **50%** of its current size when full. +* **Best Use Case:** It is more efficient in terms of **Memory (RAM) consumption**. It is ideal when you have limited memory resources or when you expect the list to grow, but at a slow, gradual, or predictable pace. Because it doesn't request massive blocks of memory at once, it prevents memory waste. + +### When is `IntVector` more efficient? +`IntVector` grows by **100%** (it doubles its size) when full. +* **Best Use Case:** It is more efficient in terms of **Processing Speed (CPU)** when dealing with massive amounts of data. Resizing an array (creating a new one and copying all elements over) is a heavy operation. By doubling in size, `IntVector` performs this costly operation much less frequently than `IntArrayList`. It trades memory space for faster execution times when rapidly adding many elements. + diff --git a/src/VideoStreamingService/AppVideoStreamingService.java b/src/VideoStreamingService/AppVideoStreamingService.java new file mode 100644 index 0000000..57d61e7 --- /dev/null +++ b/src/VideoStreamingService/AppVideoStreamingService.java @@ -0,0 +1,25 @@ +package VideoStreamingService; + +import java.util.ArrayList; +import java.util.List; + +public class AppVideoStreamingService { + public static void main(String[] args) { + System.out.println("~~~~~~VIDEO SUMMARY~~~~~~"); + List