Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/labs.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ Una vez que termines la tarea, envía un enlace URL a tu repositorio o tu solici

### Sistema de inventario de automóviles

1. Supongamos que estás construyendo un sistema de inventario de automóviles. Todos los automóviles tienen un `vinNumber`, `make`, `model` y `mileage`. Pero ningún automóvil es solo un automóvil cualquiera. Cada automóvil puede ser un `Sedan`, un `UtilityVehicle` o un `Truck`.
2. Crea una clase abstracta llamada `Car` y define las siguientes propiedades y comportamientos:
1. Supongamos que estás construyendo un sistema de inventario de automóviles. Todos los automóviles tienen un `vinNumber`, `make`, `model` y `mileage`. Pero ningún automóvil es solo un automóvil cualquiera. Cada automóvil puede ser un `vehicles.Sedan`, un `vehicles.UtilityVehicle` o un `vehicles.Truck`.
2. Crea una clase abstracta llamada `vehicles.Car` y define las siguientes propiedades y comportamientos:
- `vinNumber`: una `String` que representa el número de VIN del automóvil
- `make`: una `String` que representa la marca del automóvil
- `model`: una `String` que representa el modelo del automóvil
- `mileage`: un `int` que representa el kilometraje del automóvil
- `getInfo()`: un método que devuelve una `String` que contiene todas las propiedades del automóvil en un formato legible
3. Crea tres clases que extiendan `Car`: `Sedan`, `UtilityVehicle` y `Truck`.
4. Los objetos de `UtilityVehicle` deben tener una propiedad adicional `fourWheelDrive`, un `boolean` que representa si el vehículo tiene tracción en las cuatro ruedas.
5. Los objetos de `Truck` deben tener una propiedad adicional `towingCapacity`, un `double` que representa la capacidad de remolque del camión.
3. Crea tres clases que extiendan `vehicles.Car`: `vehicles.Sedan`, `vehicles.UtilityVehicle` y `vehicles.Truck`.
4. Los objetos de `vehicles.UtilityVehicle` deben tener una propiedad adicional `fourWheelDrive`, un `boolean` que representa si el vehículo tiene tracción en las cuatro ruedas.
5. Los objetos de `vehicles.Truck` deben tener una propiedad adicional `towingCapacity`, un `double` que representa la capacidad de remolque del camión.

<br>

Expand All @@ -69,6 +69,20 @@ Una vez que termines la tarea, envía un enlace URL a tu repositorio o tu solici
4. `IntVector` debe almacenar números en un arreglo con una longitud de 20 por defecto. Cuando se llama al método `add`, primero debes determinar si el array está lleno. Si lo está, crea un nuevo array que sea el doble del tamaño del array actual, mueve todos los elementos al nuevo array y agrega el nuevo elemento. (Por ejemplo, un array de longitud 10 aumentaría a 20).
5. En su `README.md`, incluye un ejemplo de cuándo `IntArrayList` sería más eficiente y cuándo `IntVector` sería más eficiente.

<br>
<!--5. En su `README.md`, incluye un ejemplo de cuándo `IntArrayList` sería más eficiente y cuándo `IntVector` sería más eficiente.-->
Ejemplo de IntArrayList e IntVector:
IntArrayList --> Crecimiento moderado del espacio, aumentándolo en un 50% si está lleno, de manera controlada.
Es más eficiente en cuanto uso de memoria, reduciendo la cantidad de espacio no utilizado.
Se utiliza donde rara vez los elementos llegan alcanzar el límite del array.
Ejemplo, se usa en el registro de datos periódicos y en bajo número.

IntVector --> Crecimiento rápido y significativo, se espera que los elementos aumenten rápidamente.
Se utilizan en entornos donde el costo de redimensionar es significativo.
Es más eficiente con respecto que supone un menor número de operaciones de copia a lo largo del tiempo y con sistemas de memoria disponible.
Ejemplo, Sistemas de monitoreo donde necesitamos guardar grandes bloques de datos con frecuencia. Registro de logs de una aplicación.


<br>

## FAQs (Preguntas frecuentes)
Expand All @@ -77,7 +91,7 @@ Una vez que termines la tarea, envía un enlace URL a tu repositorio o tu solici

