1 /*
2 Copyright (C) 2013 Alessandro Bugatti (alessandro.bugatti@istruzione.it)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 /*! \file
20 * \brief
21 * \author Alessandro Bugatti
22 * \version 0.1
23 * \date Creazione 1-nov-2014
24 * \date Ultima modifica 1-nov-2014
25 */
26
27 package blocconotetest;
28
29
30 public class BloccoNote {
31 private String nome;
32 private Appunto appunti[];
33 private int quanti;
34 private static final int max = 100;
35 public BloccoNote(String n)
36 {
37 nome = n;
38 appunti = new Appunto[max];
39 quanti = 0;
40 }
41 public void aggiungiAppunto(Appunto a)
42 {
43 if (quanti >= max) return;
44 appunti[quanti] = a;
45 quanti++;
46 }
47
48 public int quanti()
49 {
50 return quanti;
51 }
52
53 public Appunto[] getAppuntiPerImportanza(int imp)
54 {
55 Appunto v[];
56 int cont = 0, j = 0;
57 for (int i = 0; i < quanti; i++)
58 if (appunti[i].getImportanza() == imp)
59 cont++;
60 v = new Appunto[cont];
61 for (int i = 0; i < quanti; i++)
62 if (appunti[i].getImportanza() == imp)
63 {
64 v[j] = new Appunto(appunti[i]);
65 j++;
66 }
67 return v;
68 }
69
70 public Appunto[] getAppuntiOrdinati()
71 {
72 Appunto v[] = new Appunto[quanti];
73 for (int i = 0; i < quanti; i++)
74 v[i] = new Appunto(appunti[i]);
75 for (int i = 0; i < quanti; i++)
76 for (int j = quanti - 1; j > i; j--)
77 if (v[j].getImportanza() > v[j-1].getImportanza())
78 {
79 Appunto temp = v[j];
80 v[j] = v[j-1];
81 v[j-1] = temp;
82 }
83 return v;
84 }
85
86 public void stampaAppunti()
87 {
88 System.out.println("**** Blocco note : " + nome + " *****");
89 for (int i = 0; i < quanti; i++)
90 System.out.println(appunti[i]);
91 }
92
93 }
94