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
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"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/gicorada/NetBeansProjects/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>
<file>file:/home/giacomo/Scrivania/Scuola/Informatica/java-scuola/NetBeans%20Projects/shape/src/shape/Shape.java</file>
</group>
</open-files>
</project-private>

View File

@ -75,7 +75,7 @@ main.class=shape.Tester
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=Zulu_17.0.6_10
platform.active=Oracle_OpenJDK_20_36
run.classpath=\
${javac.classpath}:\
${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;
/**
*
* @author gicorada
* @author radaelli11353
*/
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.yc = yc;
this.r = r;
}
public void setRadius(int r) {
public void setRadius(double r) {
this.r = r;
}
@Override
public int width() {
public double width() {
return r*2;
}
@Override
public int height() {
public double height() {
return r*2;
}
@Override
public int posX() {
public double posX() {
return xc - r;
}
@Override
public int posY() {
public double posY() {
return yc - r;
}
@ -55,6 +53,6 @@ public class Circle extends Shape {
if (o == null) return false;
if (getClass() != o.getClass()) return false;
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;
/**
*
* @author gicorada
* @author radaelli11353
*/
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.y = y;
this.w = w;
@ -19,22 +18,22 @@ public class Rectangle extends Shape {
}
@Override
public int width() {
public double width() {
return w;
}
@Override
public int height() {
public double height() {
return h;
}
@Override
public int posX() {
public double posX() {
return x;
}
@Override
public int posY() {
public double posY() {
return y;
}
@ -53,8 +52,6 @@ public class Rectangle extends Shape {
if (o == null) return false;
if (getClass() != o.getClass()) return false;
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;
/**
*
* @author gicorada
* @author radaelli11353
*/
public abstract class Shape implements Comparable<Shape> {
private int w, h, x, y;
public abstract int width();
public abstract int height();
public abstract int posX();
public abstract int posY();
public abstract double width();
public abstract double height();
public abstract double posX();
public abstract double posY();
@Override
public int compareTo(Shape o) {
return width()*height() - o.width()*o.height();
return Double.compare(width() * height(), o.width() * o.height());
}
}
}