Created
March 2, 2023 08:51
-
-
Save ProfAndreaPollini/448de655774436e347014d667fa466b1 to your computer and use it in GitHub Desktop.
autonoleggio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package autonoleggio; | |
public class App { | |
public static void main(String[] args) { | |
var autoNoleggio = new AutoNoleggio(); | |
System.out.println("all'inizio le auto sono zero"); | |
var auto = autoNoleggio.elencoAuto(); | |
System.out.println(auto.size() == 0); | |
System.out.println("aggiunta auto incrementa auto disponibili"); | |
autoNoleggio.aggiungiAuto("abc","fiat panda","grigino","SUV"); | |
auto = autoNoleggio.elencoAuto(); | |
System.out.println(auto.size() == 1); | |
System.out.println("Rimozione auto"); | |
try { | |
autoNoleggio.rimuoviAuto("abc"); | |
System.out.println(auto.size() == 0); | |
} catch (TargaNonValidaException e) { | |
System.err.println("targa non valida"); | |
} | |
try { | |
autoNoleggio.rimuoviAuto("abc"); | |
System.out.println(auto.size() == 0); | |
} catch (TargaNonValidaException e) { | |
System.out.println(true); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package autonoleggio; | |
public class Auto { | |
private String targa; | |
private final String modello; | |
private String colore; | |
private final String categoria; | |
private boolean occupato; | |
public Auto(String targa, String modello, String colore, String categoria) { | |
this.targa = targa; | |
this.modello = modello; | |
this.colore = colore; | |
this.categoria = categoria; | |
occupato = false; | |
} | |
@Override | |
public String toString() { | |
return "Auto{" + | |
"targa='" + targa + '\'' + | |
", modello='" + modello + '\'' + | |
", colore='" + colore + '\'' + | |
", categoria='" + categoria + '\'' + | |
'}'; | |
} | |
public String getTarga() { | |
return targa; | |
} | |
public void setTarga(String targa) { | |
this.targa = targa; | |
} | |
public String getModello() { | |
return modello; | |
} | |
public String getColore() { | |
return colore; | |
} | |
public void setColore(String colore) { | |
this.colore = colore; | |
} | |
public String getCategoria() { | |
return categoria; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package autonoleggio; | |
import java.time.LocalDate; | |
import java.util.ArrayList; | |
import java.util.HashSet; | |
import java.util.List; | |
import java.util.Set; | |
public class AutoNoleggio { | |
private final Set<Auto> autoDisponibili; | |
private final List<Noleggio> noleggi; | |
public AutoNoleggio() { | |
noleggi = new ArrayList<>(); | |
autoDisponibili = new HashSet<>(); | |
} | |
public Set<Auto> elencoAuto() { | |
return autoDisponibili; | |
} | |
public void aggiungiAuto(String targa, String modello, String colore, String categoria) { | |
var auto = new Auto(targa,modello,colore,categoria); | |
autoDisponibili.add(auto); | |
} | |
public void rimuoviAuto(String targa) throws TargaNonValidaException { | |
Auto autoDaEliminare = cercaAuto(targa); | |
if (autoDaEliminare != null) { | |
autoDisponibili.remove(autoDaEliminare); | |
} else throw new TargaNonValidaException(); | |
} | |
private Auto cercaAuto(String targa) { | |
Auto auto = null; | |
for (var a: | |
autoDisponibili) { | |
if (a.getTarga().equals(targa)) { | |
auto = a; | |
break; | |
} | |
} | |
return auto; | |
} | |
public void noleggiaAuto(String client, LocalDate dataInizio, LocalDate dataFine, String targaAuto) { | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@startuml | |
'https://plantuml.com/class-diagram | |
class NoleggioAuto { | |
autoDisponibili: HashSet<Auto> | |
noleggi: List<Noleggio> | |
+aggiungiAuto(String targa, String modello, String colore, Stringcategoria) | |
+void rimuoviAuto(String targa) | |
+Auto cercaAuto(String targa) | |
+Set<Auto> elencoAuto() | |
+void noleggiaAuto(String nomeCliente, LocalDate dataInizio,LocalDate dataFine, String targaAuto) | |
} | |
class Noleggio { | |
id: int | |
auto: Auto | |
cliente: String | |
inizio: LocalDate | |
fine: LocalDate | |
} | |
class Auto { | |
modello: String | |
colore: String | |
categoria: String | |
occupata: boolean | |
targa: String | |
} | |
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package autonoleggio; | |
public class Noleggio { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package autonoleggio; | |
public class TargaNonValidaException extends Throwable { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment