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
11 changes: 11 additions & 0 deletions Lab_1.08/Lab_1.08.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
32 changes: 32 additions & 0 deletions Lab_1.08/src/InterfazIntList/IntArrayList.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
7 changes: 7 additions & 0 deletions Lab_1.08/src/InterfazIntList/IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package InterfazIntList;

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

31 changes: 31 additions & 0 deletions Lab_1.08/src/InterfazIntList/IntVector.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
93 changes: 93 additions & 0 deletions Lab_1.08/src/Main.java
Original file line number Diff line number Diff line change
@@ -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 <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> 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));
}
}
31 changes: 31 additions & 0 deletions Lab_1.08/src/automoviles/Car.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
12 changes: 12 additions & 0 deletions Lab_1.08/src/automoviles/Sedan.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
16 changes: 16 additions & 0 deletions Lab_1.08/src/automoviles/Truck.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
16 changes: 16 additions & 0 deletions Lab_1.08/src/automoviles/UtilityVehicle.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
14 changes: 14 additions & 0 deletions Lab_1.08/src/transmisionVideo/Movie.java
Original file line number Diff line number Diff line change
@@ -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 + ")";
}
}
15 changes: 15 additions & 0 deletions Lab_1.08/src/transmisionVideo/TvSeries.java
Original file line number Diff line number Diff line change
@@ -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)";
}
}
20 changes: 20 additions & 0 deletions Lab_1.08/src/transmisionVideo/Video.java
Original file line number Diff line number Diff line change
@@ -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;
}
}