Pulizia delle cose inutili
This commit is contained in:
@@ -12,7 +12,6 @@ import com.googlecode.lanterna.gui2.BasicWindow;
|
||||
import com.googlecode.lanterna.gui2.Button;
|
||||
import com.googlecode.lanterna.gui2.Direction;
|
||||
import com.googlecode.lanterna.gui2.EmptySpace;
|
||||
import com.googlecode.lanterna.gui2.GridLayout;
|
||||
import com.googlecode.lanterna.gui2.Label;
|
||||
import com.googlecode.lanterna.gui2.LinearLayout;
|
||||
import com.googlecode.lanterna.gui2.Panel;
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.googlecode.lanterna.gui2.MultiWindowTextGUI;
|
||||
@@ -38,76 +37,6 @@ public class GradeAnalyzer {
|
||||
static boolean isEmpty = true;
|
||||
static ArrayList<Valutazione> valutazioni = valutazioniDaFile();
|
||||
|
||||
/*
|
||||
* public static void main(String[] args) {
|
||||
* int scelta = -1;
|
||||
*
|
||||
* do {
|
||||
* System.out.println("Scegliere un'opzione:");
|
||||
* System.out.println("1. Inserisci dati alunno");
|
||||
* System.out.println("2. Trova voto più alto e più basso");
|
||||
* System.out.println("3. Promossi");
|
||||
* System.out.println("0. Esci");
|
||||
* System.out.print("Opzione: ");
|
||||
*
|
||||
* try {
|
||||
* scelta = sc.nextInt();
|
||||
* sc.nextLine();
|
||||
*
|
||||
* switch (scelta) {
|
||||
* case 0:
|
||||
* break;
|
||||
* case 1:
|
||||
* isSaved = false;
|
||||
* isEmpty = false;
|
||||
* inserisciDati();
|
||||
* System.out.println("Studente aggiunto correttamente.");
|
||||
* pausa();
|
||||
* break;
|
||||
* case 2:
|
||||
* if (isEmpty) {
|
||||
* System.out.println(
|
||||
* "Errore: inserire almeno la valutazione di uno studente prima di proseguire."
|
||||
* );
|
||||
* } else {
|
||||
* if (!isSaved) {
|
||||
* System.out.println("Attenzione: ci sono dati non salvati.");
|
||||
* salvaValutazioni();
|
||||
* }
|
||||
* trovaMigliorePeggiore();
|
||||
* }
|
||||
* pausa();
|
||||
* break;
|
||||
* case 3:
|
||||
* if (isEmpty) {
|
||||
* System.out.println(
|
||||
* "Errore: inserire almeno la valutazione di uno studente prima di proseguire."
|
||||
* );
|
||||
* } else {
|
||||
* if (!isSaved) {
|
||||
* System.out.println("Attenzione: ci sono dati non salvati.");
|
||||
* System.out.println("Verranno salvati automaticamente.");
|
||||
* salva(valutazioni, PATH_VOTI);
|
||||
* valutazioni = valutazioniDaFile();
|
||||
* isSaved = true;
|
||||
* }
|
||||
* promossi();
|
||||
* }
|
||||
* pausa();
|
||||
* break;
|
||||
* default:
|
||||
* System.out.println(ERRORE_GENERICO);
|
||||
* pausa();
|
||||
* break;
|
||||
* }
|
||||
* } catch (InputMismatchException _) {
|
||||
* System.out.println("Errore: scelta non valida.");
|
||||
* pausa();
|
||||
* }
|
||||
* } while (scelta != 0);
|
||||
* }
|
||||
*/
|
||||
|
||||
public static void main(String[] args) {
|
||||
try (Screen schermo = new TerminalScreen(new DefaultTerminalFactory().createTerminal())) {
|
||||
schermo.startScreen(); // crea terminale, inserisci CRT e dai corrente
|
||||
@@ -123,77 +52,6 @@ public class GradeAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
/* public static void pausa() {
|
||||
System.out.println("Premere un tasto per continuare. . .");
|
||||
sc.nextLine();
|
||||
} */
|
||||
|
||||
/* static void inserisciDati() {
|
||||
String nome;
|
||||
String cognome;
|
||||
double voto;
|
||||
String scelta;
|
||||
boolean exit;
|
||||
int posizione;
|
||||
|
||||
System.out.print("Inserisci il nome: ");
|
||||
nome = sc.nextLine().trim();
|
||||
|
||||
System.out.print("Inserisci il cognome: ");
|
||||
cognome = sc.nextLine().trim();
|
||||
|
||||
voto = voto();
|
||||
|
||||
if ((posizione = exists(nome, cognome, valutazioni)) != -1) {
|
||||
System.out.println("Attenzione: lo studente esiste già.");
|
||||
do {
|
||||
exit = true;
|
||||
System.out.print("Aggiornarne i dati [S/N]? ");
|
||||
scelta = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
switch (scelta) {
|
||||
case "s":
|
||||
valutazioni.get(posizione).setVoto(voto);
|
||||
break;
|
||||
case "n":
|
||||
System.out.println("Lo studente non è stato aggiornato.");
|
||||
break;
|
||||
default:
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
pausa();
|
||||
exit = false;
|
||||
}
|
||||
} while (!exit);
|
||||
} else {
|
||||
valutazioni.add(new Valutazione(nome, cognome, voto));
|
||||
}
|
||||
|
||||
salvaValutazioni();
|
||||
} */
|
||||
|
||||
/* static double voto() {
|
||||
double voto;
|
||||
boolean error;
|
||||
final double VOTO_MINIMO = 1;
|
||||
final double VOTO_MASSIMO = 10;
|
||||
|
||||
do {
|
||||
error = false;
|
||||
System.out.print("Inserisci il voto: ");
|
||||
voto = Math.round((sc.nextDouble() * 10) / 10);
|
||||
sc.nextLine();
|
||||
|
||||
if (voto < VOTO_MINIMO || voto > VOTO_MASSIMO) {
|
||||
System.out.println(
|
||||
"Errore: il voto deve essere compreso tra " + VOTO_MINIMO + " e " + VOTO_MASSIMO + ".");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
|
||||
return voto;
|
||||
} */
|
||||
|
||||
static ArrayList<Valutazione> valutazioniDaFile() {
|
||||
ArrayList<Valutazione> valutazioni = new ArrayList<>();
|
||||
|
||||
@@ -231,44 +89,6 @@ public class GradeAnalyzer {
|
||||
return valutazioni;
|
||||
}
|
||||
|
||||
/* static int exists(String nome, String cognome, ArrayList<Valutazione> valutazioni) {
|
||||
boolean exit = false;
|
||||
int posizione = -1;
|
||||
for (int i = 0; i < valutazioni.size() && !exit; i++) {
|
||||
if (nome.equalsIgnoreCase(valutazioni.get(i).getNome())
|
||||
&& cognome.equalsIgnoreCase(valutazioni.get(i).getCognome())) {
|
||||
posizione = i;
|
||||
exit = true;
|
||||
}
|
||||
}
|
||||
return posizione;
|
||||
} */
|
||||
|
||||
/* static void salvaValutazioni() {
|
||||
boolean exit;
|
||||
String scelta;
|
||||
do {
|
||||
exit = true;
|
||||
System.out.print("Salvare i dati [S/N]? ");
|
||||
scelta = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
switch (scelta) {
|
||||
case "s":
|
||||
salva(valutazioni, PATH_VOTI);
|
||||
valutazioni = valutazioniDaFile();
|
||||
isSaved = true;
|
||||
break;
|
||||
case "n":
|
||||
System.out.println("I dati non sono stati salvati.");
|
||||
break;
|
||||
default:
|
||||
System.out.println(ERRORE_GENERICO);
|
||||
pausa();
|
||||
exit = false;
|
||||
}
|
||||
} while (!exit);
|
||||
} */
|
||||
|
||||
static String salva(ArrayList<Valutazione> valutazioni, String path) {
|
||||
String messaggio = null;
|
||||
try (BufferedWriter bw = new BufferedWriter(new FileWriter(path))) {
|
||||
@@ -290,61 +110,4 @@ public class GradeAnalyzer {
|
||||
|
||||
return messaggio;
|
||||
}
|
||||
|
||||
/* 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])));
|
||||
}
|
||||
}*/
|
||||
|
||||
static void promossi() {
|
||||
final int MINIMO_PROMOZIONE = 6;
|
||||
String stringaFormattazione = "%-20s%-20s%-20s";
|
||||
ArrayList<Valutazione> promossi = new ArrayList<>();
|
||||
ArrayList<Valutazione> copiaValutazioni = new ArrayList<>();
|
||||
for (Valutazione valutazione : valutazioni) {
|
||||
copiaValutazioni.add(valutazione);
|
||||
}
|
||||
|
||||
Collections.sort(copiaValutazioni);
|
||||
|
||||
for (Valutazione valutazione : copiaValutazioni) {
|
||||
if (valutazione.getVoto() >= MINIMO_PROMOZIONE) {
|
||||
promossi.add(valutazione);
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("\nTutte le valutazioni dei promossi, in ordine crescente:\n");
|
||||
System.out.println(String.format(stringaFormattazione, "Nome", "Cognome", "Voto"));
|
||||
for (int i = 0; i < promossi.size(); i++) {
|
||||
System.out.println(String.format(stringaFormattazione, promossi.get(i).getNome(),
|
||||
promossi.get(i).getCognome(), Double.toString(promossi.get(i).getVoto())));
|
||||
}
|
||||
|
||||
salva(promossi, PATH_PROMOSSI);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user