begin mp3
This commit is contained in:
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
|
||||
*/
|
||||
package mp3_calebfontenot;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class MP3_CalebFontenot {
|
||||
|
||||
/**
|
||||
* @param args the command line arguments
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.print("Enter the first complex number: ");
|
||||
double a = input.nextDouble();
|
||||
double b = input.nextDouble();
|
||||
Complex c1 = new Complex(a, b);
|
||||
System.out.print("Enter the second complex number: ");
|
||||
double c = input.nextDouble();
|
||||
double d = input.nextDouble();
|
||||
Complex c2 = new Complex(c, d);
|
||||
System.out.println("(" + c1 + ")" + " + " + "(" + c2 + ")" + " = "
|
||||
+ c1.add(c2));
|
||||
System.out.println("(" + c1 + ")" + " - " + "(" + c2 + ")" + " = "
|
||||
+ c1.subtract(c2));
|
||||
System.out.println("(" + c1 + ")" + " * " + "(" + c2 + ")" + " = "
|
||||
+ c1.multiply(c2));
|
||||
System.out.println("(" + c1 + ")" + " / " + "(" + c2 + ")" + " = "
|
||||
+ c1.divide(c2));
|
||||
System.out.println("|" + c1 + "| = " + c1.abs());
|
||||
Complex c3 = (Complex) c1.clone();
|
||||
System.out.println(c1 == c3);
|
||||
System.out.println(c3.getRealPart());
|
||||
System.out.println(c3.getImaginaryPart());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
class Complex {
|
||||
|
||||
private double a;
|
||||
private double b;
|
||||
private final double i = Math.sqrt(-1);
|
||||
public Complex() {
|
||||
this.a = 0;
|
||||
}
|
||||
|
||||
public Complex(double a) {
|
||||
this.a = a;
|
||||
this.b = 0;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of b
|
||||
*
|
||||
* @param b new value of b
|
||||
*/
|
||||
public void setB(double b) {
|
||||
this.b = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a
|
||||
*
|
||||
* @return the value of a
|
||||
*/
|
||||
public double getA() {
|
||||
return a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of a
|
||||
*
|
||||
* @param a new value of a
|
||||
*/
|
||||
public void setA(double a) {
|
||||
this.a = a;
|
||||
}
|
||||
|
||||
public double add(Complex c2) {
|
||||
double result;
|
||||
result = (this.a + (this.b * this.i) + (c2.a + (this.b * this.i));
|
||||
return result;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user