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..901b2f1 --- /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..35eb1dd --- /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..e33ad0f 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,14 @@ Once you finish the assignment, submit a URL link to your repository or your pul 4. `IntVector` should store numbers in an array with a length of 20 by default. When the `add` method is called, you must first determine if the array is full. If it is, create a new array that is double the size of the current array, move all elements over to the new array and add the new element. (For example, an array of length 10 would be increased to 20.) 5. In your `README.md`, include an example of when `IntArrayList` would be more efficient and when `IntVector` would be more efficient. +## IntArrayList vs IntVector Efficiency + +- IntArrayList: +- Esta opcion es más eficiente cuando es importante el uso de la memoria y no se espera un crecimiento muy frecuente de la lista + +- IntVector: +- Por otro lado, esta opcion es más práctica cuando se piensa añadir elementos con frecuencia +
## FAQs diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/Main.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/Main.class new file mode 100644 index 0000000..63bcfd0 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/Main.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise1/BigDecimalOperations.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise1/BigDecimalOperations.class new file mode 100644 index 0000000..8806edf Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise1/BigDecimalOperations.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/Car.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/Car.class new file mode 100644 index 0000000..50216b2 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/Car.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/Sedan.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/Sedan.class new file mode 100644 index 0000000..be311bc Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/Sedan.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/Truck.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/Truck.class new file mode 100644 index 0000000..347196f Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/Truck.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/UtilityVehicle.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/UtilityVehicle.class new file mode 100644 index 0000000..43213f5 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise2/UtilityVehicle.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise3/Movie.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise3/Movie.class new file mode 100644 index 0000000..a5d5264 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise3/Movie.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise3/TvSeries.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise3/TvSeries.class new file mode 100644 index 0000000..41faf6b Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise3/TvSeries.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise3/Video.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise3/Video.class new file mode 100644 index 0000000..b015096 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise3/Video.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise4/IntArrayList.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise4/IntArrayList.class new file mode 100644 index 0000000..6554ed3 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise4/IntArrayList.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise4/IntList.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise4/IntList.class new file mode 100644 index 0000000..77f6bc5 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise4/IntList.class differ diff --git a/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise4/IntVector.class b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise4/IntVector.class new file mode 100644 index 0000000..0d212f2 Binary files /dev/null and b/out/production/lab-java-interfaces-and-abstract-classes/com/ironhack/lab/exercise4/IntVector.class differ diff --git a/src/com/ironhack/lab/Main.java b/src/com/ironhack/lab/Main.java new file mode 100644 index 0000000..1d7fd03 --- /dev/null +++ b/src/com/ironhack/lab/Main.java @@ -0,0 +1,67 @@ +package com.ironhack.lab; + +import com.ironhack.lab.exercise1.BigDecimalOperations; +import com.ironhack.lab.exercise2.Sedan; +import com.ironhack.lab.exercise2.Truck; +import com.ironhack.lab.exercise2.UtilityVehicle; +import com.ironhack.lab.exercise3.TvSeries; +import com.ironhack.lab.exercise3.Movie; +import com.ironhack.lab.exercise4.IntArrayList; +import com.ironhack.lab.exercise4.IntVector; + +import java.math.BigDecimal; + +public class Main { + public static void main(String[] args){ + System.out.println("Iniciando lab sem 3"); + + //Creando un Bigdecimal + BigDecimal value = new BigDecimal("2.4532"); + + + System.out.println("The value in exercise 1 is: " + BigDecimalOperations.roundBigDecimalToDouble(value)); + System.out.println("The value in exercise 2 is: " + BigDecimalOperations.negateAndRound (value)); + + System.out.println("=== Car Inventory Test ==="); + + // Sedan + Sedan sedan = new Sedan("VIN001", "Toyota", "Corolla", 30000); + System.out.println(sedan.getInfo()); + + // UtilityVehicle + UtilityVehicle uv = new UtilityVehicle("VIN002", "Jeep", "Wrangler", 40000, true); + System.out.println(uv.getInfo()); + + // Truck + Truck truck = new Truck("VIN003", "Ford", "F-150", 50000, 3500.5); + System.out.println(truck.getInfo()); + + System.out.println("=== Video Test ==="); + + TvSeries series = new TvSeries("Breaking Bad", 50, 62); + Movie movie = new Movie("Inception", 148, 8.8); + + System.out.println(series.getInfo()); + System.out.println(movie.getInfo()); + + System.out.println("=== IntList Test ==="); + + IntArrayList arrayList = new IntArrayList(); + arrayList.add(10); + arrayList.add(20); + arrayList.add(30); + + System.out.println("IntArrayList element at index 0: " + arrayList.get(0)); + System.out.println("IntArrayList element at index 1: " + arrayList.get(1)); + System.out.println("IntArrayList element at index 2: " + arrayList.get(2)); + + IntVector vector = new IntVector(); + vector.add(100); + vector.add(200); + vector.add(300); + + System.out.println("IntVector element at index 0: " + vector.get(0)); + System.out.println("IntVector element at index 1: " + vector.get(1)); + System.out.println("IntVector element at index 2: " + vector.get(2)); + } +} diff --git a/src/com/ironhack/lab/exercise1/BigDecimalOperations.java b/src/com/ironhack/lab/exercise1/BigDecimalOperations.java new file mode 100644 index 0000000..48ef708 --- /dev/null +++ b/src/com/ironhack/lab/exercise1/BigDecimalOperations.java @@ -0,0 +1,19 @@ +package com.ironhack.lab.exercise1; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class BigDecimalOperations { + + //Ejercicio 1 redondear un Bigdecimal y convertirlo en bouble + public static double roundBigDecimalToDouble(BigDecimal number){ + BigDecimal roundToTwoDecimals = number.setScale(2, RoundingMode.HALF_UP); + return roundToTwoDecimals.doubleValue(); + } + + //Ejercicio 2 Invertir signo y redondear la decima más cercana + public static BigDecimal negateAndRound(BigDecimal number){ + BigDecimal invertedNumber = number.negate(); + return invertedNumber.setScale(1, RoundingMode.HALF_UP ); + } +} diff --git a/src/com/ironhack/lab/exercise2/Car.java b/src/com/ironhack/lab/exercise2/Car.java new file mode 100644 index 0000000..0f379e8 --- /dev/null +++ b/src/com/ironhack/lab/exercise2/Car.java @@ -0,0 +1,52 @@ +package com.ironhack.lab.exercise2; + + //Clase abstracta para los modelos de coche + public abstract class Car{ + private String vinNumber; + private String make; + private String model; + private int mileage; + + //Cpnstructor de la clase abtracta Car + + public Car(String vinNumber, String make, String model, int mileage) { + this.vinNumber = vinNumber; + this.make = make; + this.model = model; + this.mileage = mileage; + } + + //Metodo getInfo + public String getInfo() { + return "VIN Number: " + vinNumber + + ", Make: " + make + + ", Model: " + model + + ", Mileage: " + mileage; + } + //Getters de la clase + + public String getVinNumber() { + return vinNumber; + } + + public String getMake() { + return make; + } + + public String getModel() { + return model; + } + + public int getMileage() { + return mileage; + } + + //toString() + + @Override + public String toString() { + return getInfo(); + } + } + + diff --git a/src/com/ironhack/lab/exercise2/Sedan.java b/src/com/ironhack/lab/exercise2/Sedan.java new file mode 100644 index 0000000..777295b --- /dev/null +++ b/src/com/ironhack/lab/exercise2/Sedan.java @@ -0,0 +1,8 @@ +package com.ironhack.lab.exercise2; + +public class Sedan extends Car { + + public Sedan(String vinNumber, String make, String model, int mileage) { + super(vinNumber, make, model, mileage); + } +} diff --git a/src/com/ironhack/lab/exercise2/Truck.java b/src/com/ironhack/lab/exercise2/Truck.java new file mode 100644 index 0000000..9415f8d --- /dev/null +++ b/src/com/ironhack/lab/exercise2/Truck.java @@ -0,0 +1,22 @@ +package com.ironhack.lab.exercise2; + +public class Truck extends Car { + private double towingCapacity; + + //Constructor + + public Truck(String vinNumber, String make, String model, int mileage, double towingCapacity) { + super(vinNumber, make, model, mileage); + this.towingCapacity = towingCapacity; + } + + //Getters de la clase + public double getTowingCapacity() { + return towingCapacity; + } + + @Override + public String getInfo() { + return super.getInfo() + ", Towing Capacity: " + towingCapacity; + } +} diff --git a/src/com/ironhack/lab/exercise2/UtilityVehicle.java b/src/com/ironhack/lab/exercise2/UtilityVehicle.java new file mode 100644 index 0000000..fa296bd --- /dev/null +++ b/src/com/ironhack/lab/exercise2/UtilityVehicle.java @@ -0,0 +1,23 @@ +package com.ironhack.lab.exercise2; + +public class UtilityVehicle extends Car { + private boolean fourWheelDrive; + + //Constructor + + public UtilityVehicle(String vinNumber, String make, String model, int mileage, boolean fourWheelDrive) { + super(vinNumber, make, model, mileage); + this.fourWheelDrive = fourWheelDrive; + } + + //Getters de la clase + + public boolean isFourWheelDrive() { + return fourWheelDrive; + } + + @Override + public String getInfo() { + return super.getInfo() + ", Four Wheel Drive: " + fourWheelDrive; + } +} diff --git a/src/com/ironhack/lab/exercise3/Movie.java b/src/com/ironhack/lab/exercise3/Movie.java new file mode 100644 index 0000000..e59d665 --- /dev/null +++ b/src/com/ironhack/lab/exercise3/Movie.java @@ -0,0 +1,19 @@ +package com.ironhack.lab.exercise3; + +public class Movie extends Video{ + private double rating; + + public Movie(String title, int duration, double rating) { + super(title, duration); + this.rating = rating; + } + + public double getRating() { + return rating; + } + + @Override + public String getInfo() { + return super.getInfo() + ", Rating: " + rating; + } +} diff --git a/src/com/ironhack/lab/exercise3/TvSeries.java b/src/com/ironhack/lab/exercise3/TvSeries.java new file mode 100644 index 0000000..8200df6 --- /dev/null +++ b/src/com/ironhack/lab/exercise3/TvSeries.java @@ -0,0 +1,19 @@ +package com.ironhack.lab.exercise3; + +public class TvSeries extends Video { + private int episodes; + + public TvSeries(String title, int duration, int episodes) { + super(title, duration); + this.episodes = episodes; + } + + public int getEpisodes() { + return episodes; + } + + @Override + public String getInfo() { + return super.getInfo() + ", Episodes: " + episodes; + } +} diff --git a/src/com/ironhack/lab/exercise3/Video.java b/src/com/ironhack/lab/exercise3/Video.java new file mode 100644 index 0000000..7723775 --- /dev/null +++ b/src/com/ironhack/lab/exercise3/Video.java @@ -0,0 +1,30 @@ +package com.ironhack.lab.exercise3; + +public abstract class Video { + private String title; + private int duration; + + public Video(String title, int duration) { + this.title = title; + this.duration = duration; + } + + //Metodo getInfo + public String getInfo() { + return "Title: " + title + + ", Duration: " + duration; + } + + public String getTitle() { + return title; + } + + public int getDuration() { + return duration; + } + + @Override + public String toString() { + return getInfo(); + } +} diff --git a/src/com/ironhack/lab/exercise4/IntArrayList.java b/src/com/ironhack/lab/exercise4/IntArrayList.java new file mode 100644 index 0000000..fa41f35 --- /dev/null +++ b/src/com/ironhack/lab/exercise4/IntArrayList.java @@ -0,0 +1,38 @@ +package com.ironhack.lab.exercise4; + +public class IntArrayList implements IntList { + + private int[] data; + private int size; + + public IntArrayList() { + this.data = new int[10]; + this.size = 0; + } + + @Override + public void add(int number) { + if (size == data.length) { + int newLength = data.length + data.length / 2; + int[] newData = new int[newLength]; + + for (int i = 0; i < data.length; i++) { + newData[i] = data[i]; + } + + data = newData; + } + + data[size] = number; + size++; + } + + @Override + public int get(int id) { + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException("Invalid index: " + id); + } + + return data[id]; + } +} \ No newline at end of file diff --git a/src/com/ironhack/lab/exercise4/IntList.java b/src/com/ironhack/lab/exercise4/IntList.java new file mode 100644 index 0000000..3f96329 --- /dev/null +++ b/src/com/ironhack/lab/exercise4/IntList.java @@ -0,0 +1,6 @@ +package com.ironhack.lab.exercise4; + +public interface IntList { + void add(int number); + int get(int id); +} \ No newline at end of file diff --git a/src/com/ironhack/lab/exercise4/IntVector.java b/src/com/ironhack/lab/exercise4/IntVector.java new file mode 100644 index 0000000..bb26093 --- /dev/null +++ b/src/com/ironhack/lab/exercise4/IntVector.java @@ -0,0 +1,38 @@ +package com.ironhack.lab.exercise4; + +public class IntVector implements IntList { + + private int[] data; + private int size; + + public IntVector() { + this.data = new int[20]; + this.size = 0; + } + + @Override + public void add(int number) { + if (size == data.length) { + int newLength = data.length * 2; + int[] newData = new int[newLength]; + + for (int i = 0; i < data.length; i++) { + newData[i] = data[i]; + } + + data = newData; + } + + data[size] = number; + size++; + } + + @Override + public int get(int id) { + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException("Invalid index: " + id); + } + + return data[id]; + } +} \ No newline at end of file