<details>
<summary style="font-size: 16px; cursor: pointer; outline: none; font-weight: bold;">Estoy atascado y no sé cómo resolver el problema o por dónde empezar. ¿Qué debo hacer?</summary>

<!-- ✅ -->

Si estás atascado con tu código y no sabes cómo resolver el problema o por dónde empezar, debes dar un paso atrás y tratar de formular una pregunta clara y directa sobre el problema específico que enfrentas. El proceso que seguirás al tratar de definir esta pregunta te ayudará a limitar el problema y a encontrar soluciones potenciales.
Expand Down
Binary file added out/production/labs/Main.class
Binary file not shown.
Binary file added out/production/labs/interfaz/IntArrayList.class
Binary file not shown.
Binary file added out/production/labs/interfaz/IntList.class
Binary file not shown.
Binary file added out/production/labs/interfaz/IntVector.class
Binary file not shown.
Binary file added out/production/labs/vehicles/Car.class
Binary file not shown.
Binary file added out/production/labs/vehicles/Sedan.class
Binary file not shown.
Binary file added out/production/labs/vehicles/Truck.class
Binary file not shown.
Binary file added out/production/labs/vehicles/UtilityVehicle.class
Binary file not shown.
Binary file added out/production/labs/video/Movie.class
Binary file not shown.
Binary file added out/production/labs/video/TvSeries.class
Binary file not shown.
Binary file added out/production/labs/video/Video.class
Binary file not shown.
122 changes: 122 additions & 0 deletions src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import java.math.BigDecimal;
import java.math.RoundingMode;

import interfaz.IntArrayList;
import interfaz.IntList;
import interfaz.IntVector;
import vehicles.Sedan;
import vehicles.Truck;
import vehicles.UtilityVehicle;
import video.Movie;
import video.TvSeries;

public class Main {

public static void main(String[] args) {
//Ejercicio 1.1
BigDecimal number = new BigDecimal("4.2545");
//decimalDouble(number);

//Ejercicio 1.2
//creamos numeros bigdecimal
BigDecimal number1 = new BigDecimal("1.2345");
BigDecimal number2 = new BigDecimal("-45.67");
// invertirSigno(number1);
// invertirSigno(number2);

//Ejercicio 2. Sistema de Inventario de vehículos.
//inventarioVehiculos();

//Ejercicio 3. Servicio de transmision de video.
playVideo();

//Ejercicio 4. Interfaz IntList
//IntArrayList
arrayList();
//Intvector
vectorList();


}


//Ejercicio 1.1
public static double decimalDouble(BigDecimal number){
System.out.println("Ejercicio 1.1, utilizando BigDecimal");
BigDecimal roundedNumber = number.setScale(2, RoundingMode.HALF_UP);
double result = roundedNumber.doubleValue();
System.out.println("Resultado redondeado y pasado a double: " + result + "\n");
return result;
}

//Ejercicio 1.2
public static double invertirSigno(BigDecimal number){
System.out.println("Ejercicio 1.2, utilizando BigDecimal");
BigDecimal invertedNumber = number.negate();
BigDecimal roundedNumber = invertedNumber.setScale(1, RoundingMode.HALF_UP);
double result = roundedNumber.doubleValue();
System.out.println("Redondeamos invirtiendo el numero: " + roundedNumber);
return result;
}

//Ejercicio 2. Inventario de coche.
public static void inventarioVehiculos(){
System.out.println("\nEjercicio 2. Sistema de inventarios de coches.");

Sedan sedan1 = new Sedan("98427823", "Turismo", "SDI", 10000);
UtilityVehicle utilityVehicle1 = new UtilityVehicle("213124", "Patro" , "todocamino", 40000, true );
Truck truck1 = new Truck("1123124", "superTruck", "4X4", 2000, 2);

sedan1.getInfo();
utilityVehicle1.getInfo();
truck1.getInfo();
}

//Ejercicio 3. Servicio de transmision de video.
public static void playVideo(){
System.out.println("\nEjercicio 3. Sistema de reproducción de video.");

TvSeries tvSeries1 = new TvSeries("Crepusculo", 45, 137 );
Movie movie1 = new Movie("Los Juegos del Hambre", 150, 7.8);

tvSeries1.getInfo();
movie1.getInfo();

}


//Ejercicio de Interfaz IntList
//IntArrayList
public static void arrayList(){
IntList intArrayList = new IntArrayList();

//Agregar elementos en el IntArrayList
for(int i = 0; i < 15; i++){
intArrayList.add(i);
}

//Intentar obtener los elementos y mostrarlos
System.out.println("\nElementos en IntArrayList:");
for(int i = 0; i < 15; i++){
intArrayList.get(i);
}
}

//IntVector
public static void vectorList(){
IntList intVector = new IntVector();
//Agregamos elementos a nuestro intvector
for( int i = 0; i < 40; i++){
intVector.add(i);
}

//Mostramos el vector
System.out.println("\nElementos de IntVector:");
for(int i = 0; i < 40; i++){
intVector.get(i);
}
}


}

