Merge branch 'master' of gitea.it:gicorada/java-scuola
This commit is contained in:
commit
22ac8bce33
24
InsOrd/Studente.java
Normal file
24
InsOrd/Studente.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
public class Studente implements Comparable<Studente>{
|
||||||
|
private String nome;
|
||||||
|
private String cognome;
|
||||||
|
private double media;
|
||||||
|
private int eta;
|
||||||
|
|
||||||
|
public Studente(String nome, String cognome, double media, int eta) {
|
||||||
|
this.nome = nome;
|
||||||
|
this.cognome = cognome;
|
||||||
|
this.media = media;
|
||||||
|
this.eta = eta;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Studente o) {
|
||||||
|
if(this.cognome.equals(o.cognome)) return this.nome.compareTo(o.nome);
|
||||||
|
return this.cognome.compareTo(o.cognome);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return nome + " " + cognome + " media=" + media + " eta=" + eta;
|
||||||
|
}
|
||||||
|
}
|
BIN
InsOrd/Studente.pdf
Normal file
BIN
InsOrd/Studente.pdf
Normal file
Binary file not shown.
36
InsOrd/Test.java
Normal file
36
InsOrd/Test.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class Test {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner in = new Scanner(System.in);
|
||||||
|
ArrayList<Studente> lista = new ArrayList<>();
|
||||||
|
|
||||||
|
while(in.hasNextLine()) {
|
||||||
|
Studente s = new Studente(in.next(), in.next(), in.nextDouble(), in.nextInt());
|
||||||
|
insert(lista, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Studente s: lista) {
|
||||||
|
System.out.println(s.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void insert(ArrayList<Studente> l, Studente s) {
|
||||||
|
if(l.size() == 0) {
|
||||||
|
l.add(s);
|
||||||
|
} else {
|
||||||
|
boolean ins = false;
|
||||||
|
for(int i = 0; i < l.size(); i++) {
|
||||||
|
if(s.compareTo(l.get(i)) < 0) {
|
||||||
|
l.add(i, s);
|
||||||
|
ins = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!ins) {
|
||||||
|
l.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
InsOrd/Test.pdf
Normal file
BIN
InsOrd/Test.pdf
Normal file
Binary file not shown.
6
InsOrd/input.txt
Normal file
6
InsOrd/input.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
AAA BBB 1 4
|
||||||
|
BBB AAA 2 2
|
||||||
|
CCC DDD 3 6
|
||||||
|
ABC AAA 4 1
|
||||||
|
BZZ AAA 5 3
|
||||||
|
BBB CCC 6 5
|
Loading…
x
Reference in New Issue
Block a user