MP3_REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

This commit is contained in:
2023-02-14 19:29:36 -06:00
parent 1c029f747f
commit 15a01d81fd
9 changed files with 227 additions and 74 deletions

View File

@@ -15,7 +15,8 @@ public class MP3_CalebFontenot {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the first complex number: ");
double a = input.nextDouble();
@@ -39,7 +40,6 @@ public class MP3_CalebFontenot {
System.out.println(c3.getRealPart());
System.out.println(c3.getImaginaryPart());
}
}
@@ -50,59 +50,88 @@ class Complex {
private double a;
private double b;
private final double i = Math.sqrt(-1);
public Complex() {
public Complex()
{
this.a = 0;
}
public Complex(double a) {
public Complex(double a)
{
this.a = a;
this.b = 0;
}
public Complex(double a, double b) {
public Complex(double a, double b)
{
this.a = a;
this.b = b;
}
/**
* Get the value of b
*
* @return the value of b
*/
public double getB() {
return b;
public Complex add(double c, double d)
{
return new Complex(this.a + c, this.b + d);
}
/**
* Set the value of b
*
* @param b new value of b
*/
public void setB(double b) {
this.b = b;
public Complex add(Complex obj)
{
return new Complex(this.a + obj.a, this.b + obj.b);
}
/**
* Get the value of a
*
* @return the value of a
*/
public double getA() {
return a;
public Complex subtract(double c, double d)
{
return new Complex(this.a - c, this.b - d);
}
/**
* Set the value of a
*
* @param a new value of a
*/
public void setA(double a) {
this.a = a;
public Complex subtract(Complex obj)
{
return new Complex(this.a - obj.a, this.b - obj.b);
}
public double add(Complex c2) {
double result;
result = (this.a + (this.b * this.i) + (c2.a + (this.b * this.i));
return result;
public Complex multiply(double c, double d)
{
double r = this.a * c - this.b * d;
double i = this.a * d + this.b * c;
return new Complex(r, i);
}
public Complex multiply(Complex obj) {
double r = this.a * obj.a - this.b * obj.b;
double i = this.a * obj.b + this.b * obj.a;
return new Complex(r, i);
}
public Complex divide(double c, double d)
{
return new Complex(this.a / c, this.a - d);
}
public Complex divide(Complex obj)
{
double denominator = this.a * this.a + this.b * this.b;
double r = (this.a * obj.b + this.a * obj.b) / denominator;
double i = (this.b * obj.b - this.a * obj.b) / denominator;
return new Complex(r, i);
}
@Override
public String toString()
{
return a + " + " + b + "i";
}
public Complex clone() {
Complex obj = new Complex(this.a, this.b);
return obj;
}
public double abs() {
return Math.abs(this. a + this.b);
}
public double getRealPart() {
return this.a;
}
public double getImaginaryPart() {
return this.b;
}
}