From 63580de34c5a7fd7a546f2f138ef4dd6527c3c75 Mon Sep 17 00:00:00 2001 From: Francisco Jose Diaz Pereira Date: Sat, 13 Apr 2024 15:10:56 +0200 Subject: [PATCH] Pull request --- Lab_1.08/Lab_1.08.iml | 11 +++ .../src/InterfazIntList/IntArrayList.java | 32 +++++++ Lab_1.08/src/InterfazIntList/IntList.java | 7 ++ Lab_1.08/src/InterfazIntList/IntVector.java | 31 +++++++ Lab_1.08/src/Main.java | 93 +++++++++++++++++++ Lab_1.08/src/automoviles/Car.java | 31 +++++++ Lab_1.08/src/automoviles/Sedan.java | 12 +++ Lab_1.08/src/automoviles/Truck.java | 16 ++++ Lab_1.08/src/automoviles/UtilityVehicle.java | 16 ++++ Lab_1.08/src/transmisionVideo/Movie.java | 14 +++ Lab_1.08/src/transmisionVideo/TvSeries.java | 15 +++ Lab_1.08/src/transmisionVideo/Video.java | 20 ++++ 12 files changed, 298 insertions(+) create mode 100644 Lab_1.08/Lab_1.08.iml create mode 100644 Lab_1.08/src/InterfazIntList/IntArrayList.java create mode 100644 Lab_1.08/src/InterfazIntList/IntList.java create mode 100644 Lab_1.08/src/InterfazIntList/IntVector.java create mode 100644 Lab_1.08/src/Main.java create mode 100644 Lab_1.08/src/automoviles/Car.java create mode 100644 Lab_1.08/src/automoviles/Sedan.java create mode 100644 Lab_1.08/src/automoviles/Truck.java create mode 100644 Lab_1.08/src/automoviles/UtilityVehicle.java create mode 100644 Lab_1.08/src/transmisionVideo/Movie.java create mode 100644 Lab_1.08/src/transmisionVideo/TvSeries.java create mode 100644 Lab_1.08/src/transmisionVideo/Video.java diff --git a/Lab_1.08/Lab_1.08.iml b/Lab_1.08/Lab_1.08.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Lab_1.08/Lab_1.08.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Lab_1.08/src/InterfazIntList/IntArrayList.java b/Lab_1.08/src/InterfazIntList/IntArrayList.java new file mode 100644 index 0000000..b55389c --- /dev/null +++ b/Lab_1.08/src/InterfazIntList/IntArrayList.java @@ -0,0 +1,32 @@ +package InterfazIntList; + +public class IntArrayList implements IntList { + private int[] array; + private int size; + + public IntArrayList() { + array = new int[10]; + size = 0; + } + + + @Override + public void add(int number) { + if (size == array.length) { + + int newSize = array.length + array.length / 2; + int[] newArray = new int[newSize]; + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; + } + array[size++] = number; + } + + @Override + public int get(int id) { + if (id >= 0 && id < size) { + return array[id]; + } + throw new IndexOutOfBoundsException("ID fuera de rango"); + } +} diff --git a/Lab_1.08/src/InterfazIntList/IntList.java b/Lab_1.08/src/InterfazIntList/IntList.java new file mode 100644 index 0000000..c066a51 --- /dev/null +++ b/Lab_1.08/src/InterfazIntList/IntList.java @@ -0,0 +1,7 @@ +package InterfazIntList; + +public interface IntList { + void add(int number); + int get(int id); +} + diff --git a/Lab_1.08/src/InterfazIntList/IntVector.java b/Lab_1.08/src/InterfazIntList/IntVector.java new file mode 100644 index 0000000..55904d6 --- /dev/null +++ b/Lab_1.08/src/InterfazIntList/IntVector.java @@ -0,0 +1,31 @@ +package InterfazIntList; + +public class IntVector implements IntList { + private int[] array; + private int size; + + public IntVector() { + array = new int[20]; + size = 0; + } + + + @Override + public void add(int number) { + if (size == array.length) { + int newSize = array.length * 2; + int[] newArray = new int[newSize]; + System.arraycopy(array, 0, newArray, 0, size); + array = newArray; + } + array[size++] = number; + } + + @Override + public int get(int id) { + if (id >= 0 && id < size) { + return array[id]; + } + throw new IndexOutOfBoundsException("ID fuera de rango"); + } +} \ No newline at end of file diff --git a/Lab_1.08/src/Main.java b/Lab_1.08/src/Main.java new file mode 100644 index 0000000..07d93f4 --- /dev/null +++ b/Lab_1.08/src/Main.java @@ -0,0 +1,93 @@ +import InterfazIntList.IntArrayList; +import InterfazIntList.IntList; +import InterfazIntList.IntVector; +import automoviles.Sedan; +import automoviles.Truck; +import automoviles.UtilityVehicle; +import transmisionVideo.Movie; +import transmisionVideo.TvSeries; + +import java.math.BigDecimal; +import java.math.RoundingMode; +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + System.out.println("------BIG DECIMAL------"); + //OPERACIONES BIG DECIMAL + operacionesBigDecimal(); + + System.out.println("-----------"); + System.out.println("------INVENTARIO DE AUTOMOVILES------"); + //SISTEMA DE INVENTARIO DE AUTOMOVILE + inventarioDeAutomoviles(); + + System.out.println("-----------"); + System.out.println("------TRANSMISION DE VIDEO------"); + //SERVICIO DE TRANSMICION DE VIDEO + transmisionDeVideo(); + + System.out.println("-----------"); + System.out.println("------INTERFAZ INT LIST------"); + //INTERFAZ INTLIST + + interfazIntList(); + } + + private static void operacionesBigDecimal() { + BigDecimal num1 = new BigDecimal("8.73782"); + BigDecimal num2 = new BigDecimal("2.32345"); + BigDecimal num3 = new BigDecimal("-5.6327"); + + System.out.println("Redondeo de \"8.73782\": " + redondearAlCentesimo(num1)); + System.out.println("Redondeo de \"2.32345\": " + redondearAlCentesimo(num2)); + System.out.println("Redondeo de \"-5.6327\": " + redondearAlCentesimo(num3)); + + + BigDecimal num4 = new BigDecimal("32.7673"); + BigDecimal num5 = new BigDecimal("-4.2127"); + + System.out.println("Resultado de invertir y redondear \"32.7673\": " + invertirYRedondear(num4)); + System.out.println("Resultado de invertir y redondear \"-4.2127\": " + invertirYRedondear(num5)); + } + + public static double redondearAlCentesimo(BigDecimal numero) { + BigDecimal redondeado = numero.setScale(2, RoundingMode.HALF_UP); + return redondeado.doubleValue();} + + public static BigDecimal invertirYRedondear(BigDecimal numero) { + BigDecimal invertido = numero.negate(); + return invertido.setScale(1, RoundingMode.HALF_UP); + + } + + private static void inventarioDeAutomoviles() { + Sedan sedan = new Sedan("123456", "Toyota", "Camry", 50000); + UtilityVehicle utilityVehicle = new UtilityVehicle("789012", "Jeep", "Wrangler", 75000, true); + Truck truck = new Truck("345678", "Ford", "F-150", 100000, 12000.0); + + System.out.println(sedan.getInfo()); + System.out.println(utilityVehicle.getInfo()); + System.out.println(truck.getInfo()); + } + + private static void transmisionDeVideo() { + TvSeries gotSeries = new TvSeries("Game of Thrones", 60, 73); + Movie inceptionMovie = new Movie("Inception", 148, 8.8); + + System.out.println(gotSeries.getInfo()); + System.out.println(inceptionMovie.getInfo()); + } + + private static void interfazIntList() { + IntList list1 = new IntArrayList(); + list1.add(5); + list1.add(10); + System.out.println("Elemento en ID 1 (IntArrayList): " + list1.get(1)); + + IntList list2 = new IntVector(); + list2.add(15); + list2.add(20); + System.out.println("Elemento en ID 1 (IntVector): " + list2.get(1)); + } +} \ No newline at end of file diff --git a/Lab_1.08/src/automoviles/Car.java b/Lab_1.08/src/automoviles/Car.java new file mode 100644 index 0000000..1062a58 --- /dev/null +++ b/Lab_1.08/src/automoviles/Car.java @@ -0,0 +1,31 @@ +package automoviles; + +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 abstract String getInfo(); + public String getVinNumber() { + return vinNumber; + } + + public String getMake() { + return make; + } + + public String getModel() { + return model; + } + + public int getMileage() { + return mileage; + } +} diff --git a/Lab_1.08/src/automoviles/Sedan.java b/Lab_1.08/src/automoviles/Sedan.java new file mode 100644 index 0000000..f333d7f --- /dev/null +++ b/Lab_1.08/src/automoviles/Sedan.java @@ -0,0 +1,12 @@ +package automoviles; + +public class Sedan extends Car{ + public Sedan(String vinNumber, String make, String model, int mileage) { + super(vinNumber, make, model, mileage); + } + + @Override + public String getInfo() { + return "Sedan: VIN " + getVinNumber() + ", Make: " + getMake() + ", Model: " + getModel() + ", Mileage: " + getMileage(); + } +} diff --git a/Lab_1.08/src/automoviles/Truck.java b/Lab_1.08/src/automoviles/Truck.java new file mode 100644 index 0000000..a6cab41 --- /dev/null +++ b/Lab_1.08/src/automoviles/Truck.java @@ -0,0 +1,16 @@ +package automoviles; + +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; + } + + @Override + public String getInfo() { + return "Truck: VIN " + getVinNumber() + ", Make: " + getMake() + ", Model: " + getModel() + + ", Mileage: " + getMileage() + ", Towing Capacity: " + towingCapacity + " lbs"; + } +} diff --git a/Lab_1.08/src/automoviles/UtilityVehicle.java b/Lab_1.08/src/automoviles/UtilityVehicle.java new file mode 100644 index 0000000..f16ae1f --- /dev/null +++ b/Lab_1.08/src/automoviles/UtilityVehicle.java @@ -0,0 +1,16 @@ +package automoviles; + +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; + } + + @Override + public String getInfo() { + return "Utility Vehicle: VIN " + getVinNumber() + ", Make: " + getMake() + ", Model: " + getModel() + + ", Mileage: " + getMileage() + ", 4WD: " + (fourWheelDrive ? "Yes" : "No"); + } +} diff --git a/Lab_1.08/src/transmisionVideo/Movie.java b/Lab_1.08/src/transmisionVideo/Movie.java new file mode 100644 index 0000000..82c57f3 --- /dev/null +++ b/Lab_1.08/src/transmisionVideo/Movie.java @@ -0,0 +1,14 @@ +package transmisionVideo; + +public 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 "Movie: " + getTitle() + " (Duration: " + getDuration() + " min, Rating: " + rating + ")"; + } +} diff --git a/Lab_1.08/src/transmisionVideo/TvSeries.java b/Lab_1.08/src/transmisionVideo/TvSeries.java new file mode 100644 index 0000000..da4af4e --- /dev/null +++ b/Lab_1.08/src/transmisionVideo/TvSeries.java @@ -0,0 +1,15 @@ +package transmisionVideo; + +public 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 "TV Series: " + getTitle() + " (Duration: " + getDuration() + " min, " + episodes + " episodes)"; + } +} diff --git a/Lab_1.08/src/transmisionVideo/Video.java b/Lab_1.08/src/transmisionVideo/Video.java new file mode 100644 index 0000000..caae44f --- /dev/null +++ b/Lab_1.08/src/transmisionVideo/Video.java @@ -0,0 +1,20 @@ +package transmisionVideo; + +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; + } +}