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.

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/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.

12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ Once you finish the assignment, submit a URL link to your repository or your pul

<br>

### Car Inventory System
### CarInventorySystem.Car Inventory System

1. Suppose you are building a car inventory system. All cars have a `vinNumber`, `make`, `model` and `mileage`. But no car is just a car. Each car is either a `Sedan`, a `UtilityVehicle` or a `Truck`.
2. Create an abstract class named `Car` and define the following properties and behaviors:
1. Suppose you are building a car inventory system. All cars have a `vinNumber`, `make`, `model` and `mileage`. But no car is just a car. Each car is either a `CarInventorySystem.Sedan`, a `CarInventorySystem.UtilityVehicle` or a `CarInventorySystem.Truck`.
2. Create an abstract class named `CarInventorySystem.Car` and define the following properties and behaviors:
- `vinNumber`: a `String` representing the VIN number of the car
- `make`: a `String` representing the make of the car
- `model`: a `String` representing the model of the car
- `mileage`: an `int` representing the mileage of the car
- `getInfo()`: a method that returns a `String` containing all of the car's properties in a readable format
3. Create three classes that extend `Car`: `Sedan`, `UtilityVehicle` and `Truck`.
4. `UtilityVehicle` objects should have an additional `fourWheelDrive` property, a `boolean` that represents whether the vehicle has four-wheel drive.
5. `Truck` objects should have an additional `towingCapacity` property, a `double` that represents the towing capacity of the truck.
3. Create three classes that extend `CarInventorySystem.Car`: `CarInventorySystem.Sedan`, `CarInventorySystem.UtilityVehicle` and `CarInventorySystem.Truck`.
4. `CarInventorySystem.UtilityVehicle` objects should have an additional `fourWheelDrive` property, a `boolean` that represents whether the vehicle has four-wheel drive.
5. `CarInventorySystem.Truck` objects should have an additional `towingCapacity` property, a `double` that represents the towing capacity of the truck.

<br>

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.
16 changes: 16 additions & 0 deletions src/BigDecimalOperations/BigDecimalOperations.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package BigDecimalOperations;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class BigDecimalOperations {
//METODO1⤵
public static double roundToDouble(BigDecimal number){
BigDecimal roundedNumber = number.setScale(2, RoundingMode.HALF_UP);
return roundedNumber.doubleValue();
}
//METODO2⤵
public static BigDecimal reverseSignAndRound(BigDecimal number){
BigDecimal negatedNumber = number.negate();
return negatedNumber.setScale(1, RoundingMode.HALF_UP);
}
}
25 changes: 25 additions & 0 deletions src/BigDecimalOperations/BigDecimalOperationsApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package BigDecimalOperations;

import java.math.BigDecimal;

import static BigDecimalOperations.BigDecimalOperations.reverseSignAndRound;
import static BigDecimalOperations.BigDecimalOperations.roundToDouble;

