Preparazione al merge

This commit is contained in:
La Programmatrice Verde
2026-03-03 08:33:37 +01:00
12 changed files with 453 additions and 83 deletions

View File

@@ -1,73 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="GUIMyBank" default="default" basedir=".">
<description>Builds, tests, and runs the project GUIMyBank.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="GUIMyBank-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>

Binary file not shown.

BIN
lib/jackson-core-2.20.1.jar Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,98 @@
/*
* 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.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
/**
*
* @author Verde
*/
public class ContoCorrente {
private String nome;
private String cognome;
private String codiceFiscale;
private double saldo;
private int numeroContoCorrente;
private static ArrayList<Integer> numeriContiCorrenti = new ArrayList<>();
@JsonFormat
(shape = JsonFormat.Shape.STRING, pattern = "dd/MM/yyyy")
private Date dataDiNascita;
public ContoCorrente() {
}
public ContoCorrente(String nome, String cognome, String codiceFiscale, Date dataDiNascita, double saldo,
int numeroContoCorrente) {
this.nome = nome;
this.cognome = cognome;
this.codiceFiscale = codiceFiscale;
this.dataDiNascita = dataDiNascita;
this.saldo = saldo;
this.numeroContoCorrente = numeroContoCorrente;
numeriContiCorrenti.add(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() {
return numeroContoCorrente;
}
public void versa(double quantita){
this.saldo += quantita;
MyBank.log("Versamento di " + quantita + " effettuato con successo.", this.numeroContoCorrente);
logSaldoCorrente();
}
public void preleva(double quantita) throws IllegalArgumentException{
if (quantita > this.saldo) {
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() {
return saldo;
}
}

338
src/mybank/MyBank.java Normal file
View File

@@ -0,0 +1,338 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.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.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
/**
*
* @author Verde
*/
public class MyBank {
/**
* @param args the command line arguments
*/
static Scanner sc = new Scanner(System.in);
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 PATH_CONTI = "./src/mybank/conti/";
public static void main(String[] args) {
int scelta = -1;
ArrayList<ContoCorrente> conti = importaConti();
do {
System.out.println("Scegliere un'opzione:");
System.out.println("1. Aprire conto corrente");
System.out.println("2. Versamento");
System.out.println("3. Prelievo");
System.out.println("4. Mostra movimenti");
System.out.println("0. Esci");
System.out.print("Opzione: ");
try {
scelta = sc.nextInt();
sc.nextLine();
switch (scelta) {
case 0:
break;
case 1:
aggiungiConto(conti);
System.out.println("Numero conto: " + conti.getLast().getNumeroContoCorrente());
System.out.println("Conto corrente aggiunto con successo.");
pausa();
break;
case 2:
if (conti.isEmpty()) {
System.out.println(ERRORE_CONTI_VUOTO);
} else {
versa(conti);
System.out.println("Versamento effettuato con successo.");
}
pausa();
break;
case 3:
if (conti.isEmpty()) {
System.out.println(ERRORE_CONTI_VUOTO);
} else {
preleva(conti);
System.out.println("Prelievo effettuato con successo.");
}
pausa();
break;
case 4:
if (conti.isEmpty()) {
System.out.println(ERRORE_CONTI_VUOTO);
} else {
stampaLog(conti);
}
pausa();
break;
default:
System.out.println(ERRORE_GENERICO);
pausa();
break;
}
} catch (InputMismatchException _) {
System.out.println(ERRORE_GENERICO);
pausa();
}
} while (scelta != 0);
}
public static void pausa() {
System.out.println("Premere un tasto per continuare. . .");
sc.nextLine();
}
static ArrayList<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()));
ArrayList<Integer> numeriContiCorrenti = (ArrayList<Integer>) ContoCorrente
.getNumeriContiCorrenti();
numeriContiCorrenti.add(conti.getLast().getNumeroContoCorrente());
ContoCorrente.setNumeriContiCorrenti(numeriContiCorrenti);
} catch (Exception e) {
System.out.println("Errore nella lettura del file di conto corrente.");
System.out.println(e.getMessage());
System.out.println(e.getStackTrace());
}
}
}
}
return conti;
}
static void aggiungiConto(ArrayList<ContoCorrente> conti) {
String nome;
String cognome;
String codiceFiscale;
Date dataDiNascita;
double saldoIniziale;
int numeroContoCorrente;
boolean error;
ContoCorrente contoCorrente;
do {
error = false;
System.out.print("Inserire il proprio nome: ");
nome = sc.nextLine().trim();
System.out.print("Inserire il proprio cognome: ");
cognome = sc.nextLine().trim();
codiceFiscale = codiceFiscale();
dataDiNascita = dataDiNascita();
saldoIniziale = quantita("del saldo iniziale");
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() {
String codiceFiscale;
boolean error;
Pattern pattern = Pattern.compile("[A-Z]{6}[ABCDEHLMPRST]{3}\\d{2}[A-Z]\\d{3}[A-Z]");
Matcher matcher;
do {
error = false;
System.out.print("Inserire il proprio codice fiscale: ");
codiceFiscale = sc.nextLine().trim().toUpperCase();
matcher = pattern.matcher(codiceFiscale);
if (!matcher.find()) {
System.out.println(ERRORE_GENERICO);
pausa();
error = true;
}
} while (error);
return codiceFiscale;
}
static Date dataDiNascita() {
Date dataDiNascita = null;
boolean error;
final String FORMATO_DATA = "dd/MM/yyyy";
SimpleDateFormat sdf = new SimpleDateFormat(FORMATO_DATA);
sdf.setLenient(false);
do {
error = false;
System.out.print("Inserire la propria data di nascita nel formato " + FORMATO_DATA + ": ");
try {
dataDiNascita = sdf.parse(sc.nextLine());
} catch (ParseException _) {
System.out.println("Errore: la data inserita non è valida.");
pausa();
error = true;
}
} while (error);
return dataDiNascita;
}
static double quantita(String diCheCosa) {
double quantita = 0;
boolean error;
do {
error = false;
System.out.print("Inserire la quantità " + diCheCosa + ": ");
try {
quantita = sc.nextDouble();
sc.nextLine();
if (quantita <= 0) {
System.out.println("Errore: la quantità non può essere minore o uguale a zero.");
pausa();
error = true;
}
} catch (InputMismatchException _) {
System.out.println(ERRORE_GENERICO);
pausa();
error = true;
}
} while (error);
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) {
selezionaConto(conti).versa(quantita("da versare"));
}
static void preleva(ArrayList<ContoCorrente> conti) {
boolean error;
do {
error = false;
try {
selezionaConto(conti).preleva(quantita("da prelevare"));
} catch (IllegalArgumentException e) {
System.out.println(e.getMessage());
pausa();
error = true;
}
} while (error);
}
static ContoCorrente selezionaConto(ArrayList<ContoCorrente> conti) {
ContoCorrente contoCorrente = null;
int numeroContoCorrente;
boolean error;
do {
error = false;
System.out.print("Inserire il proprio numero di conto: ");
numeroContoCorrente = sc.nextInt();
sc.nextLine();
if (!ContoCorrente.getNumeriContiCorrenti().contains(numeroContoCorrente)) {
System.out.println("Errore: il conto corrente specificato non esiste.");
pausa();
error = true;
} else {
for (ContoCorrente conto : conti) {
if (conto.getNumeroContoCorrente() == numeroContoCorrente) {
contoCorrente = conto;
break;
}
}
}
} while (error);
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.");
}
}
}

