Creating Dual class

This commit is contained in:
F. Y. H. 2023-05-18 23:45:24 +02:00
parent a2311b7bf6
commit 5669350291
Signed by: Alnotz
GPG key ID: B808CA1113935C00
2 changed files with 60 additions and 0 deletions

49
fr/alnotz/Dual.java Normal file
View file

@ -0,0 +1,49 @@
package fr.alnotz;
public class Dual implements IsDual{
private double r;
private double d;
public Dual(double r, double d){
this.r = r;
this.d = d;
}
public static Dual plus(IsDual dual0, IsDual dual1){
return new Dual(dual0.getR() + dual1.getR(), dual0.getD() + dual1.getD());
}
@Override
public double getR() {
return this.r;
}
@Override
public double getD() {
return this.d;
}
@Override
public void setR(double r) {
this.r = r;
}
@Override
public void setD(double d) {
this.d = d;
}
@Override
public void plus(IsDual dual) {
this.r += dual.getR();
this.d += dual.getD();
}
@Override
public void times(IsDual dual) {
this.r *= dual.getR();
this.d = 2 * this.r * dual.getD();
}
@Override
public boolean equals(IsDual dual) {
return this.r == dual.getR() && this.d == dual.getR();
}
}

11
fr/alnotz/IsDual.java Normal file
View file

@ -0,0 +1,11 @@
package fr.alnotz;
public interface IsDual {
double getR();
double getD();
void setR(double r);
void setD(double d);
void plus(IsDual dual);
void times(IsDual dual);
boolean equals(IsDual dual);
}