Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
7c9a936fec | |||
de3c827937 | |||
9ed76d07ce | |||
84b40cc8e9 | |||
f4b0fa1846 | |||
3ed4f15666 | |||
4c8c038eec | |||
76aa0080c6 | |||
2bfc3a410c | |||
6ad6edfb8d |
2
.gitignore
vendored
2
.gitignore
vendored
@ -36,3 +36,5 @@ hs_err_pid*
|
||||
/NetBeans Projects/BankAccount/dist/
|
||||
/NetBeans Projects/Inventory/build/
|
||||
/NetBeans Projects/Grafica/nbproject/private/
|
||||
/NetBeans Projects/Ricorsione/nbproject/private/
|
||||
/NetBeans Projects/Ricorsione/build/
|
||||
|
2
NetBeans Projects/.directory
Normal file
2
NetBeans Projects/.directory
Normal file
@ -0,0 +1,2 @@
|
||||
[Desktop Entry]
|
||||
Icon=org.apache.netbeans
|
@ -1,73 +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="Grafica" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project Grafica.</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="Grafica-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>
|
||||
<?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="Grafica" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project Grafica.</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="Grafica-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>
|
||||
|
4
NetBeans Projects/Grafica/build/built-jar.properties
Normal file
4
NetBeans Projects/Grafica/build/built-jar.properties
Normal file
@ -0,0 +1,4 @@
|
||||
#Mon, 22 May 2023 12:35:23 +0200
|
||||
|
||||
|
||||
Z\:\\Informatica\\Java\\NetBeans\\Grafica=
|
@ -1,3 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
||||
|
@ -119,43 +119,7 @@ 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">
|
||||
<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=<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)
|
||||
</fail>
|
||||
<property name="platform.java" value="${java.home}/bin/java"/>
|
||||
<available file="${manifest.file}" property="manifest.available"/>
|
||||
<condition property="splashscreen.available">
|
||||
<and>
|
||||
@ -278,6 +242,20 @@ 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"/>
|
||||
@ -365,7 +343,7 @@ is divided into following sections:
|
||||
</path>
|
||||
</resourcecount>
|
||||
</condition>
|
||||
<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}">
|
||||
<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}">
|
||||
<src>
|
||||
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
|
||||
<include name="*"/>
|
||||
@ -416,7 +394,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}" executable="${platform.javac}" fork="yes" 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}" fork="${javac.fork}" 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="*"/>
|
||||
@ -458,7 +436,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}" executable="${platform.javac}" fork="yes" 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}" fork="${javac.fork}" 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="*"/>
|
||||
@ -537,7 +515,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}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
@ -565,7 +543,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}" jvm="${platform.java}" showoutput="true" tempdir="${build.dir}">
|
||||
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" forkmode="${junit.forkmode}" showoutput="true" tempdir="${build.dir}">
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper from="test-sys-prop.*" to="*" type="glob"/>
|
||||
@ -641,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" jvm="${platform.java}" listeners="org.testng.reporters.VerboseReporter" methods="${testng.methods.arg}" mode="${testng.mode}" outputdir="${build.test.results.dir}" suitename="Grafica" 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="Grafica" testname="TestNG tests" workingDir="${work.dir}">
|
||||
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
||||
<propertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
@ -872,9 +850,6 @@ is divided into following sections:
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<bootclasspath>
|
||||
<path path="${platform.bootcp}"/>
|
||||
</bootclasspath>
|
||||
</nbjpdastart>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
@ -924,7 +899,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" jvm="${platform.java}" module="@{modulename}">
|
||||
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true" module="@{modulename}">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
@ -958,7 +933,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" jvm="${platform.java}">
|
||||
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
@ -990,7 +965,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" jvm="${platform.java}">
|
||||
<java classname="@{classname}" dir="${work.dir}" failonerror="${java.failonerror}" fork="true">
|
||||
<jvmarg line="${endorsed.classpath.cmd.line.arg}"/>
|
||||
<jvmarg value="-Dfile.encoding=${runtime.encoding}"/>
|
||||
<redirector errorencoding="${runtime.encoding}" inputencoding="${runtime.encoding}" outputencoding="${runtime.encoding}"/>
|
||||
@ -1224,7 +1199,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">${platform.java} -jar "${dist.jar.resolved}"</echo>
|
||||
<echo level="info">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}"/>
|
||||
@ -1326,8 +1301,8 @@ is divided into following sections:
|
||||
<isset property="main.class.available"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="platform.jlink" value="${platform.home}/bin/jlink"/>
|
||||
<property name="jlink.systemmodules.internal" value="${platform.home}/jmods"/>
|
||||
<property name="platform.jlink" value="${jdk.home}/bin/jlink"/>
|
||||
<property name="jlink.systemmodules.internal" value="${jdk.home}/jmods"/>
|
||||
<exec executable="${platform.jlink}">
|
||||
<arg value="--module-path"/>
|
||||
<arg path="${jlink.systemmodules.internal}:${run.modulepath}:${dist.jar}"/>
|
||||
@ -1520,19 +1495,16 @@ 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 multiline="true" pattern="1\.[56](\..*)?" string="${platform.version.output}"/>
|
||||
<matches pattern="1\.[56](\..*)?" string="${java.version}"/>
|
||||
</condition>
|
||||
<condition else="" property="javadoc.html5.cmd.line.arg" value="-html5">
|
||||
<and>
|
||||
<isset property="javadoc.html5"/>
|
||||
<available file="${platform.home}${file.separator}lib${file.separator}jrt-fs.jar"/>
|
||||
<available file="${jdk.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}" 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}">
|
||||
<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}">
|
||||
<classpath>
|
||||
<path path="${javac.classpath}"/>
|
||||
</classpath>
|
||||
|
@ -1,8 +1,8 @@
|
||||
build.xml.data.CRC32=acf20e45
|
||||
build.xml.data.CRC32=7a406286
|
||||
build.xml.script.CRC32=761ebeaf
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.106.0.48
|
||||
build.xml.stylesheet.CRC32=f85dc8f2@1.99.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=acf20e45
|
||||
nbproject/build-impl.xml.script.CRC32=a1851d6a
|
||||
nbproject/build-impl.xml.data.CRC32=7a406286
|
||||
nbproject/build-impl.xml.script.CRC32=e96aa72e
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48
|
||||
|
@ -1,95 +1,97 @@
|
||||
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}/Grafica.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
dist.jlink.dir=${dist.dir}/jlink
|
||||
dist.jlink.output=${dist.jlink.dir}/Grafica
|
||||
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=Grafica
|
||||
main.class=shape.ShapesViewer
|
||||
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
|
||||
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=Grafica
|
||||
application.vendor=radaelli11353
|
||||
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}/Grafica.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
dist.jlink.dir=${dist.dir}/jlink
|
||||
dist.jlink.output=${dist.jlink.dir}/Grafica
|
||||
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=Grafica
|
||||
main.class=shape.ShapesViewer
|
||||
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 +1,15 @@
|
||||
<?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>Grafica</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>
|
||||
<?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>Grafica</name>
|
||||
<source-roots>
|
||||
<root id="src.dir"/>
|
||||
</source-roots>
|
||||
<test-roots>
|
||||
<root id="test.src.dir"/>
|
||||
</test-roots>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
|
@ -1,28 +1,28 @@
|
||||
package investment;
|
||||
|
||||
public class BankAccount {
|
||||
private double balance;
|
||||
|
||||
public BankAccount() {
|
||||
balance = 0;
|
||||
}
|
||||
|
||||
public BankAccount(double initialBalance) {
|
||||
balance = initialBalance;
|
||||
}
|
||||
|
||||
public void deposit(double amount) {
|
||||
double newBalance = balance + amount;
|
||||
balance = newBalance;
|
||||
}
|
||||
|
||||
public void withdraw(double amount) {
|
||||
double newBalance = balance - amount;
|
||||
balance = newBalance;
|
||||
}
|
||||
|
||||
public double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
}
|
||||
|
||||
package investment;
|
||||
|
||||
public class BankAccount {
|
||||
private double balance;
|
||||
|
||||
public BankAccount() {
|
||||
balance = 0;
|
||||
}
|
||||
|
||||
public BankAccount(double initialBalance) {
|
||||
balance = initialBalance;
|
||||
}
|
||||
|
||||
public void deposit(double amount) {
|
||||
double newBalance = balance + amount;
|
||||
balance = newBalance;
|
||||
}
|
||||
|
||||
public void withdraw(double amount) {
|
||||
double newBalance = balance - amount;
|
||||
balance = newBalance;
|
||||
}
|
||||
|
||||
public double getBalance() {
|
||||
return balance;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package investment;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
class InterestListener1 implements ActionListener {
|
||||
private static final double INITIAL_BALANCE = 1000;
|
||||
private final BankAccount account;
|
||||
private final double INTEREST_RATE;
|
||||
|
||||
public InterestListener1(double interest) {
|
||||
account = new BankAccount(INITIAL_BALANCE);
|
||||
INTEREST_RATE = interest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
double interest = account.getBalance() * INTEREST_RATE / 100;
|
||||
account.deposit(interest);
|
||||
System.out.println("saldo: " + account.getBalance());
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package investment;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
class InterestListener2 implements ActionListener {
|
||||
private static final double INITIAL_BALANCE = 1000;
|
||||
private BankAccount account;
|
||||
private final double INTEREST_RATE;
|
||||
private final JLabel label;
|
||||
|
||||
public InterestListener2(double interest, JLabel label) {
|
||||
account = new BankAccount(INITIAL_BALANCE);
|
||||
INTEREST_RATE = interest;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
double interest = account.getBalance() * INTEREST_RATE / 100;
|
||||
account.deposit(interest);
|
||||
label.setText("Saldo: " + account.getBalance());
|
||||
System.out.println(label.getText());
|
||||
}
|
||||
}
|
@ -1,39 +1,28 @@
|
||||
package investment;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class InvestmentViewer1 {
|
||||
private static final int FRAME_WIDTH = 120;
|
||||
private static final int FRAME_HEIGHT = 60;
|
||||
|
||||
private static final double INTEREST_RATE = 10;
|
||||
private static final double INITIAL_BALANCE = 1000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
BankAccount account = new BankAccount(INITIAL_BALANCE);
|
||||
|
||||
JButton button = new JButton("Aggiungi interessi");
|
||||
frame.add(button);
|
||||
|
||||
class InterestListener implements ActionListener {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
double interest = account.getBalance() * INTEREST_RATE / 100;
|
||||
account.deposit(interest);
|
||||
System.out.println("saldo: " + account.getBalance());
|
||||
}
|
||||
}
|
||||
|
||||
ActionListener listener = new InterestListener();
|
||||
button.addActionListener(listener);
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
package investment;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class InvestmentViewer1 {
|
||||
private static final int FRAME_WIDTH = 120;
|
||||
private static final int FRAME_HEIGHT = 60;
|
||||
|
||||
private static final double INTEREST_RATE = 10;
|
||||
private static final double INITIAL_BALANCE = 1000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
JButton button = new JButton("Aggiungi interessi");
|
||||
frame.add(button);
|
||||
|
||||
ActionListener listener = new InterestListener1(INTEREST_RATE);
|
||||
button.addActionListener(listener);
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
package investment;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
public class InvestmentViewer1Lambda {
|
||||
private static final int FRAME_WIDTH = 120;
|
||||
private static final int FRAME_HEIGHT = 60;
|
||||
|
||||
private static final double INTEREST_RATE = 10;
|
||||
private static final double INITIAL_BALANCE = 1000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
BankAccount account = new BankAccount(INITIAL_BALANCE);
|
||||
|
||||
JButton button = new JButton("Aggiungi interessi");
|
||||
frame.add(button);
|
||||
|
||||
button.addActionListener(event -> {
|
||||
double interest = account.getBalance() * INTEREST_RATE / 100;
|
||||
account.deposit(interest);
|
||||
System.out.println("Saldo: " + account.getBalance());
|
||||
});
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,46 +1,38 @@
|
||||
package investment;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class InvestmentViewer2 {
|
||||
private static final int FRAME_WIDTH = 400;
|
||||
private static final int FRAME_HEIGHT = 100;
|
||||
|
||||
private static final double INTEREST_RATE = 10;
|
||||
private static final double INITIAL_BALANCE = 1000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
BankAccount account = new BankAccount(INITIAL_BALANCE);
|
||||
|
||||
JButton button = new JButton("Aggiungi interessi");
|
||||
JLabel label = new JLabel("Saldo: " + account.getBalance());
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
panel.add(button);
|
||||
panel.add(label);
|
||||
frame.add(panel);
|
||||
|
||||
class InterestListener implements ActionListener {
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
double interest = account.getBalance() * INTEREST_RATE / 100;
|
||||
account.deposit(interest);
|
||||
label.setText("Saldo: " + account.getBalance());
|
||||
}
|
||||
}
|
||||
|
||||
ActionListener listener = new InterestListener();
|
||||
button.addActionListener(listener);
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
package investment;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class InvestmentViewer2 {
|
||||
private static final int FRAME_WIDTH = 400;
|
||||
private static final int FRAME_HEIGHT = 100;
|
||||
|
||||
private static final double INTEREST_RATE = 10;
|
||||
private static final double INITIAL_BALANCE = 1000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
BankAccount account = new BankAccount(INITIAL_BALANCE);
|
||||
|
||||
JButton button = new JButton("Aggiungi interessi");
|
||||
JLabel label = new JLabel("Saldo: " + account.getBalance());
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
panel.add(button);
|
||||
panel.add(label);
|
||||
frame.add(panel);
|
||||
|
||||
|
||||
ActionListener listener = new InterestListener2(INTEREST_RATE, label);
|
||||
button.addActionListener(listener);
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
package investment;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
public class InvestmentViewer2Lambda {
|
||||
private static final int FRAME_WIDTH = 400;
|
||||
private static final int FRAME_HEIGHT = 100;
|
||||
|
||||
private static final double INTEREST_RATE = 10;
|
||||
private static final double INITIAL_BALANCE = 1000;
|
||||
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
BankAccount account = new BankAccount(INITIAL_BALANCE);
|
||||
|
||||
JButton button = new JButton("Aggiungi interessi");
|
||||
JLabel label = new JLabel("Saldo: " + account.getBalance());
|
||||
JPanel panel = new JPanel();
|
||||
|
||||
panel.add(button);
|
||||
panel.add(label);
|
||||
frame.add(panel);
|
||||
|
||||
|
||||
ActionListener listener = new InterestListener2(INTEREST_RATE, label);
|
||||
button.addActionListener(event -> {
|
||||
double interest = account.getBalance() * INTEREST_RATE / 100;
|
||||
account.deposit(interest);
|
||||
label.setText("Saldo: " + account.getBalance());
|
||||
System.out.println(label.getText());
|
||||
});
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,53 +1,53 @@
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class Circle extends Shape {
|
||||
private double r;
|
||||
|
||||
public Circle(double xc, double yc, double r) {
|
||||
super(xc-r, yc-r);
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public void setRadius(double r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double width() {
|
||||
return r*2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double height() {
|
||||
return r*2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 83 * hash + (int) (Double.doubleToLongBits(this.r) ^ (Double.doubleToLongBits(this.r) >>> 32));
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
if (getClass() != o.getClass()) return false;
|
||||
Circle c = (Circle) o;
|
||||
return r == c.r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
Ellipse2D.Double e = new Ellipse2D.Double(posX(), posY(), width(), height());
|
||||
|
||||
g2.draw(e);
|
||||
}
|
||||
}
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Ellipse2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class Circle extends Shape {
|
||||
private double r;
|
||||
|
||||
public Circle(double xc, double yc, double r) {
|
||||
super(xc-r, yc-r);
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
public void setRadius(double r) {
|
||||
this.r = r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double width() {
|
||||
return r*2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double height() {
|
||||
return r*2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 5;
|
||||
hash = 83 * hash + (int) (Double.doubleToLongBits(this.r) ^ (Double.doubleToLongBits(this.r) >>> 32));
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
if (getClass() != o.getClass()) return false;
|
||||
Circle c = (Circle) o;
|
||||
return r == c.r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
Ellipse2D.Double e = new Ellipse2D.Double(posX(), posY(), width(), height());
|
||||
|
||||
g2.draw(e);
|
||||
}
|
||||
}
|
||||
|
@ -1,47 +1,47 @@
|
||||
package shape;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public class Geometria {
|
||||
private ArrayList<Shape> elementi;
|
||||
|
||||
public Geometria() {
|
||||
elementi = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void riempiACaso(int size) {
|
||||
Random r = new Random();
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
int s = r.nextInt(3);
|
||||
|
||||
double x = r.nextDouble()*300;
|
||||
double y = r.nextDouble()*300;
|
||||
|
||||
switch(s) {
|
||||
case 0:
|
||||
//circle
|
||||
double raggio = r.nextDouble()*30;
|
||||
elementi.add(new Circle(x, y, raggio));
|
||||
break;
|
||||
case 1:
|
||||
//square
|
||||
double lato = r.nextDouble()*40;
|
||||
elementi.add(new Square(x, y, lato));
|
||||
break;
|
||||
case 2:
|
||||
//triangolo
|
||||
double base = r.nextDouble()*30;
|
||||
double altezza = r.nextDouble()*30;
|
||||
elementi.add(new TriangoloRettangolo(x, y, base, altezza));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2) {
|
||||
for(Shape s : elementi) s.draw(g2);
|
||||
}
|
||||
}
|
||||
package shape;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
public class Geometria {
|
||||
private ArrayList<Shape> elementi;
|
||||
|
||||
public Geometria() {
|
||||
elementi = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void riempiACaso(int size) {
|
||||
Random r = new Random();
|
||||
|
||||
for(int i = 0; i < size; i++) {
|
||||
int s = r.nextInt(3);
|
||||
|
||||
double x = r.nextDouble()*300;
|
||||
double y = r.nextDouble()*300;
|
||||
|
||||
switch(s) {
|
||||
case 0:
|
||||
//circle
|
||||
double raggio = r.nextDouble()*30;
|
||||
elementi.add(new Circle(x, y, raggio));
|
||||
break;
|
||||
case 1:
|
||||
//square
|
||||
double lato = r.nextDouble()*40;
|
||||
elementi.add(new Square(x, y, lato));
|
||||
break;
|
||||
case 2:
|
||||
//triangolo
|
||||
double base = r.nextDouble()*30;
|
||||
double altezza = r.nextDouble()*30;
|
||||
elementi.add(new TriangoloRettangolo(x, y, base, altezza));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(Graphics2D g2) {
|
||||
for(Shape s : elementi) s.draw(g2);
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public abstract class Shape implements Comparable<Shape> {
|
||||
private double x, y;
|
||||
|
||||
public Shape(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public abstract double width();
|
||||
public abstract double height();
|
||||
public double posX() {
|
||||
return x;
|
||||
}
|
||||
public double posY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public abstract void draw(Graphics2D g2);
|
||||
|
||||
@Override
|
||||
public int compareTo(Shape o) {
|
||||
return Double.compare(width() * height(), o.width() * o.height());
|
||||
}
|
||||
}
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public abstract class Shape implements Comparable<Shape> {
|
||||
private double x, y;
|
||||
|
||||
public Shape(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public abstract double width();
|
||||
public abstract double height();
|
||||
public double posX() {
|
||||
return x;
|
||||
}
|
||||
public double posY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public abstract void draw(Graphics2D g2);
|
||||
|
||||
@Override
|
||||
public int compareTo(Shape o) {
|
||||
return Double.compare(width() * height(), o.width() * o.height());
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,22 @@
|
||||
package shape;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class ShapesViewer {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
|
||||
frame.setSize(600, 600);
|
||||
frame.setTitle("Circles");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Tester component = new Tester();
|
||||
frame.add(component);
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
package shape;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class ShapesViewer {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new JFrame();
|
||||
|
||||
frame.setSize(600, 600);
|
||||
frame.setTitle("Circles");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
|
||||
Tester component = new Tester();
|
||||
frame.add(component);
|
||||
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,50 +1,50 @@
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class Square extends Shape {
|
||||
private double l;
|
||||
|
||||
public Square(double x, double y, double l) {
|
||||
super(x, y);
|
||||
this.l = l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double width() {
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double height() {
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 97 * hash + (int) (Double.doubleToLongBits(this.l) ^ (Double.doubleToLongBits(this.l) >>> 32));
|
||||
hash = 97 * hash + super.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
if (getClass() != o.getClass()) return false;
|
||||
Square s = (Square) o;
|
||||
return l == s.l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
Rectangle r = new Rectangle((int)posX(), (int)posY(), (int)width(), (int)height());
|
||||
|
||||
g2.draw(r);
|
||||
}
|
||||
}
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class Square extends Shape {
|
||||
private double l;
|
||||
|
||||
public Square(double x, double y, double l) {
|
||||
super(x, y);
|
||||
this.l = l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double width() {
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double height() {
|
||||
return l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 97 * hash + (int) (Double.doubleToLongBits(this.l) ^ (Double.doubleToLongBits(this.l) >>> 32));
|
||||
hash = 97 * hash + super.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null) return false;
|
||||
if (getClass() != o.getClass()) return false;
|
||||
Square s = (Square) o;
|
||||
return l == s.l;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
Rectangle r = new Rectangle((int)posX(), (int)posY(), (int)width(), (int)height());
|
||||
|
||||
g2.draw(r);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,21 @@
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class Tester extends JComponent{
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
Geometria geom = new Geometria();
|
||||
|
||||
geom.riempiACaso(10);
|
||||
|
||||
geom.draw(g2);
|
||||
}
|
||||
}
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class Tester extends JComponent{
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
|
||||
Geometria geom = new Geometria();
|
||||
|
||||
geom.riempiACaso(10);
|
||||
|
||||
geom.draw(g2);
|
||||
}
|
||||
}
|
||||
|
@ -1,62 +1,62 @@
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Line2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class TriangoloRettangolo extends Shape {
|
||||
private double b;
|
||||
private double h;
|
||||
|
||||
public TriangoloRettangolo(double x, double y, double b, double h) {
|
||||
super(x, y);
|
||||
this.b = b;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double width() {
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double height() {
|
||||
return h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 53 * hash + (int) (Double.doubleToLongBits(this.b) ^ (Double.doubleToLongBits(this.b) >>> 32));
|
||||
hash = 53 * hash + (int) (Double.doubleToLongBits(this.h) ^ (Double.doubleToLongBits(this.h) >>> 32));
|
||||
hash = 53 * hash + super.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TriangoloRettangolo t = (TriangoloRettangolo) o;
|
||||
if (Double.doubleToLongBits(b) != Double.doubleToLongBits(t.b)) {
|
||||
return false;
|
||||
}
|
||||
return Double.doubleToLongBits(h) != Double.doubleToLongBits(t.h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
Line2D.Double altezza = new Line2D.Double(posX(), posY(), posX(), posY()+height());
|
||||
Line2D.Double base = new Line2D.Double(posX(), posY()+height(), posX()+width(), posY()+height());
|
||||
Line2D.Double ipotenusa = new Line2D.Double(posX(), posY(), posX()+width(), posY()+height());
|
||||
|
||||
g2.draw(altezza);
|
||||
g2.draw(base);
|
||||
g2.draw(ipotenusa);
|
||||
}
|
||||
|
||||
}
|
||||
package shape;
|
||||
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Line2D;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class TriangoloRettangolo extends Shape {
|
||||
private double b;
|
||||
private double h;
|
||||
|
||||
public TriangoloRettangolo(double x, double y, double b, double h) {
|
||||
super(x, y);
|
||||
this.b = b;
|
||||
this.h = h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double width() {
|
||||
return b;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double height() {
|
||||
return h;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 3;
|
||||
hash = 53 * hash + (int) (Double.doubleToLongBits(this.b) ^ (Double.doubleToLongBits(this.b) >>> 32));
|
||||
hash = 53 * hash + (int) (Double.doubleToLongBits(this.h) ^ (Double.doubleToLongBits(this.h) >>> 32));
|
||||
hash = 53 * hash + super.hashCode();
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TriangoloRettangolo t = (TriangoloRettangolo) o;
|
||||
if (Double.doubleToLongBits(b) != Double.doubleToLongBits(t.b)) {
|
||||
return false;
|
||||
}
|
||||
return Double.doubleToLongBits(h) != Double.doubleToLongBits(t.h);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Graphics2D g2) {
|
||||
Line2D.Double altezza = new Line2D.Double(posX(), posY(), posX(), posY()+height());
|
||||
Line2D.Double base = new Line2D.Double(posX(), posY()+height(), posX()+width(), posY()+height());
|
||||
Line2D.Double ipotenusa = new Line2D.Double(posX(), posY(), posX()+width(), posY()+height());
|
||||
|
||||
g2.draw(altezza);
|
||||
g2.draw(base);
|
||||
g2.draw(ipotenusa);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package timer.DateViewer;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.util.Date;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class DateComponent extends JComponent {
|
||||
private Date now;
|
||||
|
||||
public DateComponent() {
|
||||
now = new Date();
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
recalculateDate();
|
||||
g2.drawString(now.toString(), 100, 100);
|
||||
}
|
||||
|
||||
public void recalculateDate() {
|
||||
now = new Date();
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package timer.DateViewer;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.Timer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class DateFrame extends JFrame {
|
||||
private static final int FRAME_WIDTH = 300;
|
||||
private static final int FRAME_HEIGHT = 400;
|
||||
|
||||
private DateComponent scene;
|
||||
|
||||
public DateFrame() {
|
||||
scene = new DateComponent();
|
||||
add(scene);
|
||||
|
||||
setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||
|
||||
final int DELAY = 100;
|
||||
Timer t = new Timer(DELAY, e -> {
|
||||
scene.repaint();
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package timer.DateViewer;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class DateViewer {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new DateFrame();
|
||||
frame.setTitle("Date and Hour");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package timer.MovingRectangle;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class RectangleComponent extends JComponent{
|
||||
private static final int BOX_X = 100;
|
||||
private static final int BOX_Y = 100;
|
||||
private static final int BOX_WIDTH = 20;
|
||||
private static final int BOX_HEIGHT = 30;
|
||||
|
||||
private Rectangle box;
|
||||
|
||||
public RectangleComponent() {
|
||||
box = new Rectangle(BOX_X, BOX_Y, BOX_WIDTH, BOX_HEIGHT);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.draw(box);
|
||||
}
|
||||
|
||||
public void moveRectangleBy(int dx, int dy) {
|
||||
box.translate(dx, dy);
|
||||
repaint();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package timer.MovingRectangle;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.Timer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class RectangleFrame extends JFrame {
|
||||
private static final int FRAME_WIDTH = 300;
|
||||
private static final int FRAME_HEIGHT = 400;
|
||||
|
||||
private RectangleComponent scene;
|
||||
|
||||
public RectangleFrame() {
|
||||
scene = new RectangleComponent();
|
||||
add(scene);
|
||||
|
||||
setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||
|
||||
final int DELAY = 100;
|
||||
Timer t = new Timer(DELAY, e -> {
|
||||
scene.moveRectangleBy(1, 1);
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package timer.MovingRectangle;
|
||||
|
||||
import timer.MovingRectangleBorders.RectangleFrame;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class RectangleViewer {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new RectangleFrame();
|
||||
frame.setTitle("An animated rectangle");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package timer.MovingRectangleBorders;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import javax.swing.JComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class RectangleComponent extends JComponent{
|
||||
private static final int BOX_X = 100;
|
||||
private static final int BOX_Y = 100;
|
||||
private static final int BOX_WIDTH = 20;
|
||||
private static final int BOX_HEIGHT = 30;
|
||||
|
||||
private Rectangle box;
|
||||
private int xMov = 1;
|
||||
private int yMov = 1;
|
||||
|
||||
public RectangleComponent() {
|
||||
box = new Rectangle(BOX_X, BOX_Y, BOX_WIDTH, BOX_HEIGHT);
|
||||
}
|
||||
|
||||
public void paintComponent(Graphics g) {
|
||||
Graphics2D g2 = (Graphics2D) g;
|
||||
g2.draw(box);
|
||||
}
|
||||
|
||||
public void moveRectangle() {
|
||||
double x = box.getX();
|
||||
double y = box.getY();
|
||||
xMov = (x + box.getWidth() < getWidth()) ? xMov : -1;
|
||||
yMov = (y + box.getHeight() < getHeight()) ? yMov : -1;
|
||||
xMov = (x >= 0) ? xMov : 1;
|
||||
yMov = (y >= 0) ? yMov : 1;
|
||||
|
||||
box.translate(xMov, yMov);
|
||||
repaint();
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package timer.MovingRectangleBorders;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.Timer;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class RectangleFrame extends JFrame {
|
||||
public static final int FRAME_WIDTH = 300;
|
||||
public static final int FRAME_HEIGHT = 400;
|
||||
|
||||
private RectangleComponent scene;
|
||||
|
||||
public RectangleFrame() {
|
||||
scene = new RectangleComponent();
|
||||
add(scene);
|
||||
|
||||
setSize(FRAME_WIDTH, FRAME_HEIGHT);
|
||||
|
||||
final int DELAY = 100;
|
||||
Timer t = new Timer(DELAY, e -> {
|
||||
scene.moveRectangle();
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package timer.MovingRectangleBorders;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class RectangleViewer {
|
||||
public static void main(String[] args) {
|
||||
JFrame frame = new RectangleFrame();
|
||||
frame.setTitle("An animated rectangle");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
73
NetBeans Projects/Ricorsione/build.xml
Normal file
73
NetBeans Projects/Ricorsione/build.xml
Normal 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="Ricorsione" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project Ricorsione.</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="Ricorsione-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>
|
3
NetBeans Projects/Ricorsione/manifest.mf
Normal file
3
NetBeans Projects/Ricorsione/manifest.mf
Normal file
@ -0,0 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
X-COMMENT: Main-Class will be added automatically by build
|
||||
|
1799
NetBeans Projects/Ricorsione/nbproject/build-impl.xml
Normal file
1799
NetBeans Projects/Ricorsione/nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
||||
build.xml.data.CRC32=b3c20d1e
|
||||
build.xml.script.CRC32=f1f4ef54
|
||||
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=b3c20d1e
|
||||
nbproject/build-impl.xml.script.CRC32=151ad6e6
|
||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48
|
95
NetBeans Projects/Ricorsione/nbproject/project.properties
Normal file
95
NetBeans Projects/Ricorsione/nbproject/project.properties
Normal 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}/Ricorsione.jar
|
||||
dist.javadoc.dir=${dist.dir}/javadoc
|
||||
dist.jlink.dir=${dist.dir}/jlink
|
||||
dist.jlink.output=${dist.jlink.dir}/Ricorsione
|
||||
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=Ricorsione
|
||||
main.class=ricorsione.Ricorsione
|
||||
manifest.file=manifest.mf
|
||||
meta.inf.dir=${src.dir}/META-INF
|
||||
mkdist.disabled=false
|
||||
platform.active=Oracle_OpenJDK_20_36
|
||||
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
|
16
NetBeans Projects/Ricorsione/nbproject/project.xml
Normal file
16
NetBeans Projects/Ricorsione/nbproject/project.xml
Normal 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>Ricorsione</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>
|
@ -12,13 +12,15 @@ public class Ricorsione {
|
||||
* @param pos posizione dell'ultimo elemento
|
||||
* @return quanti numeri dispari sono presenti nell'array
|
||||
*/
|
||||
public static int contaDispari(int[] x, int pos) {
|
||||
private static int contaDispari(int[] x, int pos) {
|
||||
if(pos < 0) return 0;
|
||||
int contatore = (x[pos] % 2 == 1) ? 1 : 0;
|
||||
|
||||
return contatore + contaDispari(x, pos - 1);
|
||||
return ((x[pos] % 2 == 1) ? 1 : 0) + contaDispari(x, pos - 1);
|
||||
}
|
||||
|
||||
|
||||
public static int contaDispari(int[] x) {
|
||||
return contaDispari(x, x.length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* metodo statico ricorsivo che restituisce la somma degli elementi
|
||||
* di un array di interi
|
||||
@ -26,13 +28,15 @@ public class Ricorsione {
|
||||
* @param pos posizione dell'ultimo elemento
|
||||
* @return somma degli elementi dell'array
|
||||
*/
|
||||
public static int somma(int[] x, int pos) {
|
||||
private static int somma(int[] x, int pos) {
|
||||
if(pos < 0) return 0;
|
||||
int contatore = x[pos];
|
||||
|
||||
return contatore + somma(x, pos - 1);
|
||||
return x[pos] + somma(x, pos - 1);
|
||||
}
|
||||
|
||||
|
||||
public static int somma(int[] x) {
|
||||
return somma(x, x.length - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* metodo statico ricorsivo che verifica se una stringa x è contenuta
|
||||
* nella stringa y
|
||||
@ -41,7 +45,7 @@ public class Ricorsione {
|
||||
* @param pos posizione iniziale
|
||||
* @return x è contenuta in y
|
||||
*/
|
||||
public static boolean cerca(String x, String y, int pos) {
|
||||
private static boolean cerca(String x, String y, int pos) {
|
||||
if (y.length() - pos < x.length()) return false;
|
||||
|
||||
if (y.substring(pos, pos + x.length()).equals(x)) {
|
||||
@ -50,12 +54,71 @@ public class Ricorsione {
|
||||
|
||||
return cerca(x, y, pos + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean cerca(String x, String y) {
|
||||
return cerca(x, y, 0);
|
||||
}
|
||||
|
||||
public static int potenzaS(int a, int b) {
|
||||
if(b==0) return 1;
|
||||
else if(a%b == 0) {
|
||||
int parz = potenzaS(a, b/2);
|
||||
return parz * parz;
|
||||
}
|
||||
return potenzaS(a, b-1);
|
||||
}
|
||||
|
||||
public static int potenzaD(int a, int b) {
|
||||
if(b == 0) return 1;
|
||||
return a * potenzaD(a, b-1);
|
||||
}
|
||||
|
||||
|
||||
public static <T extends Comparable> int binSearch(T[] x, T el) {
|
||||
int min = 0;
|
||||
int max = x.length -1;
|
||||
while(min <= max) {
|
||||
int med = (max+min)/2;
|
||||
int tmp = el.compareTo(x[med]);
|
||||
if(tmp == 0) return med;
|
||||
if(tmp < 0) max = med - 1;
|
||||
if(tmp > 0) min = med + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] array = {1, 2, 3, 4, 5, 6};
|
||||
System.out.println(contaDispari(array, array.length - 1));
|
||||
System.out.println(somma(array, array.length - 1));
|
||||
System.out.println(cerca("Test", "Testare", 0));
|
||||
int[] array = {1, 6, 4, 5};
|
||||
System.out.println(contaDispari(array));
|
||||
System.out.println(somma(array));
|
||||
System.out.println(cerca("Test", "Testare"));
|
||||
|
||||
System.out.println(binSearch());
|
||||
|
||||
|
||||
int base = 2, esponente = 30;
|
||||
|
||||
////////
|
||||
long startTimeD = System.nanoTime();
|
||||
potenzaD(base, esponente);
|
||||
long endTimeD = System.nanoTime();
|
||||
|
||||
long timeElapsedD = endTimeD - startTimeD;
|
||||
System.out.print("D time: " + timeElapsedD + " ns");
|
||||
|
||||
////////
|
||||
|
||||
long startTimeS = System.nanoTime();
|
||||
potenzaS(base, esponente);
|
||||
long endTimeS = System.nanoTime();
|
||||
|
||||
long timeElapsedS = endTimeS - startTimeS;
|
||||
System.out.println(" - S time: " + timeElapsedS + " ns");
|
||||
|
||||
System.out.println("Best time: " + ((timeElapsedD > timeElapsedS) ? "Smart" : "Dumb"));
|
||||
|
||||
|
||||
////////
|
||||
}
|
||||
}
|
||||
|
75
NetBeans Projects/Ricorsione/src/ricorsione/Ricorsione2.java
Normal file
75
NetBeans Projects/Ricorsione/src/ricorsione/Ricorsione2.java
Normal file
@ -0,0 +1,75 @@
|
||||
package ricorsione;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Collezione 2 di metodi ricorsivi utilizzata per gli esercizi per il 6/6/23
|
||||
* @author radaelli11353
|
||||
*/
|
||||
public class Ricorsione2 {
|
||||
public static ArrayList<Integer> scomposizioneFattoriPrimi(int n) {
|
||||
ArrayList<Integer> fattori = new ArrayList<>();
|
||||
scomposizioneFattoriPrimi(n, fattori);
|
||||
return fattori;
|
||||
}
|
||||
|
||||
public static void scomposizioneFattoriPrimi(int n, ArrayList<Integer> x) {
|
||||
if(n == 1) return;
|
||||
for (int i = 2; i <= n; i++) {
|
||||
if (n % i == 0) {
|
||||
x.add(i);
|
||||
n = n / i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (n > 1) {
|
||||
scomposizioneFattoriPrimi(n, x);
|
||||
}
|
||||
}
|
||||
|
||||
public static String reverse(String text) {
|
||||
if (text.length() <= 1) {
|
||||
return text;
|
||||
}
|
||||
//return reverse(text.substring(1)) + text.charAt(0);
|
||||
//return reverse(text, text.length() - 1);
|
||||
char[] b = text.toCharArray();
|
||||
reverse(b, 0);
|
||||
return String.valueOf(b);
|
||||
}
|
||||
|
||||
public static String reverse(String text, int index) {
|
||||
if(index == 0) return String.valueOf(text.charAt(index));
|
||||
return text.charAt(index) + reverse(text, index-1);
|
||||
}
|
||||
|
||||
public static void reverse(char[] x, int pos) {
|
||||
int l = x.length;
|
||||
if(pos < l/2) {
|
||||
char tmp = x[pos];
|
||||
x[pos] = x[l - 1 - pos];
|
||||
x[l - 1 - pos] = tmp;
|
||||
reverse(x, pos + 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
int numero = 4;
|
||||
ArrayList<Integer> fattoriPrimi = scomposizioneFattoriPrimi(numero);
|
||||
|
||||
System.out.println("Fattori primi di " + numero + ":");
|
||||
for (int fattore : fattoriPrimi) {
|
||||
System.out.println(fattore);
|
||||
}
|
||||
|
||||
System.out.println("----------------------");
|
||||
|
||||
String input = "Hello!";
|
||||
String reversed = reverse(input);
|
||||
|
||||
System.out.println("Originale: " + input);
|
||||
System.out.println("Invertita: " + reversed);
|
||||
}
|
||||
}
|
52
corr-verifica-recupero/ContoCorrente.java
Executable file
52
corr-verifica-recupero/ContoCorrente.java
Executable file
@ -0,0 +1,52 @@
|
||||
public class ContoCorrente implements Comparable<ContoCorrente> {
|
||||
private double saldo;
|
||||
private int numero;
|
||||
private static int conta = 0;
|
||||
|
||||
public ContoCorrente(double iniz) {
|
||||
if(iniz < 0) throw new IllegalArgumentException();
|
||||
saldo = iniz;
|
||||
numero = ++conta;
|
||||
}
|
||||
|
||||
public void deposita(double somma) {
|
||||
if(somma <= 0) throw new IllegalArgumentException();
|
||||
saldo += somma;
|
||||
}
|
||||
|
||||
public void preleva(double somma) {
|
||||
if(somma <= 0 || somma > saldo) throw new IllegalArgumentException();
|
||||
saldo += somma;
|
||||
}
|
||||
|
||||
public double getSaldo() {
|
||||
return saldo;
|
||||
}
|
||||
|
||||
public double getNumero() {
|
||||
return numero;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Conto " + numero + ", saldo: " + saldo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(o == null) return false;
|
||||
if(getClass() != o.getClass()) return false;
|
||||
ContoCorrente c = (ContoCorrente) o;
|
||||
return saldo == c.saldo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (int)saldo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(ContoCorrente c) {
|
||||
return Double.compare(saldo, c.saldo);
|
||||
}
|
||||
}
|
32
corr-verifica-recupero/ContoDeposito.java
Executable file
32
corr-verifica-recupero/ContoDeposito.java
Executable file
@ -0,0 +1,32 @@
|
||||
public class ContoDeposito extends ContoCorrente {
|
||||
private double tasso;
|
||||
|
||||
public ContoDeposito(double iniz, double tasso) {
|
||||
super(iniz);
|
||||
this.tasso = tasso;
|
||||
}
|
||||
|
||||
public void setTasso(double tasso) {
|
||||
this.tasso = tasso;
|
||||
}
|
||||
|
||||
public void addInteressi() {
|
||||
deposita(getSaldo() * tasso / 100);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + ", tasso: " + tasso;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(!super.equals(o)) return false;
|
||||
ContoDeposito c = (ContoDeposito) o;
|
||||
return tasso == c.tasso;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
return super.hashCode() + (int)tasso;
|
||||
}
|
||||
}
|
25
corr-verifica-recupero/ContoIntestato.java
Normal file
25
corr-verifica-recupero/ContoIntestato.java
Normal file
@ -0,0 +1,25 @@
|
||||
public class ContoIntestato extends ContoCorrente {
|
||||
private String nome;
|
||||
|
||||
public ContoIntestato(double iniz, String nome) {
|
||||
super(iniz);
|
||||
this.nome = nome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " intestato a " + nome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if(!super.equals(o)) return false;
|
||||
ContoIntestato c = (ContoIntestato) o;
|
||||
return nome.equals(c.nome);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return super.hashCode() + nome.hashCode();
|
||||
}
|
||||
}
|
36
corr-verifica-recupero/Filiale.java
Normal file
36
corr-verifica-recupero/Filiale.java
Normal file
@ -0,0 +1,36 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
||||
public class Filiale {
|
||||
private ArrayList<ContoCorrente> conti;
|
||||
|
||||
public Filiale() {
|
||||
conti = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void add(ContoCorrente c) {
|
||||
conti.add(c);
|
||||
}
|
||||
|
||||
public void remove(int num) {
|
||||
for(ContoCorrente c : conti) {
|
||||
if(c.getNumero() == num) {
|
||||
conti.remove(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String text = "";
|
||||
|
||||
Collections.sort(conti);
|
||||
|
||||
for(ContoCorrente c : conti) {
|
||||
text += c + "\n";
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
}
|
15
corr-verifica-recupero/Tester.java
Normal file
15
corr-verifica-recupero/Tester.java
Normal file
@ -0,0 +1,15 @@
|
||||
public class Tester {
|
||||
public static void main(String[] args) {
|
||||
Filiale f = new Filiale();
|
||||
|
||||
f.add(new ContoCorrente(1000));
|
||||
f.add(new ContoDeposito(500, 10));
|
||||
f.add(new ContoIntestato(1500, "Test"));
|
||||
|
||||
f.add(new ContoIntestato(2001, "quello da rimuovere"));
|
||||
f.remove(4);
|
||||
|
||||
System.out.println(f);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user