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.

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.

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
### Car.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 `Car.Sedan`, a `Car.UtilityVehicle` or a `Car.Truck`.
2. Create an abstract class named `Car.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 `Car.Car`: `Car.Sedan`, `Car.UtilityVehicle` and `Car.Truck`.
4. `Car.UtilityVehicle` objects should have an additional `fourWheelDrive` property, a `boolean` that represents whether the vehicle has four-wheel drive.
5. `Car.Truck` objects should have an additional `towingCapacity` property, a `double` that represents the towing capacity of the truck.

<br>

Expand Down
11 changes: 11 additions & 0 deletions bigDecimal/bigDecimal.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>
26 changes: 26 additions & 0 deletions bigDecimal/src/ArrotondamentoBigDecimal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import java.math.BigDecimal;
import java.math.RoundingMode;

public class ArrotondamentoBigDecimal {

public static void main(String[] args) {
// Esempi di test
System.out.println("Input 1.2345 -> Risultato: " + reverseAndRound(new BigDecimal("1.2345")));
System.out.println("Input -45.67 -> Risultato: " + reverseAndRound(new BigDecimal("-45.67")));
System.out.println("Input null -> Risultato: " + reverseAndRound(null));
}

/**
* Inverte il segno e arrotonda al decimo più vicino.
*/
public static BigDecimal reverseAndRound(BigDecimal value) {
// Gestione del null: restituisce ZERO per evitare errori
if (value == null) {
return BigDecimal.ZERO;
}

// Inverte il segno e arrotonda a 1 cifra decimale
return value.negate()
.setScale(1, RoundingMode.HALF_UP);
}
}
23 changes: 23 additions & 0 deletions bigDecimal/src/Car/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package Car;

public 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 String.format("VIN: %s, Marca: %s, Modello: %s, Chilometraggio: %d km",
vinNumber, make, model, mileage);
}

// Getter e Setter possono essere aggiunti qui se necessario
}

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

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

public class Main {
public static void main(String[] args) {
// Creazione di una lista di Car per sfruttare il polimorfismo
List<Car> concessionario = new ArrayList<>();

// 1. Creazione di una Sedan
Sedan miaSedan = new Sedan("ABC12345", "Toyota", "Corolla", 15000);

// 2. Creazione di un UtilityVehicle (con parametro fourWheelDrive)
UtilityVehicle mioSUV = new UtilityVehicle("XYZ67890", "Jeep", "Wrangler", 5000, true);

// 3. Creazione di un Truck (con parametro towingCapacity)
Truck mioTruck = new Truck("TRK44556", "Ford", "F-150", 1200, 3500.5);

// Aggiungiamo i veicoli alla lista
concessionario.add(miaSedan);
concessionario.add(mioSUV);
concessionario.add(mioTruck);

// Ciclo attraverso la lista e stampa delle informazioni
System.out.println("--- Inventario Veicoli ---");
for (Car veicolo : concessionario) {
System.out.println(veicolo.getInfo());
}
}
}
8 changes: 8 additions & 0 deletions bigDecimal/src/Car/Sedan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package Car;

// Classe Car.Sedan: estensione semplice di Car.Car
public class Sedan extends Car {
public Sedan(String vinNumber, String make, String model, int mileage) {
super(vinNumber, make, model, mileage);
}
}
15 changes: 15 additions & 0 deletions bigDecimal/src/Car/Truck.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Car;

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 super.getInfo() + ", Capacità di traino: " + towingCapacity;
}
}
15 changes: 15 additions & 0 deletions bigDecimal/src/Car/UtilityVehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package Car;

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 super.getInfo() + ", 4WD: " + fourWheelDrive;
}
}
24 changes: 24 additions & 0 deletions bigDecimal/src/Int/IntArrayList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package Int;

import java.util.Arrays;

public class IntArrayList implements IntList {
private int[] array = new int[10];
private int size = 0;

@Override
public void add(int number) {
if (size == array.length) {
// Aumenta del 50% (es. da 10 a 15)
int newSize = array.length + (array.length / 2);
array = Arrays.copyOf(array, newSize);
}
array[size++] = number;
}

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

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

import java.util.Arrays;

public class IntVector implements IntList {
private int[] array = new int[20];
private int size = 0;

@Override
public void add(int number) {
if (size == array.length) {
// Raddoppia la dimensione (es. da 20 a 40)
int newSize = array.length * 2;
array = Arrays.copyOf(array, newSize);
}
array[size++] = number;
}

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

public class Main {
public static void main(String[] args) {
// --- Test IntArrayList (Capacità iniziale 10, cresce del 50%) ---
IntArrayList myArrayList = new IntArrayList();
System.out.println("Test IntArrayList:");

// Aggiungiamo 12 elementi per forzare il primo ridimensionamento (da 10 a 15)
for (int i = 1; i <= 12; i++) {
myArrayList.add(i * 10);
}

System.out.println("Elemento a id 0: " + myArrayList.get(0)); // 10
System.out.println("Elemento a id 11: " + myArrayList.get(11)); // 120
System.out.println();


// --- Test IntVector (Capacità iniziale 20, raddoppia) ---
IntList myVector = new IntVector();
System.out.println("Test IntVector:");

// Aggiungiamo 25 elementi per forzare il primo ridimensionamento (da 20 a 40)
for (int i = 1; i <= 25; i++) {
myVector.add(i * 100);
}

System.out.println("Elemento a id 0: " + myVector.get(0)); // 100
System.out.println("Elemento a id 24: " + myVector.get(24)); // 2500

// Test errore (ID fuori dai limiti)
try {
System.out.println(myVector.get(100));
} catch (IndexOutOfBoundsException e) {
System.out.println("\nErrore gestito: ID 100 non esiste ancora.");
}
}
}
15 changes: 15 additions & 0 deletions bigDecimal/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import java.math.BigDecimal;

public class Main {
public static void main(String[] args) {
eje1 utils = new eje1();

BigDecimal input = new BigDecimal("4.2545");
double result = utils.roundToHundredth(input);

System.out.println("Il numero arrotondato è: " + result);



}
}
31 changes: 31 additions & 0 deletions bigDecimal/src/VideoStreamingService/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package VideoStreamingService;

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

public class Main {
public static void main(String[] args) {
// Creazione di una lista che può contenere qualsiasi tipo di Video
List<Video> catalogo = new ArrayList<>();

// 1. Creazione di un Movie (titolo, durata, rating)
Movie devilDressPrada = new Movie("Il diavolo veste Prada", 121, 9);

// 2. Creazione di una TvSeries (titolo, durata, episodi)
TvSeries breakingBad = new TvSeries("Breaking Bad", 50, 62);

// 3. Altro esempio di Movie
Movie inception = new Movie("Inception", 148, 8.8);

// Aggiunta al catalogo
catalogo.add(devilDressPrada);
catalogo.add(breakingBad);
catalogo.add(inception);

// Stampa delle informazioni di ogni video
System.out.println("=== CATALOGO VIDEO ===");
for (Video v : catalogo) {
System.out.println(v.getInfo());
}
}
}
15 changes: 15 additions & 0 deletions bigDecimal/src/VideoStreamingService/Movie.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package VideoStreamingService;

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

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 super.getInfo() + ", Episodi: " + episodes;
}
}
Loading