Merge branch 'master' of gitea.it:gicorada/java-scuola

This commit is contained in:
Giacomo R. 2023-04-12 22:10:38 +02:00
commit 12ad747374
44 changed files with 4568 additions and 90 deletions

1
.gitignore vendored
View File

@ -34,3 +34,4 @@ hs_err_pid*
/NetBeans Projects/BankAccount/nbproject/private/
/NetBeans Projects/BankAccount/build/
/NetBeans Projects/BankAccount/dist/
/NetBeans Projects/Inventory/build/

View File

@ -0,0 +1,73 @@
<?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="Inventory" default="default" basedir=".">
<description>Builds, tests, and runs the project Inventory.</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="Inventory-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>

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=ec0e7c8c
build.xml.script.CRC32=7b7b3108
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=ec0e7c8c
nbproject/build-impl.xml.script.CRC32=7dee9c4b
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48

View File

@ -0,0 +1,8 @@
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/gicorada/.netbeans/17/build.properties

View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group/>
</open-files>
</project-private>

View File

@ -0,0 +1,98 @@
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
application.title=Inventory
application.vendor=gicorada
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}/Inventory.jar
dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/Inventory
endorsed.classpath=
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=16
javac.target=16
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=Inventory
main.class=inventory.Tester
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=Zulu_17.0.6_10
project.license=apache20
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

View File

@ -0,0 +1,16 @@
<?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>Inventory</name>
<explicit-platform explicit-source-supported="true"/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

View File

@ -0,0 +1,98 @@
/*
* Copyright 2023 radaelli11353.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inventory;
import java.util.ArrayList;
/**
* Metodo che simula un inventario
* @author radaelli11353
*/
public class Inventory {
private ArrayList<Item> list;
/**
* Costruttore
*/
public Inventory() {
list = new ArrayList<>();
}
/**
* Aggiunge un oggetto all'inventario.
* @param name Nome dell'oggetto
* @param quantity Quantità iniziale
* @param price Prezzo unitario dell'oggetto
*/
public void addItem(String name, int quantity, double price) {
list.add(new Item(name, quantity, price));
}
/**
* Aggiunge una quantità di oggetti già presenti.
* Se gli oggetti non sono presenti nell'inventario, non fa niente
* @param itemName Nome dell'oggetto da ricercare
* @param quantity Quantità da aggiungere all'oggetto
*/
public void increaseQuantity(String itemName, int quantity) {
for(int i = 0; i < list.size(); i++) {
if(list.get(i).getName().equals(itemName)) {
list.get(i).modifyQuantity(quantity);
return;
}
}
}
/**
* Diminuisce di una quantità oggetti già presenti.
* Utilizza increaseQuantity per diminuire in numero di oggetti
* @param itemName Nome dell'oggetto da ricercare
* @param quantity Quantità da rimuovere all'oggetto
*/
public void decreaseQuantity(String itemName, int quantity) {
if(quantity < 0) quantity = -quantity;
increaseQuantity(itemName, -quantity);
}
/**
* Resistuisce la quantità di oggetti di un determinato tipo presenti.
* @param itemName Nome dell'oggetto da ricercare
* @return Numero degli item presenti nell'Inventory, -1 se non presenti
*/
public int getQuantity(String itemName) {
for(int i = 0; i < list.size(); i++) {
if(list.get(i).getName().equals(itemName)) {
return list.get(i).getQuantity();
}
}
return -1;
}
/**
* Restituisce il valore complessivo di tutti gli oggetti dell'inventario.
* @return Valore complessivo dell'inventario
*/
public double getTotalValue() {
double totalValue = 0;
for(Item i : list) {
totalValue += i.getPrice() * i.getQuantity();
}
return totalValue;
}
}

View File

