Aggiunta di parziale
This commit is contained in:
+129
@@ -0,0 +1,129 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
}
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(ricoverati);
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
|
||||
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
}
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg /
|
||||
}
|
||||
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer>
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return (Double) (avg / pazienti.size());
|
||||
}
|
||||
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
return pazienti1 - pazienti2;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
|
||||
}
|
||||
}
|
||||
+168
@@ -0,0 +1,168 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
cliniche.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
return pazienti1 - pazienti2;
|
||||
}
|
||||
});
|
||||
|
||||
return cliniche;
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if ()
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iter
|
||||
}
|
||||
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
|
||||
}
|
||||
}
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente
|
||||
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
}
|
||||
|
||||
}
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+139
@@ -0,0 +1,139 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
Iterator<Paziente> fixedIt = ricoveratiOrdinati.keySet().iterator();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp =
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else
|
||||
}
|
||||
}
|
||||
}
|
||||
+145
@@ -0,0 +1,145 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
|
||||
}
|
||||
}
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0)
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iter
|
||||
}
|
||||
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
}
|
||||
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put();
|
||||
}
|
||||
}
|
||||
}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente>
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
|
||||
}
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iter
|
||||
}
|
||||
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente>
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
return c1 - c2;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
if () {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> ) {
|
||||
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return (Double) (avg / pazienti.size());
|
||||
}
|
||||
|
||||
}
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare() {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put();
|
||||
}
|
||||
}
|
||||
}
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
Iterator<String>
|
||||
|
||||
}
|
||||
}
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
return
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+141
@@ -0,0 +1,141 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
Iterator<Paziente> fixedIt = ricoveratiOrdinati.keySet().iterator();
|
||||
while (fixedIt.hasNext()) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+79
@@ -0,0 +1,79 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
}
|
||||
|
||||
}
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
}
|
||||
+147
@@ -0,0 +1,147 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ordinatiPerCodice(){
|
||||
|
||||
}
|
||||
}
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
if (cmp == 0) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it =
|
||||
}
|
||||
}
|
||||
+151
@@ -0,0 +1,151 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if ()
|
||||
}
|
||||
}
|
||||
}
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare() {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new Map<Integer, Integer>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return false;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null)
|
||||
}
|
||||
}
|
||||
}
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
}
|
||||
}
|
||||
+148
@@ -0,0 +1,148 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+127
@@ -0,0 +1,127 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String>
|
||||
}
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
}
|
||||
}
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
clinica.sort(new Comparator<Clinica>() {
|
||||
@Override
|
||||
public int compare(Clinica c1, Clinica c2) {
|
||||
int pazienti1 = c1.pazienti.size();
|
||||
int pazienti2 = c2.pazienti.size();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear =
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
}
|
||||
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
|
||||
}
|
||||
+128
@@ -0,0 +1,128 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente> {
|
||||
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List ordinaListaClinicaPerNumeroPazienti() {
|
||||
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(current);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+124
@@ -0,0 +1,124 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
if ()
|
||||
}
|
||||
}
|
||||
+83
@@ -0,0 +1,83 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public Double etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0.0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+105
@@ -0,0 +1,105 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
|
||||
}
|
||||
}
|
||||
+142
@@ -0,0 +1,142 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
|
||||
ricoveratiOrdinati.put(current, cf);
|
||||
}
|
||||
|
||||
Iterator<Paziente> fixedIt = ricoveratiOrdinati.keySet().iterator();
|
||||
while (fixedIt.hasNext()) {
|
||||
ricoverati.add(fixedIt.next());
|
||||
}
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>(pazienti);
|
||||
|
||||
ricoverati.sort(new Comparator<Paziente>() {
|
||||
@Override
|
||||
public int compare(Paziente p1, Paziente p2) {
|
||||
String id1 = p1.getId();
|
||||
String id2 = p2.getId();
|
||||
return id1.compareTo(id2);
|
||||
}
|
||||
});
|
||||
|
||||
return ricoverati;
|
||||
}
|
||||
|
||||
// 7. Distribuzione pazienti per anno di nascita
|
||||
public Map<Integer, Integer> pazientiPerAnnoDiNascita() {
|
||||
// AnnoNascita, NumeroPazienti
|
||||
Map<Integer, Integer> pazientiPerAnnoDiNascita = new TreeMap<Integer, Integer>(); // Si usa TreeMap per avere una vista già ordinata di anni
|
||||
|
||||
if (pazienti.isEmpty()) return pazientiPerAnnoDiNascita;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int annoNascita = current.getAnnoNascita();
|
||||
|
||||
if (pazientiPerAnnoDiNascita.get(annoNascita) == null) pazientiPerAnnoDiNascita.put(annoNascita, 1);
|
||||
else pazientiPerAnnoDiNascita.put(annoNascita, pazientiPerAnnoDiNascita.get(annoNascita) + 1);
|
||||
}
|
||||
|
||||
return pazientiPerAnnoDiNascita;
|
||||
}
|
||||
|
||||
public static List<Clinica> ordinaListaClinicaPerNumeroPazienti(List <Clinica> cliniche) {
|
||||
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
package parziale.p251110;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.ListIterator;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Clinica {
|
||||
|
||||
ArrayList<Paziente> pazienti = new ArrayList<Paziente>();
|
||||
|
||||
// 1. Numero di pazienti Ricoverati
|
||||
public int pazientiRicoverati() {
|
||||
return pazienti.size();
|
||||
}
|
||||
|
||||
// 2. Inserimento del paziente
|
||||
/*
|
||||
* Dal momento che non ci è permesso adoperare
|
||||
* TreeSet per l'ordine e per l'unicità
|
||||
*/
|
||||
public boolean ricoveraPaziente(Paziente paziente) {
|
||||
// Se il paziente è nullo, nulla verrà aggiunto
|
||||
if (paziente == null) return false;
|
||||
|
||||
// Controllo se il paziente è già presente nella lista ricoveri
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
if (paziente.equals(current)) return false; // Se è già presente un paziente con id uguale allora non viene aggiunto e ritorna false
|
||||
}
|
||||
|
||||
// Aggiunta del paziente
|
||||
ListIterator<Paziente> lit = pazienti.listIterator();
|
||||
while (lit.hasNext()) {
|
||||
Paziente current = lit.next();
|
||||
int cmp = current.compareTo(paziente);
|
||||
if (cmp > 0) {
|
||||
lit.previous();
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
lit.add(paziente);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. Dimissione
|
||||
public Paziente dimettiPaziente(String id, int annoNascita) {
|
||||
if (id == null || annoNascita <= 0) return null;
|
||||
Paziente tmp = new Paziente(id, annoNascita);
|
||||
|
||||
Iterator<Paziente> iterator = pazienti.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Paziente current = iterator.next();
|
||||
int cmp = current.compareTo(tmp);
|
||||
if (cmp == 0) {
|
||||
// Paziente da rimuovere
|
||||
iterator.remove();
|
||||
return current;
|
||||
}
|
||||
if (cmp > 0) return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. Età media
|
||||
public int etaMedia() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
int avg = 0;
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
int ageYear = currentDate - it.next().getAnnoNascita();
|
||||
avg += ageYear;
|
||||
}
|
||||
|
||||
return avg / pazienti.size();
|
||||
}
|
||||
|
||||
// 5. Età più rappresenta
|
||||
public int etaMediaPiuRappresentata() {
|
||||
if (pazienti.isEmpty()) return 0;
|
||||
|
||||
int currentDate = LocalDate.now().getYear();
|
||||
TreeMap<Integer, Integer> listaEta = new TreeMap<Integer, Integer>();
|
||||
|
||||
Iterator<Paziente> it = pazienti.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
int currentAge = currentDate - current.getAnnoNascita();
|
||||
|
||||
if (listaEta.get(currentAge) == null) listaEta.put(currentAge, 1);
|
||||
else listaEta.put(currentAge, listaEta.get(currentAge) + 1);
|
||||
}
|
||||
|
||||
int maxAge = 0;
|
||||
int maxFrequency = 0;
|
||||
|
||||
for (Integer i : listaEta.keySet()) {
|
||||
int currentFrequency = listaEta.get(i);
|
||||
|
||||
if (currentFrequency > maxFrequency) {
|
||||
maxFrequency = currentFrequency;
|
||||
maxAge = i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return maxAge;
|
||||
}
|
||||
|
||||
// 6. Ricoverati ordinati per codice
|
||||
public ArrayList<Paziente> ricoveratiOrdinatiPerCodice() {
|
||||
ArrayList<Paziente> ricoverati = new ArrayList<Paziente>();
|
||||
|
||||
// Se non vi sono pazienti, restituisci un ArrayList<Paziente> vuoto.
|
||||
if (pazienti.isEmpty()) return ricoverati;
|
||||
|
||||
TreeMap<Paziente, String> ricoveratiOrdinati = new TreeMap<Paziente, String>();
|
||||
|
||||
Iterator<Paziente> it = ricoverati.iterator();
|
||||
while (it.hasNext()) {
|
||||
Paziente current = it.next();
|
||||
String cf = current.getId();
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user