From dc5962739db294fb696d6b2b3eeb9983dc07364b Mon Sep 17 00:00:00 2001 From: juangarcia15525 Date: Fri, 10 Apr 2026 17:08:03 +0200 Subject: [PATCH 1/2] Add files via upload --- BigDecimalOperations.java | 14 ++++++++++ Car.java | 36 +++++++++++++++++++++++++ IntArrayList.java | 42 +++++++++++++++++++++++++++++ IntList.java | 4 +++ IntVector.java | 34 +++++++++++++++++++++++ Main.java | 57 +++++++++++++++++++++++++++++++++++++++ Movie.java | 17 ++++++++++++ Sedan.java | 6 +++++ Truck.java | 17 ++++++++++++ TvSeries.java | 17 ++++++++++++ UtilityVehicle.java | 17 ++++++++++++ 11 files changed, 261 insertions(+) create mode 100644 BigDecimalOperations.java create mode 100644 Car.java create mode 100644 IntArrayList.java create mode 100644 IntList.java create mode 100644 IntVector.java create mode 100644 Main.java create mode 100644 Movie.java create mode 100644 Sedan.java create mode 100644 Truck.java create mode 100644 TvSeries.java create mode 100644 UtilityVehicle.java diff --git a/BigDecimalOperations.java b/BigDecimalOperations.java new file mode 100644 index 0000000..809476c --- /dev/null +++ b/BigDecimalOperations.java @@ -0,0 +1,14 @@ +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class BigDecimalOperations { + + public static double roundToNearestHundredth(BigDecimal number) { + return number.setScale(2, RoundingMode.HALF_UP).doubleValue(); + } + + public static double reverseSignAndRoundToNearestTenth(BigDecimal number) { + BigDecimal reversed = number.negate(); + return reversed.setScale(1, RoundingMode.HALF_UP).doubleValue(); + } +} \ No newline at end of file diff --git a/Car.java b/Car.java new file mode 100644 index 0000000..116a9e4 --- /dev/null +++ b/Car.java @@ -0,0 +1,36 @@ +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 String getMake() { + return make; + } + + public String getModel() { + return model; + } + + public int getMileage() { + return mileage; + } + + public String getInfo() { + return "VIN: " + vinNumber + + ", Make: " + make + + ", Model: " + model + + ", Mileage: " + mileage; + } +} \ No newline at end of file diff --git a/IntArrayList.java b/IntArrayList.java new file mode 100644 index 0000000..36f82b0 --- /dev/null +++ b/IntArrayList.java @@ -0,0 +1,42 @@ +public class IntArrayList implements IntList { + + private int[] numbers; + private int size; + + public IntArrayList() { + numbers = new int[10]; // tamaño inicial 10 + size = 0; + } + + @Override + public void add(int number) { + + // Si el array está lleno, lo ampliamos un 50% + if (size == numbers.length) { + + int newLength = numbers.length + (numbers.length / 2); + int[] newArray = new int[newLength]; + + // Copiar elementos al nuevo array + for (int i = 0; i < numbers.length; i++) { + newArray[i] = numbers[i]; + } + + numbers = newArray; + } + + // Añadir el nuevo número + numbers[size] = number; + size++; + } + + @Override + public int get(int id) { + + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException("Índice fuera de rango"); + } + + return numbers[id]; + } +} diff --git a/IntList.java b/IntList.java new file mode 100644 index 0000000..5f800aa --- /dev/null +++ b/IntList.java @@ -0,0 +1,4 @@ +public interface IntList { + void add(int number); + int get(int id); +} \ No newline at end of file diff --git a/IntVector.java b/IntVector.java new file mode 100644 index 0000000..e227ac4 --- /dev/null +++ b/IntVector.java @@ -0,0 +1,34 @@ +public class IntVector implements IntList { + private int[] numbers; + private int size; + + public IntVector() { + numbers = new int[20]; + size = 0; + } + + @Override + public void add(int number) { + if (size == numbers.length) { + int newLength = numbers.length * 2; + int[] newArray = new int[newLength]; + + for (int i = 0; i < numbers.length; i++) { + newArray[i] = numbers[i]; + } + + numbers = newArray; + } + + numbers[size] = number; + size++; + } + + @Override + public int get(int id) { + if (id < 0 || id >= size) { + throw new IndexOutOfBoundsException("Índice fuera de rango"); + } + return numbers[id]; + } +} diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..22829fa --- /dev/null +++ b/Main.java @@ -0,0 +1,57 @@ +import java.math.BigDecimal; + +public class Main { + public static void main(String[] args) { + + System.out.println("=== BIGDECIMAL OPERATIONS ==="); + BigDecimal num1 = new BigDecimal("4.2545"); + BigDecimal num2 = new BigDecimal("1.2345"); + BigDecimal num3 = new BigDecimal("-45.67"); + + System.out.println("Rounded to nearest hundredth: " + + BigDecimalOperations.roundToNearestHundredth(num1)); + + System.out.println("Reverse sign and round to nearest tenth (1.2345): " + + BigDecimalOperations.reverseSignAndRoundToNearestTenth(num2)); + + System.out.println("Reverse sign and round to nearest tenth (-45.67): " + + BigDecimalOperations.reverseSignAndRoundToNearestTenth(num3)); + + System.out.println(); + System.out.println("=== CAR INVENTORY SYSTEM ==="); + + Car sedan = new Sedan("VIN001", "Toyota", "Corolla", 50000); + Car suv = new UtilityVehicle("VIN002", "Jeep", "Cherokee", 30000, true); + Car truck = new Truck("VIN003", "Ford", "F-150", 45000, 3500.5); + + System.out.println(sedan.getInfo()); + System.out.println(suv.getInfo()); + System.out.println(truck.getInfo()); + + System.out.println(); + System.out.println("=== VIDEO STREAMING SERVICE ==="); + + Video series = new TvSeries("Breaking Bad", 50, 62); + Video movie = new Movie("Inception", 148, 8.8); + + System.out.println(series.getInfo()); + System.out.println(movie.getInfo()); + + System.out.println(); + System.out.println("=== INTLIST INTERFACE ==="); + + IntList arrayList = new IntArrayList(); + IntList vector = new IntVector(); + + arrayList.add(10); + arrayList.add(20); + arrayList.add(30); + + vector.add(100); + vector.add(200); + vector.add(300); + + System.out.println("IntArrayList element at index 1: " + arrayList.get(1)); + System.out.println("IntVector element at index 2: " + vector.get(2)); + } +} \ No newline at end of file diff --git a/Movie.java b/Movie.java new file mode 100644 index 0000000..5024857 --- /dev/null +++ b/Movie.java @@ -0,0 +1,17 @@ +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; + } +} \ No newline at end of file diff --git a/Sedan.java b/Sedan.java new file mode 100644 index 0000000..3a23fd3 --- /dev/null +++ b/Sedan.java @@ -0,0 +1,6 @@ +public class Sedan extends Car { + + public Sedan(String vinNumber, String make, String model, int mileage) { + super(vinNumber, make, model, mileage); + } +} \ No newline at end of file diff --git a/Truck.java b/Truck.java new file mode 100644 index 0000000..5391600 --- /dev/null +++ b/Truck.java @@ -0,0 +1,17 @@ +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; + } + + @Override + public String getInfo() { + return super.getInfo() + ", Towing Capacity: " + towingCapacity; + } +} \ No newline at end of file diff --git a/TvSeries.java b/TvSeries.java new file mode 100644 index 0000000..3a256cf --- /dev/null +++ b/TvSeries.java @@ -0,0 +1,17 @@ +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; + } +} \ No newline at end of file diff --git a/UtilityVehicle.java b/UtilityVehicle.java new file mode 100644 index 0000000..14c65ea --- /dev/null +++ b/UtilityVehicle.java @@ -0,0 +1,17 @@ +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; + } + + @Override + public String getInfo() { + return super.getInfo() + ", Four Wheel Drive: " + fourWheelDrive; + } +} \ No newline at end of file From 21824ff900f1d5e8251845b59cd5a206fc4e375a Mon Sep 17 00:00:00 2001 From: juangarcia15525 Date: Fri, 10 Apr 2026 17:11:02 +0200 Subject: [PATCH 2/2] Add files via upload --- Video.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Video.java diff --git a/Video.java b/Video.java new file mode 100644 index 0000000..f2b1fdf --- /dev/null +++ b/Video.java @@ -0,0 +1,21 @@ +public abstract class Video { + private String title; + private int duration; + + public Video(String title, int duration) { + this.title = title; + this.duration = duration; + } + + public String getTitle() { + return title; + } + + public int getDuration() { + return duration; + } + + public String getInfo() { + return "Title: " + title + ", Duration: " + duration + " minutes"; + } +} \ No newline at end of file