38 changes: 38 additions & 0 deletions src/interfaz/IntArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package interfaz;

public class IntArrayList implements IntList{

//ARRAY
int[] arrayList = new int[20];
int count = 0;

@Override
public void add(int number){
//vemos si tenemos que expandir el array o no
if (count == arrayList.length){
//creamos new array
int[] newArrayList = new int[arrayList.length + arrayList.length / 2];

//copiamos los elementos al nuevo array
for (int i = 0; i < arrayList.length; i++){
newArrayList[i] = arrayList[i];
}
arrayList = newArrayList;
}
//Agrega,los numero en la primera posicion vacia
arrayList[count] = number;
count++;

}

@Override
public void get(int id) {
if(id < 0 || id >= count){
throw new IndexOutOfBoundsException("Índice fuera de rango.");
}
System.out.println("Elemento en Índice " + id + " : " + arrayList[id]);
}



}
7 changes: 7 additions & 0 deletions src/interfaz/IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package interfaz;

public interface IntList {
public void add(int number);
public void get(int id);

}
29 changes: 29 additions & 0 deletions src/interfaz/IntVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package interfaz;

public class IntVector implements IntList{

int[] intVector = new int[10];
int count = 0;

@Override
public void add(int number){
if(count == intVector.length){
int[] newIntVector = new int[intVector.length * 2];
for(int i = 0; i < intVector.length; i++){
newIntVector[i] = intVector[i];
}
intVector = newIntVector;
}
intVector[count] = number;
count++;
}


@Override
public void get(int id){
if (id < 0 || id >= count){
throw new IndexOutOfBoundsException("Indice fuera de rengo");
}
System.out.println("Elemento en índice " + id + " : " + intVector[id]);
}
}
33 changes: 33 additions & 0 deletions src/vehicles/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package vehicles;
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;
}

// Asegúrate que estos métodos sean públicos
public String getVinNumber() {
return vinNumber;
}

public String getMake() {
return make;
}

public String getModel() {
return model;
}

public int getMileage() {
return mileage;
}

public abstract void getInfo();
}
17 changes: 17 additions & 0 deletions src/vehicles/Sedan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package vehicles;

public class Sedan extends Car {

public Sedan(String vinNumber, String make, String model, int mileage) {

super(vinNumber, make, model, mileage);
}

@Override
public void getInfo() {
System.out.println("Sedan --> VIN Number: " + getVinNumber()
+ ", Make: " + getMake()
+ ", Model: " + getModel()
+ ", Mileage: " + getMileage());
}
}
29 changes: 29 additions & 0 deletions src/vehicles/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package vehicles;

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;
}

//Capacidad de remolque del camion.
public double getTowingCapacity() {
return towingCapacity;
}

public void setTowingCapacity(double towingCapacity) {
this.towingCapacity = towingCapacity;
}

@Override
public void getInfo() {
System.out.println("Truck --> VIN Number: " + getVinNumber()
+ ", Make: " + getMake()
+ ", Model: " + getModel()
+ ", Mileage: " + getMileage()
+ ", TowingCapacity: " + getTowingCapacity());
}
}
Loading