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
Binary file added .DS_Store
Binary file not shown.
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.

9 changes: 9 additions & 0 deletions .idea/lab-java-interfaces-and-abstract-classes-es.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.

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

Binary file added out/production/untitled/Car.class
Binary file not shown.
Binary file added out/production/untitled/InList.class
Binary file not shown.
Binary file not shown.
Binary file added out/production/untitled/IntArrayList.class
Binary file not shown.
Binary file added out/production/untitled/IntVector.class
Binary file not shown.
Binary file added out/production/untitled/Main.class
Binary file not shown.
Binary file added out/production/untitled/Movie.class
Binary file not shown.
Binary file added out/production/untitled/Sedan.class
Binary file not shown.
Binary file added out/production/untitled/Truck.class
Binary file not shown.
Binary file added out/production/untitled/TvSeries.class
Binary file not shown.
Binary file added out/production/untitled/UtilityVehicle.class
Binary file not shown.
Binary file added out/production/untitled/Video.class
Binary file not shown.
Binary file added untitled/.DS_Store
Binary file not shown.
48 changes: 48 additions & 0 deletions untitled/src/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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 abstract String getInfo();
}
4 changes: 4 additions & 0 deletions untitled/src/InList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public interface InList {
void add(int number);
int get(int id);
}
5 changes: 5 additions & 0 deletions untitled/src/IndexOutOfBoundsException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public class IndexOutOfBoundsException extends RuntimeException {
public IndexOutOfBoundsException(String message) {
super(message);
}
}
38 changes: 38 additions & 0 deletions untitled/src/IntArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public class IntArrayList implements InList {
private int[] array;
private int size;

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

private void resizeArray() {
int newSize = array.length + (array.length / 2); // Increase the 50%
int[] newArray = new int[newSize];
System.arraycopy(array, 0, newArray, 0, array.length);
array = newArray;
System.out.println("IntArrayList resized! New array size: " + newSize);

}

@Override
public void add(int number) {
if (size == array.length) {
resizeArray();
}
array[size++] = number;
}

@Override
public int get(int id) {
if (id >= 0 && id < size) {
return array[id];
} else { //as we need to return an int, we need exception
throw new IndexOutOfBoundsException("Index out of range");
}

}

}

37 changes: 37 additions & 0 deletions untitled/src/IntVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
public class IntVector implements InList{
private int[] array;
private int size;

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

private void resizeArray() {
int newSize = array.length * 2; // Double the size
int[] newArray = new int[newSize];
System.arraycopy(array, 0, newArray, 0, array.length);
array = newArray;
System.out.println("InVector resized! New array size: " + newSize);
}

@Override
public void add(int number) {
if (size == array.length) {
resizeArray();
}
array[size++] = number;
}

@Override
public int get(int id) {
if (id >= 0 && id < size) {
return array[id];
} else { //as we need to return an int, we need excpetion
throw new IndexOutOfBoundsException("Index out of range");
}

}


}
73 changes: 73 additions & 0 deletions untitled/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {
public static double roundTwo(BigDecimal number) {
BigDecimal rounded = number.setScale(2, RoundingMode.HALF_UP);
return rounded.doubleValue();
}
public static double invert(BigDecimal number){
BigDecimal inverted = number.negate();
BigDecimal rounded = inverted.setScale(1, RoundingMode.HALF_UP);
return rounded.doubleValue();
}
public static void main(String[] args) {

System.out.println("ERCERCICE 1 ---------- BIG DECIMAL");
BigDecimal num1 = new BigDecimal("4.2565");
BigDecimal num2 = new BigDecimal("-9.548");

System.out.println(roundTwo(num1));
System.out.println(invert(num1));
System.out.println(roundTwo(num2));
System.out.println(invert(num2));

System.out.println("\nEXERCICIE 2 ----------");
Car Sedan = new Sedan("891223","Cheverolet","Aveo",15000);
Car UtilityVehicle = new UtilityVehicle("654321", "Jeep", "Cherokee", 20000, true);
Car Truck = new Truck("789012", "Ford", "F-150", 25000,4.6);


System.out.println(Sedan.getInfo());
System.out.println(UtilityVehicle.getInfo());
System.out.println(Truck.getInfo());

System.out.println("\nEXERCICE 3---------");
Video movie = new Movie("Harry Potter",120,9.5);
Video tvserie = new TvSeries("El cor de la ciutat",30,500);

System.out.println(movie.getInfo());
System.out.println(tvserie.getInfo());

System.out.println("\nEXERCICE 4---------");

InList arrayList = new IntArrayList();
System.out.println("\nTesting IntArrayList:");
for (int i = 0; i < 17; i++) {
arrayList.add(i * 2);
}
for (int i = 0; i < 17; i++) {
System.out.println("Element at index " + i + ": " + arrayList.get(i));
}


InList vector = new IntVector();
System.out.println("\nTesting IntVector:");
for (int i = 0; i < 25; i++) {
vector.add(i * 3);
}
for (int i = 0; i < 25; i++) {
System.out.println("Element at index " + i + ": " + vector.get(i));
}



}

}






13 changes: 13 additions & 0 deletions untitled/src/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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 "The " + getTitle() + " movie has a duration of " + getDuration() + " minutes and is rated as " + rating;
}
}
13 changes: 13 additions & 0 deletions untitled/src/Sedan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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() + "]";
}
}


14 changes: 14 additions & 0 deletions untitled/src/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class Truck extends Car{
private final 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 + "]";
}
}
21 changes: 21 additions & 0 deletions untitled/src/TvSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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 "The " + getTitle() + " has a duration of " + getDuration() + " minutes and have " + episodes + " episodes";
}
}
13 changes: 13 additions & 0 deletions untitled/src/UtilityVehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

public class UtilityVehicle extends Car {
private final 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 "UtilityVehicle [VIN: " + getVinNumber() + ", Make: " + getMake() + ", Model: " + getModel() + ", Mileage: " + getMileage() + ", Four-Wheel Drive: " + fourWheelDrive + "]";
}
}
31 changes: 31 additions & 0 deletions untitled/src/Video.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
public abstract class Video {
private String title;
private int duration;

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

public String getInfo (String title, int duration){
return "The " + getTitle() + " has a duration of " + getDuration();
}

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();
}
11 changes: 11 additions & 0 deletions untitled/untitled.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>