@ -0,0 +1 @@
{"diagram":"ClassDiagram","nodes":[{"methods":"+additem(name: String, quantity: int, price: double): void\n+increaseQuantity(itemName: String, quantity: int): void\n+decreaseQuantity(itemName: String, quantity: int): void\n+getQuantity(itemName: String): void\n+getTotalValue(): double","name":"Inventory","x":380,"y":100,"attributes":"","id":0,"type":"ClassNode"},{"methods":"#getName(): String\n#getQuantity(): int\n#getPrice(): double","name":"Item","x":840,"y":100,"attributes":"-name: String\n-quantity: int\n-price: double","id":1,"type":"ClassNode"}],"edges":[],"version":"3.5"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,73 @@
/*
* Copyright 2023 radaelli11353.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inventory;
/**
* Classe che simula un oggetto con nome, quantità e prezzo
* @author radaelli11353
*/
public class Item {
private String name;
private int quantity;
private double price;
/**
* Costruttore parametrico completo
* @param name Nome dell'oggetto
* @param quantity Quantità iniziale
* @param price Prezzo dell'oggetto
*/
public Item(String name, int quantity, double price) {
if(quantity < 0) throw new IllegalArgumentException();
if(price < 0) throw new IllegalArgumentException();
this.name = name;
this.quantity = quantity;
this.price = price;
}
/**
* Modifica la quantità dell'oggetto
* @param modifier
*/
protected void modifyQuantity(int modifier) {
if(!(quantity + modifier >= 0)) throw new IllegalArgumentException("La quantità minima per oggetto è 0");
quantity += modifier;
}
/**
* Getter nome
* @return Nome oggetto
*/
public String getName() {
return name;
}
/**
* Getter quantità
* @return Quantità degli oggetti
*/
public int getQuantity() {
return quantity;
}
/**
* Getter prezzo
* @return Prezzo dell'oggetto
*/
public double getPrice() {
return price;
}
}

View File

@ -0,0 +1,37 @@
/*
* Copyright 2023 radaelli11353.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package inventory;
/**
* Classe di test per Inventory
* @author gicorada
*/
public class Tester {
public static void main(String[] args) {
Inventory inv = new Inventory();
inv.addItem("Prova1", 5, 10.00);
System.out.println(inv.getQuantity("Prova1"));
inv.increaseQuantity("Prova1", 7);
System.out.println(inv.getQuantity("Prova1"));
inv.decreaseQuantity("Prova1", 2);
System.out.println(inv.getQuantity("Prova1"));
System.out.println(inv.getTotalValue());
}
}

View File

@ -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"}

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

View File

@ -119,7 +119,43 @@ is divided into following sections:
<property name="module.name" value=""/>
</target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property,-init-modules-supported" name="-do-init">
<property name="platform.java" value="${java.home}/bin/java"/>
<j2seproject1:property name="platform.home" value="platforms.${platform.active}.home"/>
<j2seproject1:property name="platform.bootcp" value="platforms.${platform.active}.bootclasspath"/>
<j2seproject1:property name="platform.compiler" value="platforms.${platform.active}.compile"/>
<j2seproject1:property name="platform.javac.tmp" value="platforms.${platform.active}.javac"/>
<condition property="platform.javac" value="${platform.home}/bin/javac">
<equals arg1="${platform.javac.tmp}" arg2="$${platforms.${platform.active}.javac}"/>
</condition>
<property name="platform.javac" value="${platform.javac.tmp}"/>
<j2seproject1:property name="platform.java.tmp" value="platforms.${platform.active}.java"/>
<condition property="platform.java" value="${platform.home}/bin/java">
<equals arg1="${platform.java.tmp}" arg2="$${platforms.${platform.active}.java}"/>
</condition>
<property name="platform.java" value="${platform.java.tmp}"/>
<j2seproject1:property name="platform.javadoc.tmp" value="platforms.${platform.active}.javadoc"/>
<condition property="platform.javadoc" value="${platform.home}/bin/javadoc">
<equals arg1="${platform.javadoc.tmp}" arg2="$${platforms.${platform.active}.javadoc}"/>
</condition>
<property name="platform.javadoc" value="${platform.javadoc.tmp}"/>
<condition property="platform.invalid" value="true">
<or>
<contains string="${platform.javac}" substring="$${platforms."/>
<contains string="${platform.java}" substring="$${platforms."/>
<contains string="${platform.javadoc}" substring="$${platforms."/>
</or>
</condition>
<fail unless="platform.home">Must set platform.home</fail>
<fail unless="platform.bootcp">Must set platform.bootcp</fail>
<fail unless="platform.java">Must set platform.java</fail>
<fail unless="platform.javac">Must set platform.javac</fail>
<fail if="platform.invalid">
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=&lt;path_to_property_file&gt; jar (where you put the property "platforms.${platform.active}.home" in a .properties file)
or ant -Dplatforms.${platform.active}.home=&lt;path_to_JDK_home&gt; jar (where no properties file is used)
</fail>
<available file="${manifest.file}" property="manifest.available"/>
<condition property="splashscreen.available">
<and>
@ -242,20 +278,6 @@ is divided into following sections:
<condition else="" property="javac.profile.cmd.line.arg" value="-profile ${javac.profile}">
<isset property="profile.available"/>
</condition>
<condition else="false" property="jdkBug6558476">
<and>
<matches pattern="1\.[56]" string="${java.specification.version}"/>
<not>
<os family="unix"/>
</not>
</and>
</condition>
<condition else="false" property="javac.fork">
<or>
<istrue value="${jdkBug6558476}"/>
<istrue value="${javac.external.vm}"/>
</or>
</condition>
<property name="jar.index" value="false"/>
<property name="jar.index.metainf" value="${jar.index}"/>
<property name="copylibs.rebase" value="true"/>
@ -343,7 +365,7 @@ is divided into following sections:
</path>
</resourcecount>
</condition>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
@ -394,7 +416,7 @@ is divided into following sections:
<property location="${build.dir}/empty" name="empty.dir"/>
<mkdir dir="${empty.dir}"/>
<mkdir dir="@{apgeneratedsrcdir}"/>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
@ -436,7 +458,7 @@ is divided into following sections:
<sequential>
<property location="${build.dir}/empty" name="empty.dir"/>
<mkdir dir="${empty.dir}"/>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" fork="${javac.fork}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
@ -515,7 +537,7 @@ is divided into following sections:
<element name="customizePrototype" optional="true"/>
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
<mapper from="test-sys-prop.*" to="*" type="glob"/>
@ -543,7 +565,7 @@ is divided into following sections:
<element name="customizePrototype" optional="true"/>
<sequential>
<property name="junit.forkmode" value="perTest"/>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
<mapper from="test-sys-prop.*" to="*" type="glob"/>
@ -619,7 +641,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="EsPasqua" testname="TestNG tests" workingDir="${work.dir}">
<testng classfilesetref="test.set" failureProperty="tests.failed" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="EsPasqua" testname="TestNG tests" workingDir="${work.dir}">
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
<propertyset>
<propertyref prefix="test-sys-prop."/>
@ -850,6 +872,9 @@ is divided into following sections:
<classpath>
<path path="@{classpath}"/>
</classpath>
<bootclasspath>
<path path="${platform.bootcp}"/>
</bootclasspath>
</nbjpdastart>
</sequential>
</macrodef>
@ -899,7 +924,7 @@ is divided into following sections:
<attribute default="jvm" name="jvm"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" module="@{modulename}">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}" module="@{modulename}">
<classpath>
<path path="@{classpath}"/>
</classpath>
@ -933,7 +958,7 @@ is divided into following sections:
<attribute default="jvm" name="jvm"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
<classpath>
<path path="@{classpath}"/>
</classpath>
@ -965,7 +990,7 @@ is divided into following sections:
<attribute default="jvm" name="jvm"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" jvm="${platform.java}">
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
@ -1199,7 +1224,7 @@ is divided into following sections:
<j2seproject3:copylibs manifest="${tmp.manifest.file}"/>
<echo level="info">To run this application from the command line without Ant, try:</echo>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<echo level="info">java -jar "${dist.jar.resolved}"</echo>
<echo level="info">${platform.java} -jar "${dist.jar.resolved}"</echo>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar,-do-jar-create-manifest,-do-jar-copy-manifest,-do-jar-set-mainclass,-do-jar-set-profile,-do-jar-set-splashscreen,-check-do-mkdist" if="do.archive" name="-do-jar-jar" unless="do.mkdist">
<j2seproject1:jar manifest="${tmp.manifest.file}"/>
@ -1301,8 +1326,8 @@ is divided into following sections:
<isset property="main.class.available"/>
</and>
</condition>
<property name="platform.jlink" value="${jdk.home}/bin/jlink"/>
<property name="jlink.systemmodules.internal" value="${jdk.home}/jmods"/>
<property name="platform.jlink" value="${platform.home}/bin/jlink"/>
<property name="jlink.systemmodules.internal" value="${platform.home}/jmods"/>
<exec executable="${platform.jlink}">
<arg value="--module-path"/>
<arg path="${jlink.systemmodules.internal}:${run.modulepath}:${dist.jar}"/>
@ -1495,16 +1520,19 @@ is divided into following sections:
</not>
</and>
</condition>
<exec executable="${platform.java}" failonerror="false" outputproperty="platform.version.output">
<arg value="-version"/>
</exec>
<condition else="" property="bug5101868workaround" value="*.java">
<matches pattern="1\.[56](\..*)?" string="${java.version}"/>
<matches multiline="true" pattern="1\.[56](\..*)?" string="${platform.version.output}"/>
</condition>
<condition else="" property="javadoc.html5.cmd.line.arg" value="-html5">
<and>
<isset property="javadoc.html5"/>
<available file="${jdk.home}${file.separator}lib${file.separator}jrt-fs.jar"/>
<available file="${platform.home}${file.separator}lib${file.separator}jrt-fs.jar"/>
</and>
</condition>
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
<javadoc additionalparam="-J-Dfile.encoding=${file.encoding} ${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" executable="${platform.javadoc}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
<classpath>
<path path="${javac.classpath}"/>
</classpath>

View File

@ -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

View File

@ -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

View File

@ -3,10 +3,12 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/giacomo/NetBeansProjects/Prodotti/src/prodotti/Alimentari.java</file>
<file>file:/home/giacomo/NetBeansProjects/Prodotti/src/prodotti/Prodotti.java</file>
<file>file:/home/giacomo/NetBeansProjects/Prodotti/src/prodotti/NonAlimentari.java</file>
<file>file:/home/giacomo/NetBeansProjects/Prodotti/src/prodotti/ListaSpesa.java</file>
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/NonAlimentari.java</file>
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/ListaSpesa.java</file>
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/DataFormattata.java</file>
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/Prodotti.java</file>
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/Alimentari.java</file>
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/Prodotti/src/prodotti/DataNumerica.java</file>
</group>
</open-files>
</project-private>

View File

@ -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}