5
src/mybank/build.xml Normal file
View File

@@ -0,0 +1,5 @@
<?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>

View File

@@ -19,7 +19,7 @@ is divided into following sections:
- cleanup
-->
<project xmlns:if="ant:if" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" xmlns:unless="ant:unless" basedir=".." default="default" name="GUIMyBank-impl">
<project xmlns:if="ant:if" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" xmlns:unless="ant:unless" basedir=".." default="default" name="mybank-impl">
<fail message="Please build using Ant 1.8.0 or higher.">
<condition>
<not>
@@ -619,7 +619,7 @@ is divided into following sections:
</fileset>
</union>
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="GUIMyBank" testname="TestNG tests" workingDir="${work.dir}">
<testng classfilesetref="test.set" failureProperty="tests.failed" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="mybank" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset>
<propertyref prefix="test-sys-prop."/>
@@ -716,7 +716,7 @@ is divided into following sections:
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
<isset property="test.method"/>
</condition>
<condition else="-suitename GUIMyBank -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<condition else="-suitename mybank -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
<matches pattern=".*\.xml" string="@{testClass}"/>
</condition>
<delete dir="${build.test.results.dir}" quiet="true"/>
@@ -1057,7 +1057,7 @@ is divided into following sections:
<delete file="${built-jar.properties}" quiet="true"/>
</target>
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
<echo level="warn" message="Cycle detected: GUIMyBank was already built"/>
<echo level="warn" message="Cycle detected: mybank was already built"/>
</target>
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
<mkdir dir="${build.dir}"/>
@@ -1728,7 +1728,7 @@ is divided into following sections:
<delete file="${built-clean.properties}" quiet="true"/>
</target>
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
<echo level="warn" message="Cycle detected: GUIMyBank was already built"/>
<echo level="warn" message="Cycle detected: mybank was already built"/>
</target>
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
<mkdir dir="${build.dir}"/>

View File

@@ -1,2 +1,3 @@
compile.on.save=true
user.properties.file=/home/Verde/.netbeans/28/build.properties

View File

@@ -28,10 +28,10 @@ debug.test.modulepath=\
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/GUIMyBank.jar
dist.jar=${dist.dir}/mybank.jar
dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/GUIMyBank
dist.jlink.output=${dist.jlink.dir}/mybank
excludes=
includes=**
jar.compress=false
@@ -70,8 +70,8 @@ jlink.additionalmodules=
# The jlink additional command line parameters
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=GUIMyBank
main.class=guimybank.GUIMyBank
jlink.launcher.name=mybank
main.class=mybank.mybank
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false

View File

@@ -3,7 +3,7 @@
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>GUIMyBank</name>
<name>mybank</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
@@ -13,3 +13,4 @@
</data>
</configuration>
</project>