public class BigDecimalOperationsApplication {

public static void main(String[] args) {
BigDecimal number1 = new BigDecimal("23.2323232323");
BigDecimal number2 = new BigDecimal("32.3232323232");
BigDecimal number3 = new BigDecimal("-32.323232323");

System.out.println("TEST METHOD 1 ↪");
System.out.println("NUMBER TO TEST ➡ " + number1 + "\nResult Method 1 (ROUNDED TO 2 DECIMALS) ➡ " + roundToDouble(number1));
System.out.println("METHOD 1 TESTED ________________________⤴\n");
System.out.println("\nTEST METHOD 2 ↪");
System.out.println("NUMBER TO TEST ➡ " + number2 + "\nResult Method 2 (INVERTED SIGN TO NEGATIVE) ➡ " + reverseSignAndRound(number2));
System.out.println("METHOD 2 NEGATED NUMBER TESTED _____________⤴\n");
System.out.println("NUMBER TO TEST ➡ " + number3 + "\nResult Method 2 (INVERTED SIGN TO POSITIVE) ➡ " + reverseSignAndRound(number3));
System.out.println("METHOD 2 POSITIVE NUMBER TESTED ____________⤴");
}

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

import java.util.ArrayList;
import java.util.List;

public class AppCarInventorySystem {
static void main(String[] args) {
List<Car> cars = new ArrayList<>();


cars.add(new Sedan("1425MXV", "Hyundai", "i30", 35000));
cars.add(new UtilityVehicle("2323FFF", "Ford", "Kuga", 3000, false));
cars.add(new Truck("1456GHH", "Chevrolet", "Silverado", 3200, 10000.0));
cars.add(new UtilityVehicle("4589NGT", "Volkswagen", "Atlas", 14000, true));
cars.add(new Truck("2555MGT", "Ford", "F-150", 4000, 10000.0));
cars.add(new Sedan("3345GTX", "BMW", "M3", 1000));


for (Car car : cars) {
System.out.println(car.getInfo());
System.out.println("<----------------------------------------------->");
}



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

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 getModel() {
return model;
}

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

public String getMake() {
return make;
}

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

public double getMileage() {
return mileage;
}

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

public String getInfo() {
return "🔢Vin:" + vinNumber + "\n🚘Make:" + make + "\nModel:" + model + "\n➡Mileage:" + mileage + " km";

}

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

public class Sedan extends Car {
public Sedan(String vinNumber, String make, String model, int mileage) {
super(vinNumber, make, model, mileage);
}

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

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

public double getTowingCapacity() {

return towingCapacity;
}

public void setTowingCapacity(double towingCapacity) {

this.towingCapacity = towingCapacity;
}
@Override
public String getInfo(){
return ("🔢Vin:" + getVinNumber() + "\nMake:" + getMake() + "\nModel:" + getModel() + "\nMileage:" + getMileage() + " km" + "\nTowing Capacity:" + getTowingCapacity() + " kg");
}

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

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

public boolean isFourWheelDrive() {
return fourWheelDrive;
}

public void setFourWheelDrive(boolean fourWheelDrive) {
this.fourWheelDrive = fourWheelDrive;
}

@Override
public String getInfo(){
return ("🔢Vin:" + getVinNumber() + "\nMake:" + getMake() + "\nModel:" + getModel() + "\nMileage:" + getMileage() + " km" + "\n4WD" + fourWheelDrive );
}


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

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) {
resize(array.length * 1.5);
}
array[size++] = number;
}

@Override
public int get(int id) {
if (id < 0 || id >= size) {
throw new IndexOutOfBoundsException("Index: " + id + ", Size: " + size);
}
return array[id];
}

private void resize(double newSize) {
int[] newArray = new int[(int) newSize];
System.arraycopy(array, 0, newArray, 0, size);
this.array = newArray;
}
}
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);
}
38 changes: 38 additions & 0 deletions src/IntListInterface/IntListTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package IntListInterface;

public class IntListTest {
public static void main(String[] args) {
testIntArrayList();
testIntVector();
}

private static void testIntArrayList() {
System.out.println("Testing IntArrayList:");
IntList intArrayList = new IntArrayList();

// Adding elements
for (int i = 0; i < 50; i++) {
intArrayList.add(i);
}

// Retrieving elements
for (int i = 0; i < 50; i++) {
System.out.println("Element at index " + i + ": " + intArrayList.get(i));
}
}

private static void testIntVector() {
System.out.println("\nTesting IntVector:");
IntList intVector = new IntVector();

// Adding elements
for (int i = 0; i < 100; i++) {
intVector.add(i);
}

// Retrieving elements
for (int i = 0; i < 100; i++) {
System.out.println("Element at index " + i + ": " + intVector.get(i));
}
}
}
31 changes: 31 additions & 0 deletions src/IntListInterface/IntVector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package IntListInterface;

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) {
resize(array.length * 2);
}
array[size++] = number;
}
@Override
public int get(int id) {
if (id < 0 || id >= size) {
throw new IndexOutOfBoundsException("Index: " + id + ", Size: " + size);
}
return array[id];
}
private void resize(double newSize) {
int[] newArray = new int[(int)newSize];
System.arraycopy(array, 0, newArray, 0, size);
this.array = newArray;
}
}
14 changes: 14 additions & 0 deletions src/IntListInterface/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# IntList Implementation Analysis

## Efficiency Comparison: IntArrayList vs. IntVector

This project includes two implementations of the `IntList` interface, each with a different strategy for resizing its internal array when it reaches capacity.

### When is `IntArrayList` more efficient?
`IntArrayList` grows by **50%** of its current size when full.
* **Best Use Case:** It is more efficient in terms of **Memory (RAM) consumption**. It is ideal when you have limited memory resources or when you expect the list to grow, but at a slow, gradual, or predictable pace. Because it doesn't request massive blocks of memory at once, it prevents memory waste.

### When is `IntVector` more efficient?
`IntVector` grows by **100%** (it doubles its size) when full.
* **Best Use Case:** It is more efficient in terms of **Processing Speed (CPU)** when dealing with massive amounts of data. Resizing an array (creating a new one and copying all elements over) is a heavy operation. By doubling in size, `IntVector` performs this costly operation much less frequently than `IntArrayList`. It trades memory space for faster execution times when rapidly adding many elements.

Loading