diff --git a/6.x/e6.7/E67.java~ b/6.x/e6.7/E67.java~ deleted file mode 100644 index 99aaea5..0000000 --- a/6.x/e6.7/E67.java~ +++ /dev/null @@ -1,25 +0,0 @@ -import java.util.Scanner; -import java.util.Random; - -public class E67 { - public static void main(String[] args) { - Scanner in = new Scanner(System.in); - Random generator = new Random(); - int i, j; - System.out.print("Inserisci una parola: "); - String word = in.next(); - - for(int k = 0; k < word.length(); k++) { - String first, middle, last; - i = generator.nextInt(word.length()); - j = generator.nextInt(word.length() - i) + i; - - first = word.substring(0, i); - middle = word.substring(i, j); - last = word.substring(j, word.length()); - - word = first + word.chatAt(j) + middle + word.charAt(i) + last; - } - System.out.println(first+middle+last); - } -} diff --git a/InsOrd/Studente.java b/InsOrd/Studente.java new file mode 100644 index 0000000..19b514f --- /dev/null +++ b/InsOrd/Studente.java @@ -0,0 +1,24 @@ +public class Studente implements Comparable{ + 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; + } +} diff --git a/InsOrd/Studente.pdf b/InsOrd/Studente.pdf new file mode 100644 index 0000000..b574467 Binary files /dev/null and b/InsOrd/Studente.pdf differ diff --git a/InsOrd/Test.java b/InsOrd/Test.java new file mode 100644 index 0000000..9c2ef28 --- /dev/null +++ b/InsOrd/Test.java @@ -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 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 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); + } + } + } +} diff --git a/InsOrd/Test.pdf b/InsOrd/Test.pdf new file mode 100644 index 0000000..f86ad72 Binary files /dev/null and b/InsOrd/Test.pdf differ diff --git a/InsOrd/input.txt b/InsOrd/input.txt new file mode 100644 index 0000000..d1cdba9 --- /dev/null +++ b/InsOrd/input.txt @@ -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 \ No newline at end of file