Correzione verifica informatica maggio
This commit is contained in:
parent
8dceaf0edb
commit
26ec9ddbad
20
corr-verifica-2maggio/Collezione.java
Normal file
20
corr-verifica-2maggio/Collezione.java
Normal file
@ -0,0 +1,20 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Collezione {
|
||||
private String nome;
|
||||
private ArrayList<OperaDArte> opere;
|
||||
|
||||
public Collezione(String nome) {
|
||||
this.nome = nome;
|
||||
opere = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addOpera(OperaDArte o) {
|
||||
opere.add(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return nome + "{" + opere.toString() + "}";
|
||||
}
|
||||
}
|
35
corr-verifica-2maggio/OperaDArte.java
Normal file
35
corr-verifica-2maggio/OperaDArte.java
Normal file
@ -0,0 +1,35 @@
|
||||
public abstract class OperaDArte implements Comparable<OperaDArte> {
|
||||
private String titolo;
|
||||
private String autore;
|
||||
|
||||
public OperaDArte(String titolo, String autore) {
|
||||
this.titolo = titolo;
|
||||
this.autore = autore;
|
||||
}
|
||||
|
||||
|
||||
public abstract double ingombro();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o==null || o.getClass() != getClass()) return false;
|
||||
OperaDArte op = (OperaDArte) o;
|
||||
|
||||
return titolo.equals(op.titolo) && autore.equals(op.autore);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return titolo.hashCode() + autore.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(OperaDArte o) {
|
||||
return Double.compare(ingombro(), o.ingombro());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return titolo + " di " + autore;
|
||||
}
|
||||
}
|
32
corr-verifica-2maggio/Quadro.java
Normal file
32
corr-verifica-2maggio/Quadro.java
Normal file
@ -0,0 +1,32 @@
|
||||
public class Quadro extends OperaDArte {
|
||||
private double larghezza;
|
||||
private double altezza;
|
||||
|
||||
public Quadro(String titolo, String autore, double larghezza, double altezza) {
|
||||
super(titolo, autore);
|
||||
this.larghezza = larghezza;
|
||||
this.altezza = altezza;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double ingombro() {
|
||||
return larghezza * altezza;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + larghezza + "x" + altezza + "(l*h)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(!super.equals(o)) return false;
|
||||
Quadro q = (Quadro) o;
|
||||
return larghezza == q.larghezza && altezza == q.altezza;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() + (int)larghezza + (int)altezza;
|
||||
}
|
||||
}
|
35
corr-verifica-2maggio/Scultura.java
Normal file
35
corr-verifica-2maggio/Scultura.java
Normal file
@ -0,0 +1,35 @@
|
||||
public class Scultura extends OperaDArte {
|
||||
private double larghezza;
|
||||
private double altezza;
|
||||
private double profondita;
|
||||
|
||||
public Scultura(String titolo, String autore, double larghezza, double altezza, double profondita) {
|
||||
super(titolo, autore);
|
||||
|
||||
this.larghezza = larghezza;
|
||||
this.altezza = altezza;
|
||||
this.profondita = profondita;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double ingombro() {
|
||||
return larghezza * altezza * profondita;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + larghezza + "x" + altezza + "x" + profondita + "(l*h*p)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(!super.equals(o)) return false;
|
||||
Scultura s = (Scultura) o;
|
||||
return larghezza == s.larghezza && altezza == s.altezza && profondita == s.profondita;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() + (int)larghezza + (int)altezza + (int)profondita;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user