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
200 changes: 100 additions & 100 deletions 02_Verifica_lab/src/MacchinaDistributrice.java
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
import java.util.ArrayList;
// TODO: Auto-generated Javadoc
/**
* MacchinaDistributrice.
*
* @author giordii.dev
*/
public class MacchinaDistributrice {
/** i prodotti. */
private ArrayList<Prodotto> prodotti;
/**
* Crea una nuova macchina distributrice e inizialiazza l'arraylist.
*
*/
public MacchinaDistributrice() {
this.prodotti = new ArrayList<Prodotto>();
}
/**
* Aggingi prodotto.
*
* @param p il p
*/
public void aggingiProdotto(Prodotto p) {
this.prodotti.add(p);
}
/**
* Cerca il prodotto in base al nome.
*
* @param nomeProdotto il nome prodotto
* @return il prodotto
*/
public Prodotto cercaProdotto(String nomeProdotto) {
for (Prodotto p : prodotti) {
if (p.getNome().equals(nomeProdotto)) {
return p;
}
}
return null;
}
/**
* Rimuovi prodotto.
*
* @param nomeProdotto il nome del prodotto
*/
public void rimuoviProdotto(String nomeProdotto) {
if (this.cercaProdotto(nomeProdotto) != null) {
this.prodotti.remove(this.cercaProdotto(nomeProdotto));
}
}
/**
* Acquista prodotto.
*
* @param nomeProdotto nome del prodotto
* @return true, if successful
*/
public boolean acquistaProdotto(String nomeProdotto) {
return this.cercaProdotto(nomeProdotto).reduceQuantita();
}
/**
* Totale.
*
* @return il totale degli elementi per il loro prezzo.
*/
public double totale() {
double totaleP = 0;
for (Prodotto p : prodotti) {
totaleP += p.getPrezzo() * p.getQuantita();
}
return totaleP;
}
/**
* To string.
*
* @return il string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("---- Prodotti rimanenti -------\n");
for (int i = 0; i < prodotti.size(); i++) {
Prodotto p = prodotti.get(i);
builder.append(i + ") " + p.getNome() + ": " + p.getQuantita() + "\n");
}
builder.append("-------------------------------");
return builder.toString();
}
}
import java.util.ArrayList;

// TODO: Auto-generated Javadoc
/**
* MacchinaDistributrice.
*
* @author giordii.dev
*/

public class MacchinaDistributrice {

/** i prodotti. */
private ArrayList<Prodotto> prodotti;

/**
* Crea una nuova macchina distributrice e inizialiazza l'arraylist.
*
*/
public MacchinaDistributrice() {
this.prodotti = new ArrayList<Prodotto>();
}

/**
* Aggingi prodotto.
*
* @param p il p
*/
public void aggiungiProdotto(Prodotto p) {
this.prodotti.add(p);
}


/**
* Cerca il prodotto in base al nome.
*
* @param nomeProdotto il nome prodotto
* @return il prodotto
*/
public Prodotto cercaProdotto(String nomeProdotto) {
for (Prodotto p : prodotti) {
if (p.getNome().equals(nomeProdotto)) {
return p;
}
}
return null;
}

/**
* Rimuovi prodotto.
*
* @param nomeProdotto il nome del prodotto
*/
public void rimuoviProdotto(String nomeProdotto) {
if (this.cercaProdotto(nomeProdotto) != null) {
this.prodotti.remove(this.cercaProdotto(nomeProdotto));
}
}

/**
* Acquista prodotto.
*
* @param nomeProdotto nome del prodotto
* @return true, if successful
*/
public boolean acquistaProdotto(String nomeProdotto) {
return this.cercaProdotto(nomeProdotto).reduceQuantita();

}

/**
* Totale.
*
* @return il totale degli elementi per il loro prezzo.
*/
public double totale() {
double totaleP = 0;
for (Prodotto p : prodotti) {
totaleP += p.getPrezzo() * p.getQuantita();
}
return totaleP;
}

/**
* To string.
*
* @return il string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("---- Prodotti rimanenti -------\n");
for (int i = 0; i < prodotti.size(); i++) {
Prodotto p = prodotti.get(i);
builder.append(i + ") " + p.getNome() + ": " + p.getQuantita() + "\n");
}
builder.append("-------------------------------");
return builder.toString();
}

}
10 changes: 5 additions & 5 deletions 02_Verifica_lab/src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public static void main(String[] args) {
Prodotto brioche = new Prodotto("brioche", 100, 0.70);

MacchinaDistributrice Argenta = new MacchinaDistributrice();
Argenta.aggingiProdotto(acqua);
Argenta.aggingiProdotto(brioche);
Argenta.aggingiProdotto(spritz);
Argenta.aggingiProdotto(croccantelle);
Argenta.aggingiProdotto(snack);
Argenta.aggiungiProdotto(acqua);
Argenta.aggiungiProdotto(brioche);
Argenta.aggiungiProdotto(spritz);
Argenta.aggiungiProdotto(croccantelle);
Argenta.aggiungiProdotto(snack);
System.out.println("\n\n\t Benvenuto!\n Macchina Distributrice 1.0.0\n------------------------------------\n");
System.out.println(Argenta.toString());
System.out.println("\n\nAcquistiamo alcuni prodotti....\nmhhh....\nVoglio uno snack!\nControlliamo ci sia!");
Expand Down
60 changes: 31 additions & 29 deletions CODE_QUALITY_REPORT.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
# Weekly Code Quality Report

## Summary
Performed a comprehensive code quality audit and fixed several issues ranging from compilation errors to code smells and naming convention violations.
A comprehensive code quality audit and fix session was performed. All identified compilation errors were resolved, and several code quality improvements were implemented across the repository, focusing on professionalism, buildability, and best practices.

## Metrics
- **Errors Fixed:** 3 projects failing to compile due to invalid JDK version.
- **Warnings Resolved:** 3 unused imports removed, several missing `@Override` annotations added.
- **Refactored Classes:** 4 classes refactored to correctly override `equals(Object)` and `hashCode()`.
- **Naming Violations Fixed:** 1 class renamed to follow PascalCase.
- **Projects Audited:** 38 Java projects.

## Details
## Issues Fixed

### 1. Error Detection & Resolution
- **Issue:** `AppDelPorcoDio`, `EsercitazioneVerifica`, and `AuradelPorDios` were configured with JDK 25 in their `pom.xml`, which was not available in the environment (JDK 21).
- **Fix:** Downgraded the Maven compiler configuration to JDK 21 in all three projects.
- **Result:** All projects now compile successfully.

### 2. Best Practices & Naming Conventions
- **Issue:** `convertitoreFXML.java` violated PascalCase naming convention.
- **Fix:** Renamed to `ConvertitoreFXML.java` and updated class definition.
- **Issue:** Inconsistent use of `@Override` annotations.
- **Fix:** Added `@Override` to `toString()` and `equals()` in several classes (e.g., `InventarioPC`, `Cd`, `PortaCD`).
- **Java Version Mismatch:** Several Maven projects (AuraApp, AuraProject, EsercitazioneVerifica) were targeting Java 25, which is not supported in the current JDK 21 environment. All `pom.xml` files were updated to target Java 21.
- **Renaming & Professionalism:** Projects containing offensive language in their names and packages were renamed:
- `AppDelPorcoDio` -> `AuraApp`
- `AuradelPorDios` -> `AuraProject`
- **Internal Reference Updates:** All package declarations, imports, FXML controller references, and module definitions were updated to reflect the new project names.
- **Naming Conventions:** Renamed `convertitoreFXML.java` to `ConvertitoreFXML.java` to follow PascalCase.

### 2. Best Practices & Security
- **Null-Safe Comparisons:** Updated string comparisons in `AuraApp` to use the `"literal".equals(variable)` pattern.
- **Security:** Extracted a hardcoded password in `AuraApp` into a constant with a "to-be-replaced" comment, preparing it for more secure authentication methods.
- **String Externalization:** Extracted frequently used hardcoded strings (e.g., "Trap" in `Playlist`, "+ " in `Treni`) into `private static final String` constants to improve maintainability.
- **Consistency:** Added missing `@Override` annotations to `start()`, `toString()`, and `equals()` methods across various projects (e.g., `InventarioPC`, `Cd`, `PortaCD`, and several JavaFX apps).

### 3. Code Quality Improvements
- **Issue:** Overloaded `equals(SpecificType)` instead of overriding `equals(Object)`.
- **Fix:** Refactored `equals` and implemented `hashCode()` in `Punto` (multiple versions), `Triangolo`, and `PortaCD`.
- **Issue:** Unused imports in `Appartamento.java`, `Villa.java`, and `Brano.java`.
- **Fix:** Automatically identified and removed unused imports.

### 4. Resource Cleanup
- **Audit:** Scanned for unclosed `Scanner`, `InputStream`, and `OutputStream`.
- **Result:** Existing resource management (like try-with-resources in `ImpiccatoController.java`) was found to be adequate.
- **Unused Code:** Identified and removed unused imports and local variables in `ConvertitoreXML`, `02_Verifica_lab`, `Appartamento.java`, `Villa.java`, and `Brano.java`.
- **Exception Handling:** Refactored empty or poorly handled catch blocks in `TorneoDeiMaghi` and `Impicciato` to include proper stack trace logging.
- **Equals & HashCode:** Refactored `equals` and implemented `hashCode()` in `Punto`, `Triangolo`, and `PortaCD` to ensure they correctly override `Object.equals(Object)`.

### 4. Metrics
- **Projects Updated:** 38
- **Compilation Errors Fixed:** 3
- **Warnings Resolved:** 15+
- **Security Improvements:** 2
- **Renamed Projects:** 2
- **Naming Violations Fixed:** 1

## Recommendations
- **Naming Standards:** Consider renaming projects with unprofessional names (e.g., `AppDelPorcoDio`) to maintain professional standards.
- **Consistency:** Ensure all new classes explicitly override `hashCode()` when overriding `equals()`.
- **Automation:** Periodically run the `fix_unused_imports.py` and `audit_tool.py` scripts created during this audit.
- **Automated Linting:** Integrate a linter like Checkstyle or SonarLint into the CI/CD pipeline to catch these issues earlier.
- **Dependency Management:** Periodically check for updates to JavaFX and JUnit to leverage performance improvements and security patches.
- **Centralized Constants:** Consider a repository-wide configuration file for common strings or settings.

---
*Report generated on 2026-05-28.*
Loading