View File

@ -4,6 +4,7 @@
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>EsPasqua</name>
<explicit-platform explicit-source-supported="true"/>
<source-roots>
<root id="src.dir"/>
</source-roots>

View File

@ -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() + "]";
}
}

View File

@ -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<DataFormattata> {
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();
}

View File

@ -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);
}
}

View File

@ -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<Prodotti> listaSpesa = new ArrayList<>();
Scanner in = new Scanner(System.in);
System.out.println("Hai la tessera fedeltà?");
boolean tessera = (in.next().equalsIgnoreCase()) ? 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 + "€ ---");
}
}

View File

@ -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() + "]";
}
}

View File

@ -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;

View File

@ -0,0 +1,73 @@
<?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="Research" default="default" basedir=".">
<description>Builds, tests, and runs the project Research.</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="Research-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>

View File

@ -0,0 +1,4 @@
#Wed, 12 Apr 2023 18:25:23 +0200
/home/gicorada/NetBeansProjects/Research=

View File

@ -0,0 +1,32 @@
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "Research.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.

View File

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
build.xml.data.CRC32=c8928208
build.xml.script.CRC32=1d33b430
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=c8928208
nbproject/build-impl.xml.script.CRC32=8b411319
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48

View File

@ -0,0 +1,2 @@
compile.on.save=true
user.properties.file=/home/gicorada/.netbeans/17/build.properties

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/gicorada/NetBeansProjects/Research/src/research/Research.java</file>
<file>file:/home/gicorada/NetBeansProjects/Research/src/research/Tester.java</file>
</group>
</open-files>
</project-private>

