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

This commit is contained in:
Giacomo R. 2023-05-04 16:19:34 +02:00
commit a313c50eae
6 changed files with 33 additions and 47 deletions

View File

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

View File

@ -3,10 +3,7 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/> <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"> <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group> <group>
<file>file:/home/gicorada/NetBeansProjects/shape/src/shape/Shape.java</file> <file>file:/home/giacomo/Scrivania/Scuola/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Shape.java</file>
<file>file:/home/gicorada/NetBeansProjects/shape/src/shape/Circle.java</file>
<file>file:/home/gicorada/NetBeansProjects/shape/src/shape/Rectangle.java</file>
<file>file:/home/gicorada/NetBeansProjects/shape/src/shape/Tester.java</file>
</group> </group>
</open-files> </open-files>
</project-private> </project-private>

View File

@ -75,7 +75,7 @@ main.class=shape.Tester
manifest.file=manifest.mf manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false mkdist.disabled=false
platform.active=Zulu_17.0.6_10 platform.active=Oracle_OpenJDK_20_36
run.classpath=\ run.classpath=\
${javac.classpath}:\ ${javac.classpath}:\
${build.classes.dir} ${build.classes.dir}

View File

@ -1,43 +1,41 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package shape; package shape;
/** /**
* *
* @author gicorada * @author radaelli11353
*/ */
public class Circle extends Shape { public class Circle extends Shape {
private int xc, yc, r; private double xc;
private double yc;
private double r;
public Circle(int xc, int yc, int r) { public Circle(double xc, double yc, double r) {
this.xc = xc; this.xc = xc;
this.yc = yc; this.yc = yc;
this.r = r; this.r = r;
} }
public void setRadius(int r) { public void setRadius(double r) {
this.r = r; this.r = r;
} }
@Override @Override
public int width() { public double width() {
return r*2; return r*2;
} }
@Override @Override
public int height() { public double height() {
return r*2; return r*2;
} }
@Override @Override
public int posX() { public double posX() {
return xc - r; return xc - r;
} }
@Override @Override
public int posY() { public double posY() {
return yc - r; return yc - r;
} }
@ -55,6 +53,6 @@ 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 (xc == c.xc && yc == c.yc) && r == c.r; return Double.compare(xc, c.xc) && Double.compare(yc, c.yc) && Double.compare(r, c.r);
} }
} }

View File

@ -1,17 +1,16 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package shape; package shape;
/** /**
* *
* @author gicorada * @author radaelli11353
*/ */
public class Rectangle extends Shape { public class Rectangle extends Shape {
private int x, y, w, h; private double x;
private double y;
private double w;
private double h;
public Rectangle(int x, int y, int w, int h) { public Rectangle(double x, double y, double w, double h) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.w = w; this.w = w;
@ -19,22 +18,22 @@ public class Rectangle extends Shape {
} }
@Override @Override
public int width() { public double width() {
return w; return w;
} }
@Override @Override
public int height() { public double height() {
return h; return h;
} }
@Override @Override
public int posX() { public double posX() {
return x; return x;
} }
@Override @Override
public int posY() { public double posY() {
return y; return y;
} }
@ -53,8 +52,6 @@ public class Rectangle extends Shape {
if (o == null) return false; if (o == null) return false;
if (getClass() != o.getClass()) return false; if (getClass() != o.getClass()) return false;
Rectangle r = (Rectangle) o; Rectangle r = (Rectangle) o;
return w == r.w && h == r.h && x == r.x && y == r.y; return Double.compare(r, r.w) && Double.compare(h, r.h) && Double.compare(x, r.x) && Double.compare(y, r.y);
} }
} }

View File

@ -1,23 +1,17 @@
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package shape; package shape;
/** /**
* *
* @author gicorada * @author radaelli11353
*/ */
public abstract class Shape implements Comparable<Shape> { public abstract class Shape implements Comparable<Shape> {
private int w, h, x, y; public abstract double width();
public abstract double height();
public abstract int width(); public abstract double posX();
public abstract int height(); public abstract double posY();
public abstract int posX();
public abstract int posY();
@Override @Override
public int compareTo(Shape o) { public int compareTo(Shape o) {
return width()*height() - o.width()*o.height(); return Double.compare(width() * height(), o.width() * o.height());
} }
} }