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
34 changes: 34 additions & 0 deletions CODE_QUALITY_REPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# CODE QUALITY REPORT

## Summary of Changes
Performed a comprehensive analysis of the codebase and addressed various issues ranging from compilation errors to code smells and best practices.

### 1. Error Detection & Resolution
- **Fixed Java Version Mismatches**: Updated `pom.xml` files in `AppDelPorcoDio`, `EsercitazioneVerifica`, and `AuradelPorDios` from Java 25 to Java 21 to match the environment JDK.
- **Resolved Compilation Failures**: All JavaFX projects now compile successfully after the version update.

### 2. Warning Analysis & Cleanup
- **Improved Exception Handling**: Fixed an empty catch block in `ImpiccatoController.java` by adding `printStackTrace()`.
- **Naming Conventions**: Renamed `convertitoreFXML.java` to `ConvertitoreFXML.java` and updated the class name to follow PascalCase.

### 3. Code Quality Improvements
- **Null-Safety in String Comparisons**: Refactored `variable.equals("literal")` to `"literal".equals(variable)` in `HelloController.java` and `Calcolatrice.java` to prevent potential `NullPointerException`.
- **String Literal Extraction**: Extracted repeated string literals (4+ occurrences) into `private static final String` constants in the following files:
- `ConvertitoreController.java` ("Input Error")
- `Esercizi/GestionePC/src/Main.java` ("Windows 11 Pro")
- `Esercizi/Libro/src/Libro.java` (Separators and labels)
- `Laboratorio/Scuola/src/Main.java` ("Stipendio effettivo: €")
- `Laboratorio/Playlist/src/Main.java` ("Trap")

### 4. Metrics
- **Errors Fixed**: 3 (Java version mismatches causing build failures)
- **Code Smells Refactored**: 7+ (String literals, null-safety, naming)
- **Build Status**: 100% Success across all projects.

## Manual Review Required
- **Hardcoded Credentials**: `HelloController.java` contains hardcoded credentials (`admin`/`password123`). While improved for null-safety, these should be moved to a secure configuration or database in a production environment.

## Recommendations for Future Improvements
- **Automated Testing**: Implement JUnit tests for core logic to ensure long-term stability.
- **Dependency Management**: Periodically check for updates to JavaFX and Maven plugins.
- **Resource Management**: Systematically check all I/O operations for proper `try-with-resources` usage.
Original file line number Diff line number Diff line change
@@ -1,89 +1,91 @@
package com.example.convertitorexml;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

public class ConvertitoreController {

// Exchange rate (approximation - 1 EUR = 1.08 USD as of 2026)
private static final double EUR_TO_USD = 1.08;
private static final double USD_TO_EUR = 1 / EUR_TO_USD;

@FXML
private Button btnChiudi;

@FXML
private Button btnDollari;

@FXML
private Button btnEuro;

@FXML
private TextField tfDollari;

@FXML
private TextField tfEuro;


@FXML
void btnChiudiEvent(ActionEvent event) {
System.exit(0);
}

@FXML
void btnDollariEvent(ActionEvent event) {
try {
String dollarText = tfDollari.getText().trim();
if (dollarText.isEmpty()) {
showError("Input Error", "Please enter an amount in dollars.");
return;
}

double dollars = Double.parseDouble(dollarText);
if (dollars < 0) {
showError("Input Error", "Amount cannot be negative.");
return;
}

double euros = dollars * USD_TO_EUR;
tfEuro.setText(String.format("%.2f", euros));

} catch (NumberFormatException e) {
showError("Input Error", "Please enter a valid number.");
}
}

@FXML
void btnEuroEvent(ActionEvent event) {
try {
String euroText = tfEuro.getText().trim();
if (euroText.isEmpty()) {
showError("Input Error", "Please enter an amount in euros.");
return;
}

double euros = Double.parseDouble(euroText);
if (euros < 0) {
showError("Input Error", "Amount cannot be negative.");
return;
}

double dollars = euros * EUR_TO_USD;
tfDollari.setText(String.format("%.2f", dollars));

} catch (NumberFormatException e) {
showError("Input Error", "Please enter a valid number.");
}
}

private void showError(String title, String message) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}
}
package com.example.convertitorexml;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;

public class ConvertitoreController {

private static final String INPUT_ERROR = "Input Error";

// Exchange rate (approximation - 1 EUR = 1.08 USD as of 2026)
private static final double EUR_TO_USD = 1.08;
private static final double USD_TO_EUR = 1 / EUR_TO_USD;

@FXML
private Button btnChiudi;

@FXML
private Button btnDollari;

@FXML
private Button btnEuro;

@FXML
private TextField tfDollari;

@FXML
private TextField tfEuro;


@FXML
void btnChiudiEvent(ActionEvent event) {
System.exit(0);
}

@FXML
void btnDollariEvent(ActionEvent event) {
try {
String dollarText = tfDollari.getText().trim();
if (dollarText.isEmpty()) {
showError(INPUT_ERROR, "Please enter an amount in dollars.");
return;
}

double dollars = Double.parseDouble(dollarText);
if (dollars < 0) {
showError(INPUT_ERROR, "Amount cannot be negative.");
return;
}

double euros = dollars * USD_TO_EUR;
tfEuro.setText(String.format("%.2f", euros));

} catch (NumberFormatException e) {
showError(INPUT_ERROR, "Please enter a valid number.");
}
}

@FXML
void btnEuroEvent(ActionEvent event) {
try {
String euroText = tfEuro.getText().trim();
if (euroText.isEmpty()) {
showError(INPUT_ERROR, "Please enter an amount in euros.");
return;
}

double euros = Double.parseDouble(euroText);
if (euros < 0) {
showError(INPUT_ERROR, "Amount cannot be negative.");
return;
}

double dollars = euros * EUR_TO_USD;
tfDollari.setText(String.format("%.2f", dollars));

} catch (NumberFormatException e) {
showError(INPUT_ERROR, "Please enter a valid number.");
}
}

private void showError(String title, String message) {
Alert alert = new Alert(Alert.AlertType.ERROR);
alert.setTitle(title);
alert.setHeaderText(null);
alert.setContentText(message);
alert.showAndWait();
}
}
14 changes: 8 additions & 6 deletions Esercizi/GestionePC/src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

// Entry point test inventario
public class Main {
private static final String WINDOWS_11_PRO = "Windows 11 Pro";

public static void main(String[] args) {
System.out.println("=== SISTEMA DI GESTIONE INVENTARIO PC ===\n");

Expand All @@ -10,12 +12,12 @@ public static void main(String[] args) {
// desktop
Desktop desk1 = new Desktop(
"Intel Core i7-13700K", 32, 1000,
"Dell", "Optiplex 7090", "Windows 11 Pro",
"Dell", "Optiplex 7090", WINDOWS_11_PRO,
"grande", "NVIDIA RTX 4070", "Realtek ALC897"
);
Desktop desk2 = new Desktop(
"AMD Ryzen 9 5950X", 64, 2000,
"HP", "EliteDesk 800 G9", "Windows 11 Pro",
"HP", "EliteDesk 800 G9", WINDOWS_11_PRO,
"medio", "AMD Radeon RX 7600", "Realtek ALC1220"
);

Expand All @@ -39,7 +41,7 @@ public static void main(String[] args) {
// notebook
Notebook nb1 = new Notebook(
"Intel Core i5-1235U", 16, 512,
"Lenovo", "ThinkPad X1 Carbon Gen 10", "Windows 11 Pro",
"Lenovo", "ThinkPad X1 Carbon Gen 10", WINDOWS_11_PRO,
1.12, 2.2, 31.5, 21.7, 14.0, true,
true, 2.1
);
Expand Down Expand Up @@ -115,9 +117,9 @@ public static void main(String[] args) {
System.out.println(" - " + pc);
}

System.out.println("\n=== TEST: RICERCA PER SISTEMA OPERATIVO (Windows 11 Pro) ===");
List<PC> pcWin11 = inv.cercaPerSistemaOperativo("Windows 11 Pro");
System.out.println("PC con Windows 11 Pro trovati: " + pcWin11.size());
System.out.println("\n=== TEST: RICERCA PER SISTEMA OPERATIVO (" + WINDOWS_11_PRO + ") ===");
List<PC> pcWin11 = inv.cercaPerSistemaOperativo(WINDOWS_11_PRO);
System.out.println("PC con " + WINDOWS_11_PRO + " trovati: " + pcWin11.size());
for (PC pc : pcWin11) {
System.out.println(" - " + pc);
}
Expand Down
Loading