Opzione 2 + correzioni
This commit is contained in:
@@ -10,6 +10,7 @@ import java.io.FileReader;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
@@ -28,7 +29,7 @@ public class GradeAnalyzer {
|
|||||||
static final String PATH_PROMOSSI = "./src/gradeanalyzer/data/promossi.txt";
|
static final String PATH_PROMOSSI = "./src/gradeanalyzer/data/promossi.txt";
|
||||||
static final String ERRORE_GENERICO = "Opzione non valida.";
|
static final String ERRORE_GENERICO = "Opzione non valida.";
|
||||||
static ArrayList<Valutazione> valutazioni = valutazioniDaFile();
|
static ArrayList<Valutazione> valutazioni = valutazioniDaFile();
|
||||||
static boolean isSaved;
|
static boolean isSaved = true;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int scelta = -1;
|
int scelta = -1;
|
||||||
@@ -55,7 +56,11 @@ public class GradeAnalyzer {
|
|||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
if (!isSaved) {
|
||||||
|
System.out.println("Attenzione: ci sono dati non salvati.");
|
||||||
|
salva();
|
||||||
|
}
|
||||||
|
trovaMigliorePeggiore();
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
@@ -169,7 +174,7 @@ public class GradeAnalyzer {
|
|||||||
boolean exit = false;
|
boolean exit = false;
|
||||||
int posizione = -1;
|
int posizione = -1;
|
||||||
for (int i = 0; i < valutazioni.size() && !exit; i++) {
|
for (int i = 0; i < valutazioni.size() && !exit; i++) {
|
||||||
if (nome.equals(valutazioni.get(i).getNome()) && cognome.equals(valutazioni.get(i).getCognome())) {
|
if (nome.equalsIgnoreCase(valutazioni.get(i).getNome()) && cognome.equalsIgnoreCase(valutazioni.get(i).getCognome())) {
|
||||||
posizione = i;
|
posizione = i;
|
||||||
exit = true;
|
exit = true;
|
||||||
}
|
}
|
||||||
@@ -216,4 +221,34 @@ public class GradeAnalyzer {
|
|||||||
}
|
}
|
||||||
} while (!exit);
|
} while (!exit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void trovaMigliorePeggiore() {
|
||||||
|
ArrayList<Valutazione> copiaValutazioni = new ArrayList<>();
|
||||||
|
for (Valutazione valutazione : valutazioni) {
|
||||||
|
copiaValutazioni.add(valutazione);
|
||||||
|
}
|
||||||
|
String[] nomi = new String[valutazioni.size()];
|
||||||
|
String[] cognomi = new String[valutazioni.size()];
|
||||||
|
double[] voti = new double[valutazioni.size()];
|
||||||
|
String stringaFormattazione = "%-20s%-20s%-20s";
|
||||||
|
|
||||||
|
Collections.sort(copiaValutazioni);
|
||||||
|
|
||||||
|
for (int i = 0; i < copiaValutazioni.size(); i++) {
|
||||||
|
nomi[i] = copiaValutazioni.get(i).getNome();
|
||||||
|
cognomi[i] = copiaValutazioni.get(i).getCognome();
|
||||||
|
voti[i] = copiaValutazioni.get(i).getVoto();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Voto migliore:");
|
||||||
|
System.out.println(copiaValutazioni.get(copiaValutazioni.size() - 1).toString());
|
||||||
|
System.out.println("\nVoto peggiore:");
|
||||||
|
System.out.println(copiaValutazioni.get(0).toString());
|
||||||
|
|
||||||
|
System.out.println("\nTutte le valutazioni, in ordine crescente:\n");
|
||||||
|
System.out.println(String.format(stringaFormattazione, "Nome", "Cognome", "Voto"));
|
||||||
|
for (int i = 0; i < nomi.length; i++) {
|
||||||
|
System.out.println(String.format(stringaFormattazione, nomi[i], cognomi[i], Double.toString(voti[i])));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ package gradeanalyzer;
|
|||||||
*
|
*
|
||||||
* @author Verde
|
* @author Verde
|
||||||
*/
|
*/
|
||||||
public class Valutazione {
|
public class Valutazione implements Comparable<Valutazione> {
|
||||||
private String nome;
|
private String nome;
|
||||||
private String cognome;
|
private String cognome;
|
||||||
private double voto;
|
private double voto;
|
||||||
@@ -35,4 +35,54 @@ public class Valutazione {
|
|||||||
return voto;
|
return voto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Nome: " + this.nome
|
||||||
|
+ "\nCognome: " + this.cognome
|
||||||
|
+ "\nVoto: " + this.voto;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Valutazione altraValutazione) {
|
||||||
|
return Double.compare(this.voto, altraValutazione.getVoto());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
boolean equals = true;
|
||||||
|
if (obj == null) {
|
||||||
|
equals = false;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (obj.getClass() != this.getClass()) {
|
||||||
|
equals = false;
|
||||||
|
} else {
|
||||||
|
final Valutazione altraValutazione = (Valutazione) obj;
|
||||||
|
if ((this.nome == null) ? (altraValutazione.nome != null) : !this.nome.equals(altraValutazione.nome)) {
|
||||||
|
equals = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((this.cognome == null) ? (altraValutazione.cognome != null)
|
||||||
|
: !this.cognome.equals(altraValutazione.cognome)) {
|
||||||
|
equals = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.voto != altraValutazione.voto) {
|
||||||
|
equals = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return equals;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 3;
|
||||||
|
hash = 53 * hash + (this.nome != null ? this.nome.hashCode() : 0);
|
||||||
|
hash = 53 * hash + (this.cognome != null ? this.cognome.hashCode() : 0);
|
||||||
|
hash = 53 * hash + Double.hashCode(this.voto);
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user