Untitled
unknown
java
5 years ago
1.7 kB
19
No Index
public class Zespolone {
private double x;
private double y;
public Zespolone(double real, double imag) {
x = real;
y = imag;
}
public double getX() { return x; }
public double getY() { return y; }
public void setX(double x) { this.x = x; }
public void setY(double y) { this.y = y; }
public Zespolone dodawanie(Zespolone b,double real,double imag) {
real = this.x + b.x;
imag = this.y + b.y;
return new Zespolone(real, imag);
}
public Zespolone odejmowanie(Zespolone b,double real,double imag) {
real = this.x - b.x;
imag = this.y - b.y;
return new Zespolone(real, imag);
}
public Zespolone mnozenie(Zespolone b,double real,double imag) {
real = this.x * b.y - this.y * b.y;
imag = this.x * b.y + this.y * b.y;
return new Zespolone(real, imag);
}
public Zespolone dzielenie(Zespolone b) {
return this.dzielenie(b.odwrotnosc());
}
public Zespolone sprzezenie() {
return new Zespolone(x, -y);
}
public Zespolone odwrotnosc() {
double waga = x*x + y*y;
return new Zespolone(x / waga, -y / waga);
}
public double modul() {
return Math.sqrt(x*x+y*y);
}
public String wypisz() {
if (getX() == 0) return y + "i";
else if (getY() == 0) return x + "i";
else if (getX() == 0 && getY()==0) return "0";
else if (getY() < 0 && getY()==getY()&& getX()!=0) return x + y + "i";
else if (getY() < 0 && getY()==getY()&& getX()==0) return y + "i";
final String s = getX() + " + " + getY() + "i";
return s;
}
}
Editor is loading...