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/lab-java-interfaces-and-abstract-classes.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/markdown.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/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.

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ 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.

# Choosing Between IntArrayList and IntVector

This project has two different ways to handle an array that runs out of space. Here is a simple guide on when to use each one:

### IntArrayList (Grows by 50%)
* **Best for:** Saving memory (RAM).
* **Why:** When the array gets full, it only adds half of its current capacity. This is great because it prevents having a lot of empty, unused spaces in memory. You should use this when your list grows slowly or if your computer doesn't have a lot of memory available.

### IntVector (Doubles its size)
* **Best for:** Speed and performance.
* **Why:** Every time an array gets full, Java has to create a brand new one and copy all the old numbers into it. This process takes time! Because `IntVector` doubles its size, it doesn't have to do this heavy task as often. You should use this when you need to add thousands of numbers very fast, even if it means wasting some empty memory spaces at the end.





<br>

## FAQs
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions src/IntListInterface/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package IntListInterface;

public class Application {
public static void main(String[] args) {

System.out.println("--- Probando IntArrayList (Crece un 50%) ---");
IntList miArrayList = new IntArrayList();


for (int i = 0; i < 12; i++) {
miArrayList.add(i * 10); // Añadimos 0, 10, 20, 30...
}
System.out.println("Elemento en ID 11: " + miArrayList.get(11));


System.out.println("\n--- Probando IntVector (Crece un 100%) ---");
IntList miVector = new IntVector();


for (int i = 0; i < 25; i++) {
miVector.add(i * 100); // Añadimos 0, 100, 200, 300...
}
System.out.println("Elemento en ID 21: " + miVector.get(21));

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

import java.util.Arrays;

public class IntArrayList implements IntList{
private int[] array;
private int size;

public IntArrayList() {
this.array = new int [10];
this.size = 0;
}

@Override
public void add(int number) {

if (size == array.length) {
// Calcular el nuevo tamaño: el actual + 50% (la mitad)
int newSize = array.length + (array.length / 2);


array = Arrays.copyOf(array, newSize);
System.out.println("IntArrayList ha crecido a tamaño: " + newSize); // Para que lo veas en consola
}

array[size] = number;
size++;
}

@Override
public int get(int id) {
// Devuelve el elemento en la posición 'id'
if (id >= 0 && id < size) {
return array[id];
}
throw new IndexOutOfBoundsException("ID fuera de rango");
}
}
6 changes: 6 additions & 0 deletions src/IntListInterface/IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package IntListInterface;

public interface IntList {
void add(int number);
int get(int id);
}
39 changes: 39 additions & 0 deletions src/IntListInterface/IntVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package IntListInterface;

import java.util.Arrays;

public class IntVector implements IntList {
private int[] array;
private int size;


public IntVector() {
this.array = new int[20];
this.size = 0;
}

@Override
public void add(int number) {

if (size == array.length) {
// Calcular el nuevo tamaño: el doble del actual
int newSize = array.length * 2;


array = Arrays.copyOf(array, newSize);
System.out.println("IntVector ha crecido a tamaño: " + newSize);
}


array[size] = number;
size++;
}

@Override
public int get(int id) {
if (id >= 0 && id < size) {
return array[id];
}
throw new IndexOutOfBoundsException("ID fuera de rango");
}
}
18 changes: 18 additions & 0 deletions src/OperationsBigDecimal/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import OperationsBigDecimal.BigDecimalOperations;

import java.math.BigDecimal;


public static void main(String[] args) {

System.out.println("--- TESTS BIGDECIMAL ---");

BigDecimal num1 = new BigDecimal("5.2565");
System.out.println("Test1: " + BigDecimalOperations.redondearCentesima(num1));

BigDecimal num2 = new BigDecimal("2.3545");
System.out.println("Test2_negative: " + BigDecimalOperations.invertirYRedondear(num2));

BigDecimal num3 = new BigDecimal("-54.7678");
System.out.println("Test2_positive: " + BigDecimalOperations.invertirYRedondear(num3));
}
17 changes: 17 additions & 0 deletions src/OperationsBigDecimal/BigDecimalOperations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package OperationsBigDecimal;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalOperations {


public static double redondearCentesima(BigDecimal numero) {
return numero.setScale(2, RoundingMode.HALF_UP).doubleValue();
}


public static BigDecimal invertirYRedondear(BigDecimal numero) {
return numero.negate().setScale(1, RoundingMode.HALF_UP);
}
}
16 changes: 16 additions & 0 deletions src/ServiceVideoStreaming/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ServiceVideoStreaming;

public class Application {
public static void main(String[] args) {

Movie miPeli = new Movie("La vida es bella", 116, 8.6);

TvSeries miSerie = new TvSeries("Pluribus", 50, 9);

System.out.println("*--- INFO MOVIE ---*");
System.out.println(miPeli.getInfo());

System.out.println("\n*--- INFO SERIE ---*");
System.out.println(miSerie.getInfo());
}
}
23 changes: 23 additions & 0 deletions src/ServiceVideoStreaming/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ServiceVideoStreaming;

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

public void setRating(double rating) {
this.rating = rating;
}

@Override
public String getInfo() {
return "Title: " + getTitle() + "\nDuration: " + getDuration() + " minutes\nRating: " + getRating();
}
}
23 changes: 23 additions & 0 deletions src/ServiceVideoStreaming/TvSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ServiceVideoStreaming;

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

public void setEpisodes(int episodes) {
this.episodes = episodes;
}

@Override
public String getInfo() {
return "Title: " + getTitle() + "\nDuration: " + getDuration() + " minutes\nEpisodes: " + getEpisodes();
}
}
29 changes: 29 additions & 0 deletions src/ServiceVideoStreaming/Video.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ServiceVideoStreaming;

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 void setTitle(String title) {
this.title = title;
}

public int getDuration() {
return duration;
}

public void setDuration(int duration) {
this.duration = duration;
}

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

public class Application {
static void main(String[] args) {
Car truck = new Truck("0007DWL", "Fiat", "Ducato", 180000, 3500.0);
Car sedan = new Sedan("1415NMB", "Opel", "Insignia", 21000);
Car utilityVehicle = new UtilityVehicle("6536MHN", "Toyota", "Hilux", 15000,true);


System.out.println(truck.getInfo());
System.out.println("******");
System.out.println(sedan.getInfo());
System.out.println("******");
System.out.println(utilityVehicle.getInfo());
}
}

53 changes: 53 additions & 0 deletions src/SystemInventoryCar/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package SystemInventoryCar;

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 void setVinNumber(String vinNumber) {
this.vinNumber = vinNumber;
}

public String getMake() {
return make;
}

public void setMake(String make) {
this.make = make;
}

public String getModel() {
return model;
}

public void setModel(String model) {
this.model = model;
}

public int getMileage() {
return mileage;
}

public void setMileage(int mileage) {
this.mileage = mileage;
}

public String getInfo(){
return "Nº vin: " + vinNumber + "\nMake: " + make + "\nModel: " + model + "\nMileage: " + mileage + "KM.";

}
}
Loading