Compare commits
9 Commits
main
...
progettoDe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6eb6cf3c09 | ||
|
|
7e1ebd31c4 | ||
|
|
d14071be53 | ||
|
|
3013655cb4 | ||
|
|
c1c74e3805 | ||
|
|
61a485c92b | ||
|
|
34cd28cfe7 | ||
|
|
3e8f99e2d9 | ||
|
|
0229a21f3b |
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/build/
|
||||||
0
nbproject/private/config.properties
Normal file
0
nbproject/private/config.properties
Normal file
@@ -1,3 +1,9 @@
|
|||||||
compile.on.save=true
|
compile.on.save=true
|
||||||
|
do.depend=false
|
||||||
|
do.jar=true
|
||||||
|
do.jlink=false
|
||||||
|
javac.debug=true
|
||||||
|
javadoc.preview=true
|
||||||
|
jlink.strip=false
|
||||||
user.properties.file=/home/Verde/.netbeans/28/build.properties
|
user.properties.file=/home/Verde/.netbeans/28/build.properties
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
annotation.processing.processor.options=
|
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
annotation.processing.run.all.processors=true
|
annotation.processing.run.all.processors=true
|
||||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
|
application.title=MyBank
|
||||||
|
application.vendor=Verde
|
||||||
build.classes.dir=${build.dir}/classes
|
build.classes.dir=${build.dir}/classes
|
||||||
build.classes.excludes=**/*.java,**/*.form
|
build.classes.excludes=**/*.java,**/*.form
|
||||||
# This directory is removed when the project is cleaned:
|
# This directory is removed when the project is cleaned:
|
||||||
@@ -32,15 +33,24 @@ dist.jar=${dist.dir}/MyBank.jar
|
|||||||
dist.javadoc.dir=${dist.dir}/javadoc
|
dist.javadoc.dir=${dist.dir}/javadoc
|
||||||
dist.jlink.dir=${dist.dir}/jlink
|
dist.jlink.dir=${dist.dir}/jlink
|
||||||
dist.jlink.output=${dist.jlink.dir}/MyBank
|
dist.jlink.output=${dist.jlink.dir}/MyBank
|
||||||
|
endorsed.classpath=
|
||||||
excludes=
|
excludes=
|
||||||
|
file.reference.jackson-annotations-3.0-rc5.jar=lib/jackson-annotations-3.0-rc5.jar
|
||||||
|
file.reference.jackson-core-2.20.1.jar=lib/jackson-core-2.20.1.jar
|
||||||
|
file.reference.jackson-databind-2.20.1.jar=lib/jackson-databind-2.20.1.jar
|
||||||
|
file.reference.MyBank-lib=lib
|
||||||
includes=**
|
includes=**
|
||||||
jar.compress=false
|
jar.compress=false
|
||||||
javac.classpath=
|
javac.classpath=\
|
||||||
|
${file.reference.jackson-databind-2.20.1.jar}:\
|
||||||
|
${file.reference.jackson-annotations-3.0-rc5.jar}:\
|
||||||
|
${file.reference.jackson-core-2.20.1.jar}
|
||||||
# Space-separated list of extra javac options
|
# Space-separated list of extra javac options
|
||||||
javac.compilerargs=
|
javac.compilerargs=
|
||||||
javac.deprecation=false
|
javac.deprecation=false
|
||||||
javac.external.vm=true
|
javac.external.vm=true
|
||||||
javac.modulepath=
|
javac.modulepath=\
|
||||||
|
${file.reference.MyBank-lib}
|
||||||
javac.processormodulepath=
|
javac.processormodulepath=
|
||||||
javac.processorpath=\
|
javac.processorpath=\
|
||||||
${javac.classpath}
|
${javac.classpath}
|
||||||
@@ -84,6 +94,7 @@ run.classpath=\
|
|||||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||||
run.jvmargs=
|
run.jvmargs=
|
||||||
run.modulepath=\
|
run.modulepath=\
|
||||||
|
${file.reference.MyBank-lib}:\
|
||||||
${javac.modulepath}
|
${javac.modulepath}
|
||||||
run.test.classpath=\
|
run.test.classpath=\
|
||||||
${javac.test.classpath}:\
|
${javac.test.classpath}:\
|
||||||
|
|||||||
@@ -4,95 +4,70 @@
|
|||||||
*/
|
*/
|
||||||
package mybank;
|
package mybank;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Verde
|
* @author Verde
|
||||||
*/
|
*/
|
||||||
public class ContoCorrente {
|
public class ContoCorrente {
|
||||||
private String nome;
|
private Persona intestatario;
|
||||||
private String cognome;
|
|
||||||
private String codiceFiscale;
|
|
||||||
private double saldo;
|
private double saldo;
|
||||||
private int numeroContoCorrente;
|
private int numeroContoCorrente;
|
||||||
|
|
||||||
private static ArrayList<Integer> numeriContiCorrenti = new ArrayList<>();
|
private static int totaleNumeriCorrenti;
|
||||||
|
|
||||||
@JsonFormat
|
|
||||||
(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
|
|
||||||
private Date dataDiNascita;
|
|
||||||
|
|
||||||
public ContoCorrente() {
|
public ContoCorrente() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ContoCorrente(String nome, String cognome, String codiceFiscale, Date dataDiNascita, double saldo,
|
public ContoCorrente(Persona intestatario, double saldo) {
|
||||||
int numeroContoCorrente) {
|
this.intestatario = intestatario;
|
||||||
this.nome = nome;
|
|
||||||
this.cognome = cognome;
|
|
||||||
this.codiceFiscale = codiceFiscale;
|
|
||||||
this.dataDiNascita = dataDiNascita;
|
|
||||||
this.saldo = saldo;
|
this.saldo = saldo;
|
||||||
this.numeroContoCorrente = numeroContoCorrente;
|
this.numeroContoCorrente = totaleNumeriCorrenti++;
|
||||||
numeriContiCorrenti.add(numeroContoCorrente);
|
ScriviLeggiFile.log("Apertura del conto con saldo iniziale di " + this.saldo, numeroContoCorrente);
|
||||||
MyBank.log("Apertura del conto con saldo iniziale di " + this.saldo, numeroContoCorrente);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Integer> getNumeriContiCorrenti() {
|
|
||||||
return numeriContiCorrenti;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setNumeriContiCorrenti(List<Integer> numeriContiCorrenti) {
|
|
||||||
ContoCorrente.numeriContiCorrenti = (ArrayList<Integer>)numeriContiCorrenti;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumeroContoCorrente() {
|
public int getNumeroContoCorrente() {
|
||||||
return numeroContoCorrente;
|
return numeroContoCorrente;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void versa(double quantita){
|
public static int getTotaleNumeriCorrenti() {
|
||||||
this.saldo += quantita;
|
return totaleNumeriCorrenti;
|
||||||
MyBank.log("Versamento di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
|
|
||||||
logSaldoCorrente();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void preleva(double quantita) throws IllegalArgumentException{
|
public Persona getIntestatario() {
|
||||||
if (quantita > this.saldo) {
|
return intestatario;
|
||||||
MyBank.log("Tentato prelievo di " + quantita + " fallito per superamento saldo.", this.numeroContoCorrente);
|
|
||||||
logSaldoCorrente();
|
|
||||||
throw new IllegalArgumentException("La quantità desiderata eccede il saldo corrente.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.saldo -= quantita;
|
|
||||||
MyBank.log("Prelievo di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
|
|
||||||
logSaldoCorrente();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void logSaldoCorrente() {
|
|
||||||
MyBank.log("Saldo corrente: " + this.saldo + "\n", this.numeroContoCorrente);
|
|
||||||
}
|
|
||||||
public String getNome() {
|
|
||||||
return nome;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCognome() {
|
|
||||||
return cognome;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCodiceFiscale() {
|
|
||||||
return codiceFiscale;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Date getDataDiNascita() {
|
|
||||||
return dataDiNascita;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getSaldo() {
|
public double getSaldo() {
|
||||||
return saldo;
|
return saldo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void versa(double quantita) {
|
||||||
|
this.saldo += quantita;
|
||||||
|
ScriviLeggiFile.log("Versamento di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
|
||||||
|
ScriviLeggiFile.salvaContoCorrente(this);
|
||||||
|
logSaldoCorrente();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void preleva(double quantita) throws IllegalArgumentException {
|
||||||
|
if (quantita > this.saldo) {
|
||||||
|
ScriviLeggiFile.log("Tentato prelievo di " + quantita + " fallito per superamento saldo.", this.numeroContoCorrente);
|
||||||
|
logSaldoCorrente();
|
||||||
|
throw new IllegalArgumentException("La quantità desiderata eccede il saldo corrente.");
|
||||||
|
} else {
|
||||||
|
this.saldo -= quantita;
|
||||||
|
ScriviLeggiFile.log("Prelievo di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
|
||||||
|
ScriviLeggiFile.salvaContoCorrente(this);
|
||||||
|
logSaldoCorrente();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logSaldoCorrente() {
|
||||||
|
ScriviLeggiFile.log("Saldo corrente: " + this.saldo + "\n", this.numeroContoCorrente);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Intestatario: " + this.intestatario.toString() + "\nSaldo corrente: " + this.saldo
|
||||||
|
+ "\nNumero conto corrente: " + this.numeroContoCorrente;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,24 +4,17 @@
|
|||||||
*/
|
*/
|
||||||
package mybank;
|
package mybank;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.BufferedWriter;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileReader;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.ParseException;
|
import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Verde
|
* @author Verde
|
||||||
@@ -35,18 +28,18 @@ public class MyBank {
|
|||||||
static Scanner sc = new Scanner(System.in);
|
static Scanner sc = new Scanner(System.in);
|
||||||
static final String ERRORE_GENERICO = "Errore: opzione non valida.";
|
static final String ERRORE_GENERICO = "Errore: opzione non valida.";
|
||||||
static final String ERRORE_CONTI_VUOTO = "Errore: è necessario aggiungere almeno un conto corrente prima di proseguire.";
|
static final String ERRORE_CONTI_VUOTO = "Errore: è necessario aggiungere almeno un conto corrente prima di proseguire.";
|
||||||
static final String PATH_CONTI = "./src/mybank/conti/";
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
int scelta = -1;
|
int scelta = -1;
|
||||||
ArrayList<ContoCorrente> conti = importaConti();
|
ArrayList<ContoCorrente> conti = (ArrayList<ContoCorrente>) ScriviLeggiFile.importaConti();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
System.out.println("Scegliere un'opzione:");
|
System.out.println("Scegliere un'opzione:");
|
||||||
System.out.println("1. Aprire conto corrente");
|
System.out.println("1. Aprire conto corrente");
|
||||||
System.out.println("2. Versamento");
|
System.out.println("2. Stampa conto corrente");
|
||||||
System.out.println("3. Prelievo");
|
System.out.println("3. Versamento");
|
||||||
System.out.println("4. Mostra movimenti");
|
System.out.println("4. Prelievo");
|
||||||
|
System.out.println("5. Mostra movimenti");
|
||||||
System.out.println("0. Esci");
|
System.out.println("0. Esci");
|
||||||
System.out.print("Opzione: ");
|
System.out.print("Opzione: ");
|
||||||
|
|
||||||
@@ -64,6 +57,14 @@ public class MyBank {
|
|||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
|
if (conti.isEmpty()) {
|
||||||
|
System.out.println(ERRORE_CONTI_VUOTO);
|
||||||
|
} else {
|
||||||
|
System.out.println(selezionaConto(conti).toString());
|
||||||
|
}
|
||||||
|
pausa();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
if (conti.isEmpty()) {
|
if (conti.isEmpty()) {
|
||||||
System.out.println(ERRORE_CONTI_VUOTO);
|
System.out.println(ERRORE_CONTI_VUOTO);
|
||||||
} else {
|
} else {
|
||||||
@@ -72,7 +73,7 @@ public class MyBank {
|
|||||||
}
|
}
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 4:
|
||||||
if (conti.isEmpty()) {
|
if (conti.isEmpty()) {
|
||||||
System.out.println(ERRORE_CONTI_VUOTO);
|
System.out.println(ERRORE_CONTI_VUOTO);
|
||||||
} else {
|
} else {
|
||||||
@@ -81,11 +82,11 @@ public class MyBank {
|
|||||||
}
|
}
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 5:
|
||||||
if (conti.isEmpty()) {
|
if (conti.isEmpty()) {
|
||||||
System.out.println(ERRORE_CONTI_VUOTO);
|
System.out.println(ERRORE_CONTI_VUOTO);
|
||||||
} else {
|
} else {
|
||||||
stampaLog(conti);
|
ScriviLeggiFile.stampaLog(selezionaConto(conti));
|
||||||
}
|
}
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
@@ -106,84 +107,53 @@ public class MyBank {
|
|||||||
sc.nextLine();
|
sc.nextLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
static ArrayList<ContoCorrente> importaConti() {
|
static void aggiungiConto(ArrayList<ContoCorrente> conti) {
|
||||||
ArrayList<ContoCorrente> conti = new ArrayList<>();
|
Persona persona;
|
||||||
File percorsoConti = new File(PATH_CONTI);
|
boolean error;
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ContoCorrente contoCorrente;
|
||||||
mapper.setDateFormat(new SimpleDateFormat("dd/MM/yyyy"));
|
List<String> listaCodiciFiscali;
|
||||||
StringBuilder sb;
|
|
||||||
String riga;
|
|
||||||
|
|
||||||
if (percorsoConti.exists() && percorsoConti.listFiles().length != 0) {
|
do {
|
||||||
for (File conto : percorsoConti.listFiles()) {
|
error = false;
|
||||||
if (conto.getName().substring(conto.getName().lastIndexOf(".")).equals(".json")) {
|
|
||||||
try (BufferedReader bf = new BufferedReader(new FileReader(conto))) {
|
|
||||||
sb = new StringBuilder();
|
|
||||||
riga = bf.readLine();
|
|
||||||
|
|
||||||
while (riga != null) {
|
try {
|
||||||
sb.append(riga);
|
persona = persona();
|
||||||
riga = bf.readLine();
|
listaCodiciFiscali = ScriviLeggiFile.leggiCodiciFiscali();
|
||||||
}
|
|
||||||
conti.add(mapper.readerFor(ContoCorrente.class).readValue(sb.toString()));
|
|
||||||
|
|
||||||
ArrayList<Integer> numeriContiCorrenti = (ArrayList<Integer>) ContoCorrente
|
if (listaCodiciFiscali != null && listaCodiciFiscali.contains(persona.getCodiceFiscale())) {
|
||||||
.getNumeriContiCorrenti();
|
System.out.println("Errore: esiste già un conto corrente per questo codice fiscale, riprovare.");
|
||||||
numeriContiCorrenti.add(conti.getLast().getNumeroContoCorrente());
|
pausa();
|
||||||
ContoCorrente.setNumeriContiCorrenti(numeriContiCorrenti);
|
error = true;
|
||||||
|
} else {
|
||||||
} catch (Exception e) {
|
ScriviLeggiFile.salvaCodiceFiscale(persona.getCodiceFiscale());
|
||||||
System.out.println("Errore nella lettura del file di conto corrente.");
|
contoCorrente = new ContoCorrente(persona, quantita("del saldo iniziale"));
|
||||||
System.out.println(e.getMessage());
|
conti.add(contoCorrente);
|
||||||
System.out.println(e.getStackTrace());
|
ScriviLeggiFile.salvaContoCorrente(contoCorrente);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println(e.getMessage());
|
||||||
|
error = true;
|
||||||
}
|
}
|
||||||
}
|
} while (error);
|
||||||
return conti;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void aggiungiConto(ArrayList<ContoCorrente> conti) {
|
static Persona persona() {
|
||||||
String nome;
|
String nome;
|
||||||
String cognome;
|
String cognome;
|
||||||
String codiceFiscale;
|
String codiceFiscale;
|
||||||
Date dataDiNascita;
|
Date dataDiNascita;
|
||||||
double saldoIniziale;
|
|
||||||
int numeroContoCorrente;
|
|
||||||
boolean error;
|
|
||||||
ContoCorrente contoCorrente;
|
|
||||||
|
|
||||||
do {
|
System.out.print("Inserire il proprio nome: ");
|
||||||
error = false;
|
nome = sc.nextLine().trim();
|
||||||
System.out.print("Inserire il proprio nome: ");
|
|
||||||
nome = sc.nextLine().trim();
|
|
||||||
|
|
||||||
System.out.print("Inserire il proprio cognome: ");
|
System.out.print("Inserire il proprio cognome: ");
|
||||||
cognome = sc.nextLine().trim();
|
cognome = sc.nextLine().trim();
|
||||||
|
|
||||||
codiceFiscale = codiceFiscale();
|
codiceFiscale = codiceFiscale();
|
||||||
|
|
||||||
dataDiNascita = dataDiNascita();
|
dataDiNascita = dataDiNascita();
|
||||||
|
|
||||||
saldoIniziale = quantita("del saldo iniziale");
|
return new Persona(nome, cognome, codiceFiscale, dataDiNascita);
|
||||||
|
|
||||||
numeroContoCorrente = Math.abs(codiceFiscale.hashCode());
|
|
||||||
|
|
||||||
if (ContoCorrente.getNumeriContiCorrenti().contains(numeroContoCorrente)) {
|
|
||||||
System.out.println("Errore: esiste già un conto corrente per questo codice fiscale, riprovare.");
|
|
||||||
pausa();
|
|
||||||
error = true;
|
|
||||||
} else {
|
|
||||||
File percorsoConti = new File(PATH_CONTI);
|
|
||||||
if (!percorsoConti.exists()) {
|
|
||||||
percorsoConti.mkdir();
|
|
||||||
}
|
|
||||||
contoCorrente = new ContoCorrente(nome, cognome, codiceFiscale, dataDiNascita, saldoIniziale,
|
|
||||||
numeroContoCorrente);
|
|
||||||
conti.add(contoCorrente);
|
|
||||||
salvaContoCorrente(contoCorrente);
|
|
||||||
}
|
|
||||||
} while (error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static String codiceFiscale() {
|
static String codiceFiscale() {
|
||||||
@@ -253,16 +223,6 @@ public class MyBank {
|
|||||||
return quantita;
|
return quantita;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void salvaContoCorrente(ContoCorrente conto) {
|
|
||||||
try (BufferedWriter bw = new BufferedWriter(
|
|
||||||
new FileWriter(PATH_CONTI + "conto_" + conto.getNumeroContoCorrente() + ".json"))) {
|
|
||||||
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
|
|
||||||
bw.write(ow.writeValueAsString(conto));
|
|
||||||
} catch (IOException _) {
|
|
||||||
System.out.println("Errore: impossibile salvare il conto corrente.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void versa(ArrayList<ContoCorrente> conti) {
|
static void versa(ArrayList<ContoCorrente> conti) {
|
||||||
selezionaConto(conti).versa(quantita("da versare"));
|
selezionaConto(conti).versa(quantita("da versare"));
|
||||||
}
|
}
|
||||||
@@ -284,7 +244,7 @@ public class MyBank {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static ContoCorrente selezionaConto(ArrayList<ContoCorrente> conti) {
|
static ContoCorrente selezionaConto(ArrayList<ContoCorrente> conti) {
|
||||||
ContoCorrente contoCorrente = null;
|
ContoCorrente contoCorrente = new ContoCorrente();
|
||||||
int numeroContoCorrente;
|
int numeroContoCorrente;
|
||||||
boolean error;
|
boolean error;
|
||||||
|
|
||||||
@@ -294,7 +254,7 @@ public class MyBank {
|
|||||||
numeroContoCorrente = sc.nextInt();
|
numeroContoCorrente = sc.nextInt();
|
||||||
sc.nextLine();
|
sc.nextLine();
|
||||||
|
|
||||||
if (!ContoCorrente.getNumeriContiCorrenti().contains(numeroContoCorrente)) {
|
if (numeroContoCorrente < 0 || numeroContoCorrente >= ContoCorrente.getTotaleNumeriCorrenti()) {
|
||||||
System.out.println("Errore: il conto corrente specificato non esiste.");
|
System.out.println("Errore: il conto corrente specificato non esiste.");
|
||||||
pausa();
|
pausa();
|
||||||
error = true;
|
error = true;
|
||||||
@@ -309,30 +269,4 @@ public class MyBank {
|
|||||||
} while (error);
|
} while (error);
|
||||||
return contoCorrente;
|
return contoCorrente;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log(String messaggio, int numeroContoCorrente) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.sss dd/MM/yyyy");
|
|
||||||
try (BufferedWriter bw = new BufferedWriter(
|
|
||||||
new FileWriter(PATH_CONTI + "movimenti_" + numeroContoCorrente + ".txt", true))) {
|
|
||||||
sb.append("[");
|
|
||||||
sb.append(sdf.format(new Date()));
|
|
||||||
sb.append("] ");
|
|
||||||
sb.append(messaggio);
|
|
||||||
sb.append("\n");
|
|
||||||
|
|
||||||
bw.write(sb.toString());
|
|
||||||
} catch (IOException _) {
|
|
||||||
System.out.println("Errore nella scrittura del movimento.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void stampaLog(ArrayList<ContoCorrente> conti) {
|
|
||||||
try (BufferedReader br = new BufferedReader(
|
|
||||||
new FileReader(PATH_CONTI + "movimenti_" + selezionaConto(conti).getNumeroContoCorrente() + ".txt"))) {
|
|
||||||
System.out.println(br.readAllAsString());
|
|
||||||
} catch (IOException _) {
|
|
||||||
System.out.println("Errore nella lettura dei movimenti.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
65
src/mybank/Persona.java
Normal file
65
src/mybank/Persona.java
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package mybank;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Verde
|
||||||
|
*/
|
||||||
|
public class Persona {
|
||||||
|
|
||||||
|
private String nome;
|
||||||
|
private String cognome;
|
||||||
|
private String codiceFiscale;
|
||||||
|
|
||||||
|
@JsonFormat
|
||||||
|
(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy",
|
||||||
|
timezone = "Europe/Rome")
|
||||||
|
private Date dataDiNascita;
|
||||||
|
|
||||||
|
private static ArrayList<String> codiciFiscali = new ArrayList<>();
|
||||||
|
|
||||||
|
public Persona(){}
|
||||||
|
|
||||||
|
public Persona(String nome, String cognome, String codiceFiscale, Date dataDiNascita) {
|
||||||
|
this.nome = nome;
|
||||||
|
this.cognome = cognome;
|
||||||
|
this.codiceFiscale = codiceFiscale;
|
||||||
|
this.dataDiNascita = dataDiNascita;
|
||||||
|
codiciFiscali.add(codiceFiscale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCodiceFiscale() {
|
||||||
|
return codiceFiscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getCodiciFiscali() {
|
||||||
|
return codiciFiscali;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setCodiciFiscali(List<String> codiciFiscali) {
|
||||||
|
Persona.codiciFiscali = (ArrayList<String>) codiciFiscali;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNome() {
|
||||||
|
return nome;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCognome() {
|
||||||
|
return cognome;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "\n\tNome: " + this.nome + "\n\tCognome: " + this.cognome + "\n\tCodice fiscale: " + this.codiceFiscale
|
||||||
|
+ "\n\tData di nascita: " + new SimpleDateFormat("dd/MM/yyyy").format(dataDiNascita);
|
||||||
|
}
|
||||||
|
}
|
||||||
127
src/mybank/ScriviLeggiFile.java
Normal file
127
src/mybank/ScriviLeggiFile.java
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package mybank;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.FileWriter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Verde
|
||||||
|
*/
|
||||||
|
public class ScriviLeggiFile {
|
||||||
|
private static final String PATH_CODICI_FISCALI = "./src/mybank/codiciFiscali.txt";
|
||||||
|
private static final String PATH_CONTI = "./src/mybank/conti/";
|
||||||
|
|
||||||
|
private ScriviLeggiFile() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void salvaCodiceFiscale(String codiceFiscale) throws IOException {
|
||||||
|
try (BufferedWriter bw = new BufferedWriter(
|
||||||
|
new FileWriter(PATH_CODICI_FISCALI, true))) {
|
||||||
|
bw.write(codiceFiscale + "\n");
|
||||||
|
} catch (IOException _) {
|
||||||
|
throw new IOException("Errore nella scrittura del codice fiscale.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> leggiCodiciFiscali() throws IOException {
|
||||||
|
List<String> codiciFiscali = null;
|
||||||
|
|
||||||
|
File percorsoCodiciFiscali = new File(PATH_CODICI_FISCALI);
|
||||||
|
if (percorsoCodiciFiscali.exists()) {
|
||||||
|
try (BufferedReader bf = new BufferedReader(
|
||||||
|
new FileReader(PATH_CODICI_FISCALI))) {
|
||||||
|
codiciFiscali = bf.readAllLines();
|
||||||
|
} catch (IOException _) {
|
||||||
|
throw new IOException("Errore nella lettura dei codici fiscali.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return codiciFiscali;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<ContoCorrente> importaConti() {
|
||||||
|
ArrayList<ContoCorrente> conti = new ArrayList<>();
|
||||||
|
File percorsoConti = new File(PATH_CONTI);
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
mapper.setDateFormat(new SimpleDateFormat("dd/MM/yyyy"));
|
||||||
|
StringBuilder sb;
|
||||||
|
String riga;
|
||||||
|
|
||||||
|
if (percorsoConti.exists() && percorsoConti.listFiles().length != 0) {
|
||||||
|
for (File conto : percorsoConti.listFiles()) {
|
||||||
|
if (conto.getName().substring(conto.getName().lastIndexOf(".")).equals(".json")) {
|
||||||
|
try (BufferedReader bf = new BufferedReader(new FileReader(conto))) {
|
||||||
|
sb = new StringBuilder();
|
||||||
|
riga = bf.readLine();
|
||||||
|
|
||||||
|
while (riga != null) {
|
||||||
|
sb.append(riga);
|
||||||
|
riga = bf.readLine();
|
||||||
|
}
|
||||||
|
conti.add(mapper.readerFor(ContoCorrente.class).readValue(sb.toString()));
|
||||||
|
|
||||||
|
} catch (IOException _) {
|
||||||
|
System.out.println("Errore nella lettura del file di conto corrente.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return conti;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void salvaContoCorrente(ContoCorrente conto) {
|
||||||
|
File percorsoConti = new File(PATH_CONTI);
|
||||||
|
if (!percorsoConti.exists()) {
|
||||||
|
percorsoConti.mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
try (BufferedWriter bw = new BufferedWriter(
|
||||||
|
new FileWriter(PATH_CONTI + "conto_" + conto.getNumeroContoCorrente() + ".json"))) {
|
||||||
|
ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
|
||||||
|
bw.write(ow.writeValueAsString(conto));
|
||||||
|
} catch (IOException _) {
|
||||||
|
System.out.println("Errore: impossibile salvare il conto corrente.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void log(String messaggio, int numeroContoCorrente) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.sss dd/MM/yyyy");
|
||||||
|
try (BufferedWriter bw = new BufferedWriter(
|
||||||
|
new FileWriter(PATH_CONTI + "movimenti_" + numeroContoCorrente + ".txt", true))) {
|
||||||
|
sb.append("[");
|
||||||
|
sb.append(sdf.format(new Date()));
|
||||||
|
sb.append("] ");
|
||||||
|
sb.append(messaggio);
|
||||||
|
sb.append("\n");
|
||||||
|
|
||||||
|
bw.write(sb.toString());
|
||||||
|
} catch (IOException _) {
|
||||||
|
System.out.println("Errore nella scrittura del movimento.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stampaLog(ContoCorrente conto) {
|
||||||
|
try (BufferedReader br = new BufferedReader(
|
||||||
|
new FileReader(PATH_CONTI + "movimenti_" + conto.getNumeroContoCorrente() + ".txt"))) {
|
||||||
|
System.out.println(br.readAllAsString());
|
||||||
|
} catch (IOException _) {
|
||||||
|
System.out.println("Errore nella lettura dei movimenti.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project name="DIRDIR" default="default" basedir=".">
|
|
||||||
<description>Builds, tests, and runs the project DIRDIR.</description>
|
|
||||||
<import file="nbproject/build-impl.xml"/>
|
|
||||||
</project>
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,3 +0,0 @@
|
|||||||
compile.on.save=true
|
|
||||||
user.properties.file=/home/Verde/.netbeans/28/build.properties
|
|
||||||
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
annotation.processing.enabled=true
|
|
||||||
annotation.processing.enabled.in.editor=false
|
|
||||||
annotation.processing.processor.options=
|
|
||||||
annotation.processing.processors.list=
|
|
||||||
annotation.processing.run.all.processors=true
|
|
||||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
|
||||||
build.classes.dir=${build.dir}/classes
|
|
||||||
build.classes.excludes=**/*.java,**/*.form
|
|
||||||
# This directory is removed when the project is cleaned:
|
|
||||||
build.dir=build
|
|
||||||
build.generated.dir=${build.dir}/generated
|
|
||||||
build.generated.sources.dir=${build.dir}/generated-sources
|
|
||||||
# Only compile against the classpath explicitly listed here:
|
|
||||||
build.sysclasspath=ignore
|
|
||||||
build.test.classes.dir=${build.dir}/test/classes
|
|
||||||
build.test.results.dir=${build.dir}/test/results
|
|
||||||
# Uncomment to specify the preferred debugger connection transport:
|
|
||||||
#debug.transport=dt_socket
|
|
||||||
debug.classpath=\
|
|
||||||
${run.classpath}
|
|
||||||
debug.modulepath=\
|
|
||||||
${run.modulepath}
|
|
||||||
debug.test.classpath=\
|
|
||||||
${run.test.classpath}
|
|
||||||
debug.test.modulepath=\
|
|
||||||
${run.test.modulepath}
|
|
||||||
# Files in build.classes.dir which should be excluded from distribution jar
|
|
||||||
dist.archive.excludes=
|
|
||||||
# This directory is removed when the project is cleaned:
|
|
||||||
dist.dir=dist
|
|
||||||
dist.jar=${dist.dir}/mybank.jar
|
|
||||||
dist.javadoc.dir=${dist.dir}/javadoc
|
|
||||||
dist.jlink.dir=${dist.dir}/jlink
|
|
||||||
dist.jlink.output=${dist.jlink.dir}/mybank
|
|
||||||
excludes=
|
|
||||||
includes=**
|
|
||||||
jar.compress=false
|
|
||||||
javac.classpath=
|
|
||||||
# Space-separated list of extra javac options
|
|
||||||
javac.compilerargs=
|
|
||||||
javac.deprecation=false
|
|
||||||
javac.external.vm=true
|
|
||||||
javac.modulepath=
|
|
||||||
javac.processormodulepath=
|
|
||||||
javac.processorpath=\
|
|
||||||
${javac.classpath}
|
|
||||||
javac.source=25
|
|
||||||
javac.target=25
|
|
||||||
javac.test.classpath=\
|
|
||||||
${javac.classpath}:\
|
|
||||||
${build.classes.dir}
|
|
||||||
javac.test.modulepath=\
|
|
||||||
${javac.modulepath}
|
|
||||||
javac.test.processorpath=\
|
|
||||||
${javac.test.classpath}
|
|
||||||
javadoc.additionalparam=
|
|
||||||
javadoc.author=false
|
|
||||||
javadoc.encoding=${source.encoding}
|
|
||||||
javadoc.html5=false
|
|
||||||
javadoc.noindex=false
|
|
||||||
javadoc.nonavbar=false
|
|
||||||
javadoc.notree=false
|
|
||||||
javadoc.private=false
|
|
||||||
javadoc.splitindex=true
|
|
||||||
javadoc.use=true
|
|
||||||
javadoc.version=false
|
|
||||||
javadoc.windowtitle=
|
|
||||||
# The jlink additional root modules to resolve
|
|
||||||
jlink.additionalmodules=
|
|
||||||
# The jlink additional command line parameters
|
|
||||||
jlink.additionalparam=
|
|
||||||
jlink.launcher=true
|
|
||||||
jlink.launcher.name=mybank
|
|
||||||
main.class=mybank.mybank
|
|
||||||
manifest.file=manifest.mf
|
|
||||||
meta.inf.dir=${src.dir}/META-INF
|
|
||||||
mkdist.disabled=false
|
|
||||||
platform.active=default_platform
|
|
||||||
run.classpath=\
|
|
||||||
${javac.classpath}:\
|
|
||||||
${build.classes.dir}
|
|
||||||
# Space-separated list of JVM arguments used when running the project.
|
|
||||||
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
|
||||||
# To set system properties for unit tests define test-sys-prop.name=value:
|
|
||||||
run.jvmargs=
|
|
||||||
run.modulepath=\
|
|
||||||
${javac.modulepath}
|
|
||||||
run.test.classpath=\
|
|
||||||
${javac.test.classpath}:\
|
|
||||||
${build.test.classes.dir}
|
|
||||||
run.test.modulepath=\
|
|
||||||
${javac.test.modulepath}
|
|
||||||
source.encoding=UTF-8
|
|
||||||
src.dir=src
|
|
||||||
test.src.dir=test
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
|
||||||
<type>org.netbeans.modules.java.j2seproject</type>
|
|
||||||
<configuration>
|
|
||||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
|
||||||
<name>mybank</name>
|
|
||||||
<source-roots>
|
|
||||||
<root id="src.dir"/>
|
|
||||||
</source-roots>
|
|
||||||
<test-roots>
|
|
||||||
<root id="test.src.dir"/>
|
|
||||||
</test-roots>
|
|
||||||
</data>
|
|
||||||
</configuration>
|
|
||||||
</project>
|
|
||||||
|
|
||||||
Reference in New Issue
Block a user