Compare commits
8 Commits
f7f5965619
...
main
Author | SHA1 | Date | |
---|---|---|---|
d8ed527c23 | |||
c50566f7bc | |||
f7c307a294 | |||
50f648d037 | |||
7d0cbb0d02 | |||
26ec9ddbad | |||
8dceaf0edb | |||
f273879242 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -35,3 +35,4 @@ hs_err_pid*
|
|||||||
/NetBeans Projects/BankAccount/build/
|
/NetBeans Projects/BankAccount/build/
|
||||||
/NetBeans Projects/BankAccount/dist/
|
/NetBeans Projects/BankAccount/dist/
|
||||||
/NetBeans Projects/Inventory/build/
|
/NetBeans Projects/Inventory/build/
|
||||||
|
/NetBeans Projects/Grafica/nbproject/private/
|
||||||
|
@@ -7,8 +7,8 @@
|
|||||||
<!-- the Compile on Save feature is turned off for the project. -->
|
<!-- the Compile on Save feature is turned off for the project. -->
|
||||||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||||
<!-- in the project's Project Properties dialog box.-->
|
<!-- in the project's Project Properties dialog box.-->
|
||||||
<project name="shape" default="default" basedir=".">
|
<project name="Grafica" default="default" basedir=".">
|
||||||
<description>Builds, tests, and runs the project shape.</description>
|
<description>Builds, tests, and runs the project Grafica.</description>
|
||||||
<import file="nbproject/build-impl.xml"/>
|
<import file="nbproject/build-impl.xml"/>
|
||||||
<!--
|
<!--
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@
|
|||||||
|
|
||||||
An example of overriding the target for project execution could look like this:
|
An example of overriding the target for project execution could look like this:
|
||||||
|
|
||||||
<target name="run" depends="shape-impl.jar">
|
<target name="run" depends="Grafica-impl.jar">
|
||||||
<exec dir="bin" executable="launcher.exe">
|
<exec dir="bin" executable="launcher.exe">
|
||||||
<arg file="${dist.jar}"/>
|
<arg file="${dist.jar}"/>
|
||||||
</exec>
|
</exec>
|
3
NetBeans Projects/Grafica/manifest.mf
Normal file
3
NetBeans Projects/Grafica/manifest.mf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
X-COMMENT: Main-Class will be added automatically by build
|
||||||
|
|
@@ -19,7 +19,7 @@ is divided into following sections:
|
|||||||
- cleanup
|
- cleanup
|
||||||
|
|
||||||
-->
|
-->
|
||||||
<project xmlns:if="ant:if" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" xmlns:unless="ant:unless" basedir=".." default="default" name="shape-impl">
|
<project xmlns:if="ant:if" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" xmlns:unless="ant:unless" basedir=".." default="default" name="Grafica-impl">
|
||||||
<fail message="Please build using Ant 1.8.0 or higher.">
|
<fail message="Please build using Ant 1.8.0 or higher.">
|
||||||
<condition>
|
<condition>
|
||||||
<not>
|
<not>
|
||||||
@@ -641,7 +641,7 @@ is divided into following sections:
|
|||||||
</fileset>
|
</fileset>
|
||||||
</union>
|
</union>
|
||||||
<taskdef classname="org.testng.TestNGAntTask" classpath="${run.test.classpath}" name="testng"/>
|
<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="shape" 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="Grafica" testname="TestNG tests" workingDir="${work.dir}">
|
||||||
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
<xmlfileset dir="${build.test.classes.dir}" includes="@{testincludes}"/>
|
||||||
<propertyset>
|
<propertyset>
|
||||||
<propertyref prefix="test-sys-prop."/>
|
<propertyref prefix="test-sys-prop."/>
|
||||||
@@ -738,7 +738,7 @@ is divided into following sections:
|
|||||||
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
|
<condition else="-testclass @{testClass}" property="test.class.or.method" value="-methods @{testClass}.@{testMethod}">
|
||||||
<isset property="test.method"/>
|
<isset property="test.method"/>
|
||||||
</condition>
|
</condition>
|
||||||
<condition else="-suitename shape -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
|
<condition else="-suitename Grafica -testname @{testClass} ${test.class.or.method}" property="testng.cmd.args" value="@{testClass}">
|
||||||
<matches pattern=".*\.xml" string="@{testClass}"/>
|
<matches pattern=".*\.xml" string="@{testClass}"/>
|
||||||
</condition>
|
</condition>
|
||||||
<delete dir="${build.test.results.dir}" quiet="true"/>
|
<delete dir="${build.test.results.dir}" quiet="true"/>
|
||||||
@@ -1082,7 +1082,7 @@ is divided into following sections:
|
|||||||
<delete file="${built-jar.properties}" quiet="true"/>
|
<delete file="${built-jar.properties}" quiet="true"/>
|
||||||
</target>
|
</target>
|
||||||
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
|
<target if="already.built.jar.${basedir}" name="-warn-already-built-jar">
|
||||||
<echo level="warn" message="Cycle detected: shape was already built"/>
|
<echo level="warn" message="Cycle detected: Grafica was already built"/>
|
||||||
</target>
|
</target>
|
||||||
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
|
<target depends="init,-deps-jar-init" name="deps-jar" unless="no.deps">
|
||||||
<mkdir dir="${build.dir}"/>
|
<mkdir dir="${build.dir}"/>
|
||||||
@@ -1756,7 +1756,7 @@ is divided into following sections:
|
|||||||
<delete file="${built-clean.properties}" quiet="true"/>
|
<delete file="${built-clean.properties}" quiet="true"/>
|
||||||
</target>
|
</target>
|
||||||
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
|
<target if="already.built.clean.${basedir}" name="-warn-already-built-clean">
|
||||||
<echo level="warn" message="Cycle detected: shape was already built"/>
|
<echo level="warn" message="Cycle detected: Grafica was already built"/>
|
||||||
</target>
|
</target>
|
||||||
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
|
<target depends="init,-deps-clean-init" name="deps-clean" unless="no.deps">
|
||||||
<mkdir dir="${build.dir}"/>
|
<mkdir dir="${build.dir}"/>
|
@@ -1,8 +1,8 @@
|
|||||||
build.xml.data.CRC32=184eed3a
|
build.xml.data.CRC32=acf20e45
|
||||||
build.xml.script.CRC32=04b06f70
|
build.xml.script.CRC32=761ebeaf
|
||||||
build.xml.stylesheet.CRC32=f85dc8f2@1.106.0.48
|
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.
|
# 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.
|
# 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=184eed3a
|
nbproject/build-impl.xml.data.CRC32=acf20e45
|
||||||
nbproject/build-impl.xml.script.CRC32=677ad60c
|
nbproject/build-impl.xml.script.CRC32=a1851d6a
|
||||||
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48
|
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.106.0.48
|
@@ -1,10 +1,9 @@
|
|||||||
annotation.processing.enabled=true
|
annotation.processing.enabled=true
|
||||||
annotation.processing.enabled.in.editor=false
|
annotation.processing.enabled.in.editor=false
|
||||||
|
annotation.processing.processor.options=
|
||||||
annotation.processing.processors.list=
|
annotation.processing.processors.list=
|
||||||
annotation.processing.run.all.processors=true
|
annotation.processing.run.all.processors=true
|
||||||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
application.title=shape
|
|
||||||
application.vendor=gicorada
|
|
||||||
build.classes.dir=${build.dir}/classes
|
build.classes.dir=${build.dir}/classes
|
||||||
build.classes.excludes=**/*.java,**/*.form
|
build.classes.excludes=**/*.java,**/*.form
|
||||||
# This directory is removed when the project is cleaned:
|
# This directory is removed when the project is cleaned:
|
||||||
@@ -29,11 +28,10 @@ debug.test.modulepath=\
|
|||||||
dist.archive.excludes=
|
dist.archive.excludes=
|
||||||
# This directory is removed when the project is cleaned:
|
# This directory is removed when the project is cleaned:
|
||||||
dist.dir=dist
|
dist.dir=dist
|
||||||
dist.jar=${dist.dir}/shape.jar
|
dist.jar=${dist.dir}/Grafica.jar
|
||||||
dist.javadoc.dir=${dist.dir}/javadoc
|
dist.javadoc.dir=${dist.dir}/javadoc
|
||||||
dist.jlink.dir=${dist.dir}/jlink
|
dist.jlink.dir=${dist.dir}/jlink
|
||||||
dist.jlink.output=${dist.jlink.dir}/shape
|
dist.jlink.output=${dist.jlink.dir}/Grafica
|
||||||
endorsed.classpath=
|
|
||||||
excludes=
|
excludes=
|
||||||
includes=**
|
includes=**
|
||||||
jar.compress=false
|
jar.compress=false
|
||||||
@@ -72,7 +70,7 @@ jlink.additionalmodules=
|
|||||||
# The jlink additional command line parameters
|
# The jlink additional command line parameters
|
||||||
jlink.additionalparam=
|
jlink.additionalparam=
|
||||||
jlink.launcher=true
|
jlink.launcher=true
|
||||||
jlink.launcher.name=shape
|
jlink.launcher.name=Grafica
|
||||||
main.class=shape.ShapesViewer
|
main.class=shape.ShapesViewer
|
||||||
manifest.file=manifest.mf
|
manifest.file=manifest.mf
|
||||||
meta.inf.dir=${src.dir}/META-INF
|
meta.inf.dir=${src.dir}/META-INF
|
@@ -3,7 +3,7 @@
|
|||||||
<type>org.netbeans.modules.java.j2seproject</type>
|
<type>org.netbeans.modules.java.j2seproject</type>
|
||||||
<configuration>
|
<configuration>
|
||||||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||||
<name>shape</name>
|
<name>Grafica</name>
|
||||||
<explicit-platform explicit-source-supported="true"/>
|
<explicit-platform explicit-source-supported="true"/>
|
||||||
<source-roots>
|
<source-roots>
|
||||||
<root id="src.dir"/>
|
<root id="src.dir"/>
|
28
NetBeans Projects/Grafica/src/investment/BankAccount.java
Normal file
28
NetBeans Projects/Grafica/src/investment/BankAccount.java
Normal file
@@ -0,0 +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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,39 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -0,0 +1,46 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@@ -8,13 +8,10 @@ import java.awt.geom.Ellipse2D;
|
|||||||
* @author radaelli11353
|
* @author radaelli11353
|
||||||
*/
|
*/
|
||||||
public class Circle extends Shape {
|
public class Circle extends Shape {
|
||||||
private double xc;
|
|
||||||
private double yc;
|
|
||||||
private double r;
|
private double r;
|
||||||
|
|
||||||
public Circle(double xc, double yc, double r) {
|
public Circle(double xc, double yc, double r) {
|
||||||
this.xc = xc;
|
super(xc-r, yc-r);
|
||||||
this.yc = yc;
|
|
||||||
this.r = r;
|
this.r = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,21 +29,9 @@ public class Circle extends Shape {
|
|||||||
return r*2;
|
return r*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posX() {
|
|
||||||
return xc - r;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posY() {
|
|
||||||
return yc - r;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 5;
|
int hash = 5;
|
||||||
hash = 83 * hash + (int) (Double.doubleToLongBits(this.xc) ^ (Double.doubleToLongBits(this.xc) >>> 32));
|
|
||||||
hash = 83 * hash + (int) (Double.doubleToLongBits(this.yc) ^ (Double.doubleToLongBits(this.yc) >>> 32));
|
|
||||||
hash = 83 * hash + (int) (Double.doubleToLongBits(this.r) ^ (Double.doubleToLongBits(this.r) >>> 32));
|
hash = 83 * hash + (int) (Double.doubleToLongBits(this.r) ^ (Double.doubleToLongBits(this.r) >>> 32));
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
@@ -56,12 +41,12 @@ public class Circle extends Shape {
|
|||||||
if (o == null) return false;
|
if (o == null) return false;
|
||||||
if (getClass() != o.getClass()) return false;
|
if (getClass() != o.getClass()) return false;
|
||||||
Circle c = (Circle) o;
|
Circle c = (Circle) o;
|
||||||
return Double.compare(xc, c.xc) == 0 && Double.compare(yc, c.yc) == 0 && Double.compare(r, c.r) == 0;
|
return r == c.r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2) {
|
public void draw(Graphics2D g2) {
|
||||||
Ellipse2D.Double e = new Ellipse2D.Double(xc-r, yc-r, r*2, r*2);
|
Ellipse2D.Double e = new Ellipse2D.Double(posX(), posY(), width(), height());
|
||||||
|
|
||||||
g2.draw(e);
|
g2.draw(e);
|
||||||
}
|
}
|
47
NetBeans Projects/Grafica/src/shape/Geometria.java
Normal file
47
NetBeans Projects/Grafica/src/shape/Geometria.java
Normal file
@@ -0,0 +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);
|
||||||
|
}
|
||||||
|
}
|
32
NetBeans Projects/Grafica/src/shape/Shape.java
Normal file
32
NetBeans Projects/Grafica/src/shape/Shape.java
Normal file
@@ -0,0 +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());
|
||||||
|
}
|
||||||
|
}
|
@@ -8,13 +8,10 @@ import java.awt.Rectangle;
|
|||||||
* @author radaelli11353
|
* @author radaelli11353
|
||||||
*/
|
*/
|
||||||
public class Square extends Shape {
|
public class Square extends Shape {
|
||||||
private double x;
|
|
||||||
private double y;
|
|
||||||
private double l;
|
private double l;
|
||||||
|
|
||||||
public Square(double x, double y, double l) {
|
public Square(double x, double y, double l) {
|
||||||
this.x = x;
|
super(x, y);
|
||||||
this.y = y;
|
|
||||||
this.l = l;
|
this.l = l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,22 +25,11 @@ public class Square extends Shape {
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hash = 7;
|
int hash = 7;
|
||||||
hash = 97 * hash + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
|
|
||||||
hash = 97 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
|
|
||||||
hash = 97 * hash + (int) (Double.doubleToLongBits(this.l) ^ (Double.doubleToLongBits(this.l) >>> 32));
|
hash = 97 * hash + (int) (Double.doubleToLongBits(this.l) ^ (Double.doubleToLongBits(this.l) >>> 32));
|
||||||
|
hash = 97 * hash + super.hashCode();
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,12 +38,12 @@ public class Square extends Shape {
|
|||||||
if (o == null) return false;
|
if (o == null) return false;
|
||||||
if (getClass() != o.getClass()) return false;
|
if (getClass() != o.getClass()) return false;
|
||||||
Square s = (Square) o;
|
Square s = (Square) o;
|
||||||
return Double.compare(l, s.l) == 0 && Double.compare(x, s.x) == 0 && Double.compare(y, s.y) == 0;
|
return l == s.l;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Graphics2D g2) {
|
public void draw(Graphics2D g2) {
|
||||||
Rectangle r = new Rectangle((int)x, (int)y, (int)l, (int)l);
|
Rectangle r = new Rectangle((int)posX(), (int)posY(), (int)width(), (int)height());
|
||||||
|
|
||||||
g2.draw(r);
|
g2.draw(r);
|
||||||
}
|
}
|
21
NetBeans Projects/Grafica/src/shape/Tester.java
Normal file
21
NetBeans Projects/Grafica/src/shape/Tester.java
Normal file
@@ -0,0 +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);
|
||||||
|
}
|
||||||
|
}
|
62
NetBeans Projects/Grafica/src/shape/TriangoloRettangolo.java
Normal file
62
NetBeans Projects/Grafica/src/shape/TriangoloRettangolo.java
Normal file
@@ -0,0 +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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
61
NetBeans Projects/Ricorsione/src/ricorsione/Ricorsione.java
Normal file
61
NetBeans Projects/Ricorsione/src/ricorsione/Ricorsione.java
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
package ricorsione;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collezione di metodi ricorsivi
|
||||||
|
* @author radaelli11353
|
||||||
|
*/
|
||||||
|
public class Ricorsione {
|
||||||
|
/**
|
||||||
|
* metodo statico ricorsivo che conta quanti numeri dispari sono presenti
|
||||||
|
* in un array di interi
|
||||||
|
* @param x array di interi
|
||||||
|
* @param pos posizione dell'ultimo elemento
|
||||||
|
* @return quanti numeri dispari sono presenti nell'array
|
||||||
|
*/
|
||||||
|
public 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* metodo statico ricorsivo che restituisce la somma degli elementi
|
||||||
|
* di un array di interi
|
||||||
|
* @param x array di interi
|
||||||
|
* @param pos posizione dell'ultimo elemento
|
||||||
|
* @return somma degli elementi dell'array
|
||||||
|
*/
|
||||||
|
public static int somma(int[] x, int pos) {
|
||||||
|
if(pos < 0) return 0;
|
||||||
|
int contatore = x[pos];
|
||||||
|
|
||||||
|
return contatore + somma(x, pos - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* metodo statico ricorsivo che verifica se una stringa x è contenuta
|
||||||
|
* nella stringa y
|
||||||
|
* @param x stringa che deve essere contenuta
|
||||||
|
* @param y stringa che deve contenere
|
||||||
|
* @param pos posizione iniziale
|
||||||
|
* @return x è contenuta in y
|
||||||
|
*/
|
||||||
|
public 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)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cerca(x, y, pos + 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));
|
||||||
|
}
|
||||||
|
}
|
@@ -1,8 +0,0 @@
|
|||||||
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
|
|
@@ -1,14 +0,0 @@
|
|||||||
<?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:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Square.java</file>
|
|
||||||
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Tester.java</file>
|
|
||||||
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Shape.java</file>
|
|
||||||
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Circle.java</file>
|
|
||||||
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/TriangoloRettangolo.java</file>
|
|
||||||
<file>file:/media/gicorada/Scuola/Anni%20Severi/22-23/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/ShapesViewer.java</file>
|
|
||||||
</group>
|
|
||||||
</open-files>
|
|
||||||
</project-private>
|
|
@@ -1,21 +0,0 @@
|
|||||||
package shape;
|
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author radaelli11353
|
|
||||||
*/
|
|
||||||
public abstract class Shape implements Comparable<Shape> {
|
|
||||||
public abstract double width();
|
|
||||||
public abstract double height();
|
|
||||||
public abstract double posX();
|
|
||||||
public abstract double posY();
|
|
||||||
|
|
||||||
public abstract void draw(Graphics2D g2);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Shape o) {
|
|
||||||
return Double.compare(width() * height(), o.width() * o.height());
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,35 +0,0 @@
|
|||||||
package shape;
|
|
||||||
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import javax.swing.JComponent;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author radaelli11353
|
|
||||||
*/
|
|
||||||
public class Tester extends JComponent{
|
|
||||||
public static void main(String[] args) {
|
|
||||||
Shape c1 = new Circle(2, 3, 1);
|
|
||||||
Shape c2 = new Circle(2, 3, 1);
|
|
||||||
|
|
||||||
System.out.println(c1.posX() + ", " +c1.posY());
|
|
||||||
System.out.println(c1.width() + ", " +c1.height());
|
|
||||||
System.out.println(c1.equals(c2));
|
|
||||||
|
|
||||||
((Circle) c2).setRadius(2);
|
|
||||||
System.out.println(c2.posX() + ", " + c2.posY());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void paintComponent(Graphics g) {
|
|
||||||
Graphics2D g2 = (Graphics2D) g;
|
|
||||||
|
|
||||||
Shape s1 = new Circle(88, 200, 50);
|
|
||||||
Shape s2 = new Square(200, 100, 100);
|
|
||||||
Shape s3 = new TriangoloRettangolo(200, 100, 100, 100);
|
|
||||||
|
|
||||||
s1.draw(g2);
|
|
||||||
s2.draw(g2);
|
|
||||||
s3.draw(g2);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,88 +0,0 @@
|
|||||||
package shape;
|
|
||||||
|
|
||||||
import java.awt.Graphics2D;
|
|
||||||
import java.awt.geom.Line2D;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author radaelli11353
|
|
||||||
*/
|
|
||||||
public class TriangoloRettangolo extends Shape {
|
|
||||||
private double b;
|
|
||||||
private double h;
|
|
||||||
private double x;
|
|
||||||
private double y;
|
|
||||||
|
|
||||||
public TriangoloRettangolo(double b, double h, double x, double y) {
|
|
||||||
this.b = b;
|
|
||||||
this.h = h;
|
|
||||||
this.x = x;
|
|
||||||
this.y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double width() {
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double height() {
|
|
||||||
return h;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posX() {
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double posY() {
|
|
||||||
return y;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 + (int) (Double.doubleToLongBits(this.x) ^ (Double.doubleToLongBits(this.x) >>> 32));
|
|
||||||
hash = 53 * hash + (int) (Double.doubleToLongBits(this.y) ^ (Double.doubleToLongBits(this.y) >>> 32));
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj) {
|
|
||||||
if (this == obj) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (obj == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (getClass() != obj.getClass()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final TriangoloRettangolo other = (TriangoloRettangolo) obj;
|
|
||||||
if (Double.doubleToLongBits(this.b) != Double.doubleToLongBits(other.b)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (Double.doubleToLongBits(this.h) != Double.doubleToLongBits(other.h)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (Double.doubleToLongBits(this.x) != Double.doubleToLongBits(other.x)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return Double.doubleToLongBits(this.y) == Double.doubleToLongBits(other.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void draw(Graphics2D g2) {
|
|
||||||
Line2D.Double altezza = new Line2D.Double(x, y, x, y+h);
|
|
||||||
Line2D.Double base = new Line2D.Double(x, y+h, x+b, y+h);
|
|
||||||
Line2D.Double ipotenusa = new Line2D.Double(x, y, x+b, y+h);
|
|
||||||
|
|
||||||
g2.draw(altezza);
|
|
||||||
g2.draw(base);
|
|
||||||
g2.draw(ipotenusa);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
20
corr-verifica-2maggio/Collezione.java
Normal file
20
corr-verifica-2maggio/Collezione.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class Collezione {
|
||||||
|
private String nome;
|
||||||
|
private ArrayList<OperaDArte> opere;
|
||||||
|
|
||||||
|
public Collezione(String nome) {
|
||||||
|
this.nome = nome;
|
||||||
|
opere = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOpera(OperaDArte o) {
|
||||||
|
opere.add(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return nome + "{" + opere.toString() + "}";
|
||||||
|
}
|
||||||
|
}
|
35
corr-verifica-2maggio/OperaDArte.java
Normal file
35
corr-verifica-2maggio/OperaDArte.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
public abstract class OperaDArte implements Comparable<OperaDArte> {
|
||||||
|
private String titolo;
|
||||||
|
private String autore;
|
||||||
|
|
||||||
|
public OperaDArte(String titolo, String autore) {
|
||||||
|
this.titolo = titolo;
|
||||||
|
this.autore = autore;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract double ingombro();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(o==null || o.getClass() != getClass()) return false;
|
||||||
|
OperaDArte op = (OperaDArte) o;
|
||||||
|
|
||||||
|
return titolo.equals(op.titolo) && autore.equals(op.autore);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return titolo.hashCode() + autore.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(OperaDArte o) {
|
||||||
|
return Double.compare(ingombro(), o.ingombro());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return titolo + " di " + autore;
|
||||||
|
}
|
||||||
|
}
|
32
corr-verifica-2maggio/Quadro.java
Normal file
32
corr-verifica-2maggio/Quadro.java
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
public class Quadro extends OperaDArte {
|
||||||
|
private double larghezza;
|
||||||
|
private double altezza;
|
||||||
|
|
||||||
|
public Quadro(String titolo, String autore, double larghezza, double altezza) {
|
||||||
|
super(titolo, autore);
|
||||||
|
this.larghezza = larghezza;
|
||||||
|
this.altezza = altezza;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double ingombro() {
|
||||||
|
return larghezza * altezza;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + larghezza + "x" + altezza + "(l*h)";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(!super.equals(o)) return false;
|
||||||
|
Quadro q = (Quadro) o;
|
||||||
|
return larghezza == q.larghezza && altezza == q.altezza;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return super.hashCode() + (int)larghezza + (int)altezza;
|
||||||
|
}
|
||||||
|
}
|
35
corr-verifica-2maggio/Scultura.java
Normal file
35
corr-verifica-2maggio/Scultura.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
public class Scultura extends OperaDArte {
|
||||||
|
private double larghezza;
|
||||||
|
private double altezza;
|
||||||
|
private double profondita;
|
||||||
|
|
||||||
|
public Scultura(String titolo, String autore, double larghezza, double altezza, double profondita) {
|
||||||
|
super(titolo, autore);
|
||||||
|
|
||||||
|
this.larghezza = larghezza;
|
||||||
|
this.altezza = altezza;
|
||||||
|
this.profondita = profondita;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double ingombro() {
|
||||||
|
return larghezza * altezza * profondita;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + larghezza + "x" + altezza + "x" + profondita + "(l*h*p)";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if(!super.equals(o)) return false;
|
||||||
|
Scultura s = (Scultura) o;
|
||||||
|
return larghezza == s.larghezza && altezza == s.altezza && profondita == s.profondita;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return super.hashCode() + (int)larghezza + (int)altezza + (int)profondita;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user