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
10 changes: 10 additions & 0 deletions .idea/.gitignore

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

9 changes: 9 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/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.

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

IntArrayList

- Aplicaciones con memoria limitada
- Conjuntos de datos pequeños o medianos
<br>

IntVector

- Aplicaciones con grandes volúmenes de datos
- Sistemas donde la velocidad es más importante que la memoria
## FAQs

<br>
Expand Down
30 changes: 30 additions & 0 deletions src/BigDecimalOperations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalOperations {

// Ex 1
public static double roundToHundredth(BigDecimal number) {
BigDecimal rounded = number.setScale(2, RoundingMode.HALF_UP);
return rounded.doubleValue();
}

// Ex 2
public static double invertAndRoundToTenth(BigDecimal number) {
BigDecimal inverted = number.negate();
BigDecimal rounded = inverted.setScale(1, RoundingMode.HALF_UP);
return rounded.doubleValue();
}

public static void main(String[] args) {

BigDecimal num1 = new BigDecimal("4.2545");
System.out.println("Rounded to hundredth: " + roundToHundredth(num1));

BigDecimal num2 = new BigDecimal("1.2345");
System.out.println("Invert and round: " + invertAndRoundToTenth(num2));

BigDecimal num3 = new BigDecimal("-45.67");
System.out.println("Invert and round: " + invertAndRoundToTenth(num3));
}
}
20 changes: 20 additions & 0 deletions src/CarInventorySystem/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package CarInventorySystem;

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 getInfo() {
return "VIN: " + vinNumber + "/ Make: " + make + "/ Model: " + model + "/ Mileage: " + mileage;
}
}
16 changes: 16 additions & 0 deletions src/CarInventorySystem/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package CarInventorySystem;

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

Sedan sedan = new Sedan("8902MLH", "Kia", "Xceed", 50000);

UtilityVehicle suv = new UtilityVehicle("8793MYT", "Jeep", "Wrangler", 30000, true);

Truck truck = new Truck("8795LFM", "Volvo", "FH", 70000, 5000.5);

System.out.println(sedan.getInfo());
System.out.println(suv.getInfo());
System.out.println(truck.getInfo());
}
}
8 changes: 8 additions & 0 deletions src/CarInventorySystem/Sedan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package CarInventorySystem;

class Sedan extends Car {

public Sedan(String vinNumber, String make, String model, int mileage) {
super(vinNumber, make, model, mileage);
}
}
16 changes: 16 additions & 0 deletions src/CarInventorySystem/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package CarInventorySystem;

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 super.getInfo() + ", Towing Capacity: " + towingCapacity;
}
}
16 changes: 16 additions & 0 deletions src/CarInventorySystem/UtilityVehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package CarInventorySystem;

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 super.getInfo() + ", Four Wheel Drive: " + fourWheelDrive;
}
}
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;

public class IntArrayList implements IntList {

private int[] data;
private int size;

public IntArrayList() {
data = new int[10];
size = 0;
}

@Override
public void add(int number) {

if (size == data.length) {
int newLength = (int) (data.length * 1.5);
int[] newData = new int[newLength];

for (int i = 0; i < data.length; i++) {
newData[i] = data[i];
}

data = newData;
}

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

@Override
public int get(int id) {
if (id < 0 || id >= size) {
throw new IndexOutOfBoundsException("Invalid index");
}
return data[id];
}
}
8 changes: 8 additions & 0 deletions src/IntListInterface/IntList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package IntListInterface;

public interface IntList {

void add(int number);

int get(int id);
}
38 changes: 38 additions & 0 deletions src/IntListInterface/IntVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package IntListInterface;

public class IntVector implements IntList {

private int[] data;
private int size;

public IntVector() {
data = new int[20];
size = 0;
}

@Override
public void add(int number) {

if (size == data.length) {
int newLength = data.length * 2;
int[] newData = new int[newLength];

for (int i = 0; i < data.length; i++) {
newData[i] = data[i];
}

data = newData;
}

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

@Override
public int get(int id) {
if (id < 0 || id >= size) {
throw new IndexOutOfBoundsException("Invalid index");
}
return data[id];
}
}
18 changes: 18 additions & 0 deletions src/IntListInterface/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package IntListInterface;

public class Main {

public static void main(String[] args) {

IntList list1 = new IntArrayList();
IntList list2 = new IntVector();

for (int i = 0; i < 15; i++) {
list1.add(i);
list2.add(i);
}

System.out.println(list1.get(5));
System.out.println(list2.get(5));
}
}
12 changes: 12 additions & 0 deletions src/VideoStreamingService/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package VideoStreamingService;

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

TvSeries series = new TvSeries("Vikings", 50, 89);
Movie movie = new Movie("TLOTR: The Return of the King", 201, 8.2);

System.out.println(series.getInfo());
System.out.println(movie.getInfo());
}
}
16 changes: 16 additions & 0 deletions src/VideoStreamingService/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package VideoStreamingService;

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 super.getInfo() + ", Rating: " + rating;
}
}
16 changes: 16 additions & 0 deletions src/VideoStreamingService/TvSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package VideoStreamingService;

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 super.getInfo() + ", Episodes: " + episodes;
}
}
15 changes: 15 additions & 0 deletions src/VideoStreamingService/Video.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package VideoStreamingService;

abstract class Video {
private String title;
private int duration;

public Video(String title, int duration) {
this.title = title;
this.duration = duration;
}

public String getInfo() {
return "Title: " + title + ", Duration: " + duration + " minutes";
}
}