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/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..f084c9f --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..36dda7f --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file 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..d6ebd48 --- /dev/null +++ b/.idea/lab-java-interfaces-and-abstract-classes.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..d1f2b79 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ 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..d14dff7 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,8 @@ Once you finish the assignment, submit a URL link to your repository or your pul ### BigDecimal Operations -1. Using the [BigDecimal documentation](https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html), create a method that accepts a `BigDecimal` and returns a `double` of the `BigDecimal` number rounded to the nearest hundredth. For example, `4.2545` should return `4.25`. -2. Using the [BigDecimal documentation](https://docs.oracle.com/javase/7/docs/api/java/math/BigDecimal.html), create a method that accepts a `BigDecimal`, reverses the sign (if the parameter is positive, the result should be negative and vice versa), rounds the number to the nearest tenth and returns the result. For example, `1.2345` should return `-1.2` and `-45.67` should return `45.7`. +1. Using the [BigDecimal documentation](https://docs.oracle.com/javase/7/docs/api/java/com.ironhack.math/BigDecimal.html), create a method that accepts a `BigDecimal` and returns a `double` of the `BigDecimal` number rounded to the nearest hundredth. For example, `4.2545` should return `4.25`. +2. Using the [BigDecimal documentation](https://docs.oracle.com/javase/7/docs/api/java/com.ironhack.math/BigDecimal.html), create a method that accepts a `BigDecimal`, reverses the sign (if the parameter is positive, the result should be negative and vice versa), rounds the number to the nearest tenth and returns the result. For example, `1.2345` should return `-1.2` and `-45.67` should return `45.7`.
@@ -117,7 +117,7 @@ Once you finish the assignment, submit a URL link to your repository or your pul Here's how you can use `BigDecimal` in a Java program: ```java - import java.math.BigDecimal; + import java.com.ironhack.math.BigDecimal; public class BigDecimalExample { public static void main(String[] args) { @@ -149,7 +149,7 @@ Once you finish the assignment, submit a URL link to your repository or your pul `setScale()` is used to set the scale of a `BigDecimal` object, which determines the number of decimal places to keep. For example: ```java - import java.math.BigDecimal; + import java.com.ironhack.math.BigDecimal; public class BigDecimalExample { public static void main(String[] args) { @@ -166,8 +166,8 @@ Once you finish the assignment, submit a URL link to your repository or your pul `RoundingMode` is an enumeration in Java that defines the different rounding modes that can be used with `BigDecimal`. For example: ```java - import java.math.BigDecimal; - import java.math.RoundingMode; + import java.com.ironhack.math.BigDecimal; + import java.com.ironhack.math.RoundingMode; public class BigDecimalExample { public static void main(String[] args) { @@ -184,7 +184,7 @@ Once you finish the assignment, submit a URL link to your repository or your pul `negate()` is used to negate the value of a `BigDecimal` object, converting a positive value to a negative and vice versa. For example: ```java - import java.math.BigDecimal; + import java.com.ironhack.math.BigDecimal; public class BigDecimalExample { public static void main(String[] args) { @@ -337,3 +337,7 @@ Once you finish the assignment, submit a URL link to your repository or your pul +Criterio IntArrayList (50%) IntVector (100%) +Uso de Memoria Más eficiente (ahorra espacio) Menos eficiente (desperdicia espacio) +Velocidad Más lenta en inserciones constantes Más rápida en inserciones constantes +Casos de uso Apps móviles o dispositivos embebidos Procesamiento de grandes volúmenes de datos \ No newline at end of file diff --git a/lab-solution3/pom.xml b/lab-solution3/pom.xml new file mode 100644 index 0000000..e51a8a6 --- /dev/null +++ b/lab-solution3/pom.xml @@ -0,0 +1,9 @@ + + 4.0.0 + org.example + lab-solution3 + 1.0-SNAPSHOT + Archetype - lab-solution3 + http://maven.apache.org + diff --git a/lab-solution3/src/main/java/Main.java b/lab-solution3/src/main/java/Main.java new file mode 100644 index 0000000..2c417e4 --- /dev/null +++ b/lab-solution3/src/main/java/Main.java @@ -0,0 +1,59 @@ +package com.ironhack; + +import java.math.BigDecimal; + +public class Main { + public static void main(String[] args) { + + // 1. Prueba de BigDecimal Operations + System.out.println("--- 1. BigDecimal Operations ---"); + BigDecimal testNum1 = new BigDecimal("4.2545"); + System.out.println("Original: 4.2545 | Redondeado (centésimas): " + + BigDecimalOperations.roundToHundredth(testNum1)); + + BigDecimal testNum2 = new BigDecimal("1.2345"); + BigDecimal testNum3 = new BigDecimal("-45.67"); + System.out.println("Original: 1.2345 | Invertido y Redondeado (décimas): " + + BigDecimalOperations.inverseAndRoundToTenth(testNum2)); + System.out.println("Original: -45.67 | Invertido y Redondeado (décimas): " + + BigDecimalOperations.inverseAndRoundToTenth(testNum3)); + System.out.println(); + + // 2. Prueba de Car Inventory System + System.out.println("--- 2. Car Inventory System ---"); + Car mySedan = new Sedan("ABC12345", "Toyota", "Corolla", 15000); + Car mySUV = new UtilityVehicle("XYZ67890", "Jeep", "Wrangler", 5000, true); + Car myTruck = new Truck("TRK999", "Ford", "F-150", 25000, 5000.5); + + System.out.println(mySedan.getInfo()); + System.out.println(mySUV.getInfo()); + System.out.println(myTruck.getInfo()); + System.out.println(); + + // 3. Prueba de Video Streaming Service + System.out.println("--- 3. Video Streaming Service ---"); + Video myMovie = new Movie("Inception", 148, 8.8); + Video mySeries = new TvSeries("The Bear", 30, 18); + + System.out.println(myMovie.getInfo()); + System.out.println(mySeries.getInfo()); + System.out.println(); + + // 4. Prueba de IntList Interface + System.out.println("--- 4. IntList System (Growth Test) ---"); + + IntList arrayList = new IntArrayList(); + System.out.println("Añadiendo 12 elementos a IntArrayList..."); + for (int i = 1; i <= 12; i++) { + arrayList.add(i * 10); + } + System.out.println("Elemento en índice 11: " + arrayList.get(11)); + + IntList vector = new IntVector(); + System.out.println("Añadiendo 22 elementos a IntVector..."); + for (int i = 1; i <= 22; i++) { + vector.add(i * 5); + } + System.out.println("Elemento en índice 21: " + vector.get(21)); + } +} \ No newline at end of file diff --git a/lab-solution3/src/main/java/com/ironhack/BigDecimalOperations.java b/lab-solution3/src/main/java/com/ironhack/BigDecimalOperations.java new file mode 100644 index 0000000..292eeef --- /dev/null +++ b/lab-solution3/src/main/java/com/ironhack/BigDecimalOperations.java @@ -0,0 +1,26 @@ +package com.ironhack; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +/** + * Operaciones de precisión con BigDecimal. + */ +public class BigDecimalOperations { + + /** + * Redondea a la centésima más cercana (2 decimales). + */ + public static double roundToHundredth(BigDecimal value) { + if (value == null) return 0.0; + return value.setScale(2, RoundingMode.HALF_UP).doubleValue(); + } + + /** + * Invierte el signo y redondea a la décima más cercana (1 decimal). + */ + public static BigDecimal inverseAndRoundToTenth(BigDecimal value) { + if (value == null) return BigDecimal.ZERO; + return value.negate().setScale(1, RoundingMode.HALF_UP); + } +} \ No newline at end of file diff --git a/lab-solution3/src/main/java/com/ironhack/Car.java b/lab-solution3/src/main/java/com/ironhack/Car.java new file mode 100644 index 0000000..28c2fe9 --- /dev/null +++ b/lab-solution3/src/main/java/com/ironhack/Car.java @@ -0,0 +1,66 @@ +package com.ironhack; + +/** + * Clase abstracta base para el inventario de coches. + */ +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 getInfo() { + return String.format("VIN: %s | Marca: %s | Modelo: %s | KM: %d", + vinNumber, make, model, mileage); + } +} + +/** + * Clase Sedan. + */ +class Sedan extends Car { + public Sedan(String vinNumber, String make, String model, int mileage) { + super(vinNumber, make, model, mileage); + } +} + +/** + * Clase UtilityVehicle con tracción 4x4. + */ +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; + } + + @Override + public String getInfo() { + return super.getInfo() + " | 4x4: " + (fourWheelDrive ? "Sí" : "No"); + } +} + +/** + * Clase Truck con capacidad de remolque. + */ +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; + } + + @Override + public String getInfo() { + return super.getInfo() + " | Capacidad Remolque: " + towingCapacity + " kg"; + } +} \ No newline at end of file diff --git a/lab-solution3/src/main/java/com/ironhack/IntList.java b/lab-solution3/src/main/java/com/ironhack/IntList.java new file mode 100644 index 0000000..6d67c8d --- /dev/null +++ b/lab-solution3/src/main/java/com/ironhack/IntList.java @@ -0,0 +1,52 @@ +package com.ironhack; + +import java.util.Arrays; + +/** + * Interfaz y sus implementaciones con estrategias de crecimiento. + */ +public interface IntList { + void add(int number); + int get(int id); +} + +class IntArrayList implements IntList { + private int[] array = new int[10]; + private int size = 0; + + @Override + public void add(int number) { + if (size == array.length) { + // Crecimiento del 50% + int newCapacity = array.length + (array.length / 2); + array = Arrays.copyOf(array, newCapacity); + } + array[size++] = number; + } + + @Override + public int get(int id) { + if (id < 0 || id >= size) throw new IndexOutOfBoundsException(); + return array[id]; + } +} + +class IntVector implements IntList { + private int[] array = new int[20]; + private int size = 0; + + @Override + public void add(int number) { + if (size == array.length) { + // Crecimiento del 100% (doble) + array = Arrays.copyOf(array, array.length * 2); + } + array[size++] = number; + } + + @Override + public int get(int id) { + if (id < 0 || id >= size) throw new IndexOutOfBoundsException(); + return array[id]; + } +} \ No newline at end of file diff --git a/lab-solution3/src/main/java/com/ironhack/Video.java b/lab-solution3/src/main/java/com/ironhack/Video.java new file mode 100644 index 0000000..ef46853 --- /dev/null +++ b/lab-solution3/src/main/java/com/ironhack/Video.java @@ -0,0 +1,47 @@ +package com.ironhack; + +/** + * Clase abstracta para servicios de video. + */ +public abstract class Video { + private String title; + private int duration; + + public Video(String title, int duration) { + this.title = title; + this.duration = duration; + } + + public abstract String getInfo(); + + public String getTitle() { return title; } + public int getDuration() { return duration; } +} + +class TvSeries extends Video { + private int episodes; + + public TvSeries(String title, int duration, int episodes) { + super(title, duration); + this.episodes = episodes; + } + + @Override + public String getInfo() { + return "Serie: " + getTitle() + " | Duración: " + getDuration() + "m | Episodios: " + episodes; + } +} + +class Movie extends Video { + private double rating; + + public Movie(String title, int duration, double rating) { + super(title, duration); + this.rating = rating; + } + + @Override + public String getInfo() { + return "Película: " + getTitle() + " | Duración: " + getDuration() + "m | Rating: " + rating + "/10"; + } +} \ No newline at end of file diff --git a/lab-solution3/src/main/resources/META-INF/maven/archetype.xml b/lab-solution3/src/main/resources/META-INF/maven/archetype.xml new file mode 100644 index 0000000..563f32a --- /dev/null +++ b/lab-solution3/src/main/resources/META-INF/maven/archetype.xml @@ -0,0 +1,9 @@ + + lab-solution3 + + src/main/java/App.java + + + src/test/java/AppTest.java + + diff --git a/lab-solution3/src/main/resources/archetype-resources/pom.xml b/lab-solution3/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000..d984103 --- /dev/null +++ b/lab-solution3/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,15 @@ + + 4.0.0 + $org.example + $lab-solution3 + $1.0-SNAPSHOT + + + junit + junit + 3.8.1 + test + + + diff --git a/lab-solution3/src/main/resources/archetype-resources/src/main/java/App.java b/lab-solution3/src/main/resources/archetype-resources/src/main/java/App.java new file mode 100644 index 0000000..1fa6a95 --- /dev/null +++ b/lab-solution3/src/main/resources/archetype-resources/src/main/java/App.java @@ -0,0 +1,13 @@ +package $org.example; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/lab-solution3/src/main/resources/archetype-resources/src/test/java/AppTest.java b/lab-solution3/src/main/resources/archetype-resources/src/test/java/AppTest.java new file mode 100644 index 0000000..65be417 --- /dev/null +++ b/lab-solution3/src/main/resources/archetype-resources/src/test/java/AppTest.java @@ -0,0 +1,38 @@ +package $org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/lab-solution3/target/classes/META-INF/maven/archetype.xml b/lab-solution3/target/classes/META-INF/maven/archetype.xml new file mode 100644 index 0000000..563f32a --- /dev/null +++ b/lab-solution3/target/classes/META-INF/maven/archetype.xml @@ -0,0 +1,9 @@ + + lab-solution3 + + src/main/java/App.java + + + src/test/java/AppTest.java + + diff --git a/lab-solution3/target/classes/archetype-resources/pom.xml b/lab-solution3/target/classes/archetype-resources/pom.xml new file mode 100644 index 0000000..d984103 --- /dev/null +++ b/lab-solution3/target/classes/archetype-resources/pom.xml @@ -0,0 +1,15 @@ + + 4.0.0 + $org.example + $lab-solution3 + $1.0-SNAPSHOT + + + junit + junit + 3.8.1 + test + + + diff --git a/lab-solution3/target/classes/archetype-resources/src/main/java/App.java b/lab-solution3/target/classes/archetype-resources/src/main/java/App.java new file mode 100644 index 0000000..1fa6a95 --- /dev/null +++ b/lab-solution3/target/classes/archetype-resources/src/main/java/App.java @@ -0,0 +1,13 @@ +package $org.example; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/lab-solution3/target/classes/archetype-resources/src/test/java/AppTest.java b/lab-solution3/target/classes/archetype-resources/src/test/java/AppTest.java new file mode 100644 index 0000000..65be417 --- /dev/null +++ b/lab-solution3/target/classes/archetype-resources/src/test/java/AppTest.java @@ -0,0 +1,38 @@ +package $org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/lab-solution3/target/classes/com/ironhack/BigDecimalOperations.class b/lab-solution3/target/classes/com/ironhack/BigDecimalOperations.class new file mode 100644 index 0000000..b419ff8 Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/BigDecimalOperations.class differ diff --git a/lab-solution3/target/classes/com/ironhack/Car.class b/lab-solution3/target/classes/com/ironhack/Car.class new file mode 100644 index 0000000..bc52eef Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/Car.class differ diff --git a/lab-solution3/target/classes/com/ironhack/IntArrayList.class b/lab-solution3/target/classes/com/ironhack/IntArrayList.class new file mode 100644 index 0000000..ff5492d Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/IntArrayList.class differ diff --git a/lab-solution3/target/classes/com/ironhack/IntList.class b/lab-solution3/target/classes/com/ironhack/IntList.class new file mode 100644 index 0000000..780d812 Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/IntList.class differ diff --git a/lab-solution3/target/classes/com/ironhack/IntVector.class b/lab-solution3/target/classes/com/ironhack/IntVector.class new file mode 100644 index 0000000..6ff4eeb Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/IntVector.class differ diff --git a/lab-solution3/target/classes/com/ironhack/Main.class b/lab-solution3/target/classes/com/ironhack/Main.class new file mode 100644 index 0000000..60f1194 Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/Main.class differ diff --git a/lab-solution3/target/classes/com/ironhack/Movie.class b/lab-solution3/target/classes/com/ironhack/Movie.class new file mode 100644 index 0000000..b0885fd Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/Movie.class differ diff --git a/lab-solution3/target/classes/com/ironhack/Sedan.class b/lab-solution3/target/classes/com/ironhack/Sedan.class new file mode 100644 index 0000000..118cb8b Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/Sedan.class differ diff --git a/lab-solution3/target/classes/com/ironhack/Truck.class b/lab-solution3/target/classes/com/ironhack/Truck.class new file mode 100644 index 0000000..751af5d Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/Truck.class differ diff --git a/lab-solution3/target/classes/com/ironhack/TvSeries.class b/lab-solution3/target/classes/com/ironhack/TvSeries.class new file mode 100644 index 0000000..6ce6965 Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/TvSeries.class differ diff --git a/lab-solution3/target/classes/com/ironhack/UtilityVehicle.class b/lab-solution3/target/classes/com/ironhack/UtilityVehicle.class new file mode 100644 index 0000000..95a10ad Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/UtilityVehicle.class differ diff --git a/lab-solution3/target/classes/com/ironhack/Video.class b/lab-solution3/target/classes/com/ironhack/Video.class new file mode 100644 index 0000000..ccdb3f7 Binary files /dev/null and b/lab-solution3/target/classes/com/ironhack/Video.class differ