diff --git a/NetBeans Projects/Prodotti/Prodotti.jet b/NetBeans Projects/Prodotti/Prodotti.jet new file mode 100644 index 0000000..4dc9527 --- /dev/null +++ b/NetBeans Projects/Prodotti/Prodotti.jet @@ -0,0 +1 @@ +{"diagram":"ClassDiagram","nodes":[{"methods":"+ applicaSconto()\n+ toString() : String","name":"NonAlimentari","x":540,"y":440,"attributes":"- materialePrincipale : String","id":2,"type":"ClassNode"},{"methods":"+ getCodiceBarre() : int\n+ getDescrizione() : String\n+ getPrezzo() : double\n+ applicaSconto()\n+ toString() : String\n+ equals(o : Object) : boolean\n+ hashCode() : int\n# setPrezzo(nuovoPrezzo : double)","name":"Prodotti","x":370,"y":120,"attributes":"- codiceBarre : int\n- descrizione : String\n- prezzo : double","id":0,"type":"ClassNode"},{"methods":"+ applicaSconto()\n+ toString() : String\n# setDate(oggi : DataFormattata)","name":"Alimentari","x":290,"y":430,"attributes":"- scadenza : DataNumerica","id":1,"type":"ClassNode"}],"edges":[{"Generalization Type":"Inheritance","start":2,"end":0,"type":"GeneralizationEdge"},{"Generalization Type":"Inheritance","start":1,"end":0,"type":"GeneralizationEdge"}],"version":"3.5"} diff --git a/NetBeans Projects/Prodotti/Prodotti.png b/NetBeans Projects/Prodotti/Prodotti.png new file mode 100644 index 0000000..f258f36 Binary files /dev/null and b/NetBeans Projects/Prodotti/Prodotti.png differ diff --git a/NetBeans Projects/Prodotti/nbproject/build-impl.xml b/NetBeans Projects/Prodotti/nbproject/build-impl.xml index fb6628c..a90096a 100644 --- a/NetBeans Projects/Prodotti/nbproject/build-impl.xml +++ b/NetBeans Projects/Prodotti/nbproject/build-impl.xml @@ -119,7 +119,43 @@ is divided into following sections: - + + + + + + + + + + + + + + + + + + + + + + + + + + Must set platform.home + Must set platform.bootcp + Must set platform.java + Must set platform.javac + + The J2SE Platform is not correctly set up. + Your active platform is: ${platform.active}, but the corresponding property "platforms.${platform.active}.home" is not found in the project's properties files. + Either open the project in the IDE and setup the Platform with the same name or add it manually. + For example like this: + ant -Duser.properties.file=<path_to_property_file> jar (where you put the property "platforms.${platform.active}.home" in a .properties file) + or ant -Dplatforms.${platform.active}.home=<path_to_JDK_home> jar (where no properties file is used) + @@ -242,20 +278,6 @@ is divided into following sections: - - - - - - - - - - - - - - @@ -343,7 +365,7 @@ is divided into following sections: - + @@ -394,7 +416,7 @@ is divided into following sections: - + @@ -436,7 +458,7 @@ is divided into following sections: - + @@ -515,7 +537,7 @@ is divided into following sections: - + @@ -543,7 +565,7 @@ is divided into following sections: - + @@ -619,7 +641,7 @@ is divided into following sections: - + @@ -850,6 +872,9 @@ is divided into following sections: + + + @@ -899,7 +924,7 @@ is divided into following sections: - + @@ -933,7 +958,7 @@ is divided into following sections: - + @@ -965,7 +990,7 @@ is divided into following sections: - + @@ -1199,7 +1224,7 @@ is divided into following sections: To run this application from the command line without Ant, try: - java -jar "${dist.jar.resolved}" + ${platform.java} -jar "${dist.jar.resolved}" @@ -1301,8 +1326,8 @@ is divided into following sections: - - + + @@ -1495,16 +1520,19 @@ is divided into following sections: + + + - + - + - + diff --git a/NetBeans Projects/Prodotti/nbproject/genfiles.properties b/NetBeans Projects/Prodotti/nbproject/genfiles.properties index c371171..19157ee 100644 --- a/NetBeans Projects/Prodotti/nbproject/genfiles.properties +++ b/NetBeans Projects/Prodotti/nbproject/genfiles.properties @@ -1,8 +1,8 @@ -build.xml.data.CRC32=2fdcd13d +build.xml.data.CRC32=24751a7c build.xml.script.CRC32=7d6b168c build.xml.stylesheet.CRC32=f85dc8f2@1.106.0.48 # This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. # Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=2fdcd13d -nbproject/build-impl.xml.script.CRC32=fc1dc10f +nbproject/build-impl.xml.data.CRC32=24751a7c +nbproject/build-impl.xml.script.CRC32=6509df98 nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48 diff --git a/NetBeans Projects/Prodotti/nbproject/private/config.properties b/NetBeans Projects/Prodotti/nbproject/private/config.properties new file mode 100644 index 0000000..e69de29 diff --git a/NetBeans Projects/Prodotti/nbproject/private/private.properties b/NetBeans Projects/Prodotti/nbproject/private/private.properties index a2ad8bd..721cc40 100644 --- a/NetBeans Projects/Prodotti/nbproject/private/private.properties +++ b/NetBeans Projects/Prodotti/nbproject/private/private.properties @@ -1,2 +1,8 @@ compile.on.save=true -user.properties.file=/home/giacomo/.netbeans/17/build.properties +do.depend=false +do.jar=true +do.jlink=false +javac.debug=true +javadoc.preview=true +jlink.strip=false +user.properties.file=/home/gicorada/.netbeans/17/build.properties diff --git a/NetBeans Projects/Prodotti/nbproject/private/private.xml b/NetBeans Projects/Prodotti/nbproject/private/private.xml index 1a110b8..f99e863 100644 --- a/NetBeans Projects/Prodotti/nbproject/private/private.xml +++ b/NetBeans Projects/Prodotti/nbproject/private/private.xml @@ -3,10 +3,12 @@ - file:/home/giacomo/NetBeansProjects/Prodotti/src/prodotti/Alimentari.java - file:/home/giacomo/NetBeansProjects/Prodotti/src/prodotti/Prodotti.java - file:/home/giacomo/NetBeansProjects/Prodotti/src/prodotti/NonAlimentari.java - file:/home/giacomo/NetBeansProjects/Prodotti/src/prodotti/ListaSpesa.java + file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/NonAlimentari.java + file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/ListaSpesa.java + file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/DataFormattata.java + file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/Prodotti.java + file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/Alimentari.java + file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/DataNumerica.java diff --git a/NetBeans Projects/Prodotti/nbproject/project.properties b/NetBeans Projects/Prodotti/nbproject/project.properties index be08150..1f503c5 100644 --- a/NetBeans Projects/Prodotti/nbproject/project.properties +++ b/NetBeans Projects/Prodotti/nbproject/project.properties @@ -1,9 +1,10 @@ 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 +application.title=EsPasqua +application.vendor=gicorada build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: @@ -32,6 +33,7 @@ dist.jar=${dist.dir}/EsPasqua.jar dist.javadoc.dir=${dist.dir}/javadoc dist.jlink.dir=${dist.dir}/jlink dist.jlink.output=${dist.jlink.dir}/EsPasqua +endorsed.classpath= excludes= includes=** jar.compress=false @@ -44,8 +46,8 @@ javac.modulepath= javac.processormodulepath= javac.processorpath=\ ${javac.classpath} -javac.source=11 -javac.target=11 +javac.source=17 +javac.target=17 javac.test.classpath=\ ${javac.classpath}:\ ${build.classes.dir} @@ -75,7 +77,7 @@ main.class=prodotti.ListaSpesa manifest.file=manifest.mf meta.inf.dir=${src.dir}/META-INF mkdist.disabled=false -platform.active=default_platform +platform.active=Zulu_17.0.6_10 run.classpath=\ ${javac.classpath}:\ ${build.classes.dir} diff --git a/NetBeans Projects/Prodotti/nbproject/project.xml b/NetBeans Projects/Prodotti/nbproject/project.xml index 4a17984..3bbe7d5 100644 --- a/NetBeans Projects/Prodotti/nbproject/project.xml +++ b/NetBeans Projects/Prodotti/nbproject/project.xml @@ -4,6 +4,7 @@ EsPasqua + diff --git a/NetBeans Projects/Prodotti/src/prodotti/Alimentari.java b/NetBeans Projects/Prodotti/src/prodotti/Alimentari.java index 67d8475..199842f 100644 --- a/NetBeans Projects/Prodotti/src/prodotti/Alimentari.java +++ b/NetBeans Projects/Prodotti/src/prodotti/Alimentari.java @@ -1,30 +1,41 @@ package prodotti; -import java.util.Date; - - - /** - * - * @author giacomo + * Classe che rappresenta Prodotti alimentari + * @author radaelli11353 */ public class Alimentari extends Prodotti { - Date scadenza; + private DataNumerica scadenza; + static DataNumerica oggi; - public Alimentari(int codiceBarre, String descrizione, double prezzo, Date scadenza) { + public Alimentari(int codiceBarre, String descrizione, double prezzo, DataNumerica scadenza) { super(codiceBarre, descrizione, prezzo); this.scadenza = scadenza; } + + //Necessario per impostare data di oggi a tutti gli Alimentari + public Alimentari() { + super(0, "", 0); + } + + /** + * Metodo che aggiorna la data del giorno attuale + * @param oggi Nuova data + */ + public void setDate(DataFormattata oggi) { + Alimentari.oggi = (DataNumerica) oggi; + } @Override public void applicaSconto() { - //condizione da implementare - if(true) { + int delta = scadenza.getDifference(oggi); + if(delta > -10 && delta < 0) { setPrezzo(getPrezzo() - getPrezzo()* 0.2); } } - - - + @Override + public String toString() { + return "Alimentari[" + getDescrizione() + ", " + getPrezzo() + "€, scade il " + scadenza.stringaFormattata() + ", codice a barre " + getCodiceBarre() + "]"; + } } diff --git a/NetBeans Projects/Prodotti/src/prodotti/DataFormattata.java b/NetBeans Projects/Prodotti/src/prodotti/DataFormattata.java new file mode 100644 index 0000000..d139013 --- /dev/null +++ b/NetBeans Projects/Prodotti/src/prodotti/DataFormattata.java @@ -0,0 +1,41 @@ +package prodotti; + +/** + * Classe che rappresenta una data senza fornire metodi per la formattazione + * @author radaelli11353 + */ +public abstract class DataFormattata implements Comparable { + private int giorno; + private int mese; + private int anno; + + public DataFormattata(int giorno, int mese, int anno) { + if(giorno >= 1 && giorno <= 31) this.giorno = giorno; + else throw new IllegalArgumentException("Il numero del giorno non è valido"); + if(mese >= 1 && mese <= 12) this.mese = mese; + else throw new IllegalArgumentException("Il numero del mese non è valido"); + this.anno = anno; + } + + protected int getGiorno() { + return giorno; + } + + protected int getMese() { + return mese; + } + + protected int getAnno() { + return anno; + } + + @Override + public int compareTo(DataFormattata o) { + if(this.anno != o.anno) return this.anno - o.anno; + if(this.mese != o.mese) return this.mese - o.mese; + return this.giorno - o.giorno; + } + + + public abstract String stringaFormattata(); +} diff --git a/NetBeans Projects/Prodotti/src/prodotti/DataNumerica.java b/NetBeans Projects/Prodotti/src/prodotti/DataNumerica.java new file mode 100644 index 0000000..b365b8f --- /dev/null +++ b/NetBeans Projects/Prodotti/src/prodotti/DataNumerica.java @@ -0,0 +1,39 @@ +package prodotti; + +/** + * Classe che rappresenta una data numerica + * @author radaelli11353 + */ +public class DataNumerica extends DataFormattata { + + public DataNumerica(int giorno, int mese, int anno) { + super(giorno, mese, anno); + } + + @Override + public String stringaFormattata() { + int g = getGiorno(); + int m = getMese(); + int a = getAnno(); + + String res = (g<10) ? "0"+g : ""+g; + res += "/"; + res += (m<10) ? "0"+m : "" + m; + + return res + "/" + a; + } + + /** + * Restituisce i giorni di differenza tra le due date + * @param o Altra data + * @return Differenza tra i giorni, Integer.MIN_VALUE se mese o anno diverso (per il problema del numero variabile di giorni al mese + */ + public int getDifference(DataNumerica o) { + //Provvisorio, per il problema del numero di giorni variabile. + //Non dovrebbe influire con l'esecuzione richesta da Alimentari, altrimenti andrebbe riscritto + if(getAnno() != o.getAnno() || getMese() != o.getMese()) return Integer.MIN_VALUE; + + return compareTo(o); + } + +} diff --git a/NetBeans Projects/Prodotti/src/prodotti/ListaSpesa.java b/NetBeans Projects/Prodotti/src/prodotti/ListaSpesa.java index e7a0b36..2a1eb51 100644 --- a/NetBeans Projects/Prodotti/src/prodotti/ListaSpesa.java +++ b/NetBeans Projects/Prodotti/src/prodotti/ListaSpesa.java @@ -2,35 +2,49 @@ package prodotti; import java.util.ArrayList; import java.util.Scanner; -import java.util.Date; /** - * - * @author giacomo + * Classe di test per Prodotti + * @author radaelli11353 */ public class ListaSpesa { public static void main(String[] args) { ArrayList listaSpesa = new ArrayList<>(); Scanner in = new Scanner(System.in); - System.out.println("Hai la tessera fedeltà?"); - boolean tessera = (in.next().equalsIgnoreCase(sì)) ? true : false; + //Metodo provvisorio per sistemare la data in tutti gli Alimentari + DataNumerica oggi = new DataNumerica(12, 2, 2023); + Alimentari a = new Alimentari(); + a.setDate(oggi); - System.out.println("Inserisci il numero di prodotti"); + + System.out.print("Hai la tessera fedeltà? (S/n) "); + boolean tessera = in.next().equalsIgnoreCase("s"); + + System.out.print("Inserisci il numero di prodotti: "); int n = in.nextInt(); for(int i = 0; i < n; i++) { - String tipoProdotto = in.next().toLowerCase(); - if(tipoProdotto.equals("alimentari")) { - System.out.println("Inserisci i dati del prodotto nel formato:\nCodiceBarre\ndescrizione\nprezzo\nscadenza"); - listaSpesa.add(new Alimentari(in.nextInt(), in.nextLine(), in.nextDouble(), new Date())); + System.out.print("Alimentari (a) o non alimentari (n)? (a/n) "); + char tipoProdotto = in.next().toLowerCase().charAt(0); + if(tipoProdotto == 'a') { + //System.out.println("Inserisci i dati del prodotto nel formato:\nCodiceBarre\ndescrizione\nprezzo\nscadenza"); + listaSpesa.add(new Alimentari(1234, "Prova alimentare", 10.00, new DataNumerica(10, 2, 2023))); + } else if(tipoProdotto == 'n') { + //System.out.println("Inserisci i dati del prodotto nel formato:\nCodiceBarre\ndescrizione\nprezzo\nmateriale principale"); + listaSpesa.add(new NonAlimentari(4321, "Prova non alimentare", 100.00, "vetro")); } } - double prezzo; + double prezzo = 0; + System.out.println("Elementi nella lista:"); for(Prodotti p : listaSpesa) { + if(tessera) p.applicaSconto(); prezzo += p.getPrezzo(); + System.out.println(p); } + + System.out.println("\n--- Prezzo finale: " + prezzo + "€ ---"); } } diff --git a/NetBeans Projects/Prodotti/src/prodotti/NonAlimentari.java b/NetBeans Projects/Prodotti/src/prodotti/NonAlimentari.java index 16df36e..593ca53 100644 --- a/NetBeans Projects/Prodotti/src/prodotti/NonAlimentari.java +++ b/NetBeans Projects/Prodotti/src/prodotti/NonAlimentari.java @@ -1,8 +1,8 @@ package prodotti; /** - * - * @author giacomo + * Classe che rappresenta Prodotti non alimentari + * @author radaelli11353 */ public class NonAlimentari extends Prodotti { String materiale; @@ -18,5 +18,12 @@ public class NonAlimentari extends Prodotti { setPrezzo(getPrezzo() - getPrezzo()* 0.1); } } + + @Override + public String toString() { + return "NonAlimentari[" + getDescrizione() + ", " + getPrezzo() + "€, fatto di " + materiale + ", codice a barre " + getCodiceBarre() + "]"; + } + + } diff --git a/NetBeans Projects/Prodotti/src/prodotti/Prodotti.java b/NetBeans Projects/Prodotti/src/prodotti/Prodotti.java index c3f4dca..cbbbfd1 100644 --- a/NetBeans Projects/Prodotti/src/prodotti/Prodotti.java +++ b/NetBeans Projects/Prodotti/src/prodotti/Prodotti.java @@ -2,14 +2,13 @@ package prodotti; import java.util.Objects; - - /** - * Class Prodotti + * Classe che rappresenta Prodotti generici + * @author radaelli11353 */ public class Prodotti { - private int codiceBarre; - private String descrizione; + private final int codiceBarre; + private final String descrizione; private double prezzo; public Prodotti(int codiceBarre, String descrizione, double prezzo) { @@ -19,29 +18,33 @@ public class Prodotti { } /** - * Get the value of codiceBarre - * @return the value of codiceBarre + * Ritorna il valore di codiceBarre + * @return valore di codiceBarre */ public int getCodiceBarre () { return codiceBarre; } /** - * Get the value of descrizione - * @return the value of descrizione + * Ritorna la descrizione + * @return descrizione */ public String getDescrizione () { return descrizione; } /** - * Get the value of prezzo - * @return the value of prezzo + * Ritorna il prezzo + * @return prezzo */ public double getPrezzo () { return prezzo; } + /** + * Modifica il prezzo + * @param nuovoPrezzo Prezzo nuovo + */ protected void setPrezzo(double nuovoPrezzo) { prezzo = nuovoPrezzo; } @@ -53,21 +56,11 @@ public class Prodotti { prezzo = prezzo - prezzo * 0.05; } - - /** - * - * @return String - */ @Override public String toString() { - return "Prodotto[descrizione: " + descrizione + ", prezzo:" + prezzo + ", codice a barre:" + codiceBarre; + return "Prodotto[" + descrizione + ", prezzo:" + prezzo + ", codice a barre:" + codiceBarre + "]"; } - - /** - * @param o - * @return boolean - */ @Override public boolean equals(Object o) { if(o == null) return false;