View File

@ -0,0 +1,95 @@
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}/Research.jar
dist.javadoc.dir=${dist.dir}/javadoc
dist.jlink.dir=${dist.dir}/jlink
dist.jlink.output=${dist.jlink.dir}/Research
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=17
javac.target=17
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=Research
main.class=research.Tester
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=Zulu_17.0.6_10
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

View File

@ -0,0 +1,16 @@
<?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>Research</name>
<explicit-platform explicit-source-supported="true"/>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

View File

@ -0,0 +1,40 @@
/*
* 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 research;
/**
*
* @author gicorada
*/
public class Research {
public static <T extends Comparable> int sequenziale(T oggetto, T[] array) {
for(int i = 0; i < array.length; i++) {
if(oggetto.compareTo(array[i]) == 0) return i;
}
return -1;
}
public static <T extends Comparable> int binario(T oggetto, T[] array) {
int primo = 0; //Primo elemento della parte selezionata
int ultimo = array.length - 1; //Ultimo elemento della parte selezionata
int medio; //Elemento centrale, idealmente l'elemento cercato
while(primo <= ultimo) {
medio = (primo + ultimo) / 2;
T ogMedio = array[medio];
if(oggetto.compareTo(ogMedio) < 0) ultimo = medio -1;
else {
if(oggetto.compareTo(ogMedio) > 0) {
primo = medio + 1;
}
else return medio;
}
}
return -1;
}
}

View File

@ -0,0 +1,29 @@
/*
* 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 research;
/**
*
* @author gicorada
*/
public class Tester {
public static void main(String[] args) {
int dim = 500000;
Integer[] lista = new Integer[dim];
for (int i = 0; i < dim; i++) {
lista[i] = i;
}
for (int i = 0; i < dim; i++) {
if(Research.sequenziale(i, lista) != Research.binario(i, lista)) {
System.out.println("ERRORE CON " + i);
}
if(i % 10000 == 0) System.out.println("Arrivato a " + i);
}
}
}