Advertisement
Guest User

Untitled

a guest
Apr 26th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.13 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class OprWithComplexNumbers {
  4.  
  5. private static ComplexNumber resSum;
  6. private static ComplexNumber resDifference;
  7. private static ComplexNumber resProduct;
  8.  
  9. public static void main(String[] args) {
  10.  
  11. Scanner input = new Scanner(System.in);
  12. System.out.println("--- Basic arithmetic operations with complex numbers ---");
  13.  
  14. //First Input
  15. System.out.print("Enter the first complex number in the format r i: ");
  16. //Input Scanner
  17. double real1 = input.nextDouble();
  18. double imaginary1 = input.nextDouble();
  19. ComplexNumber compNum1 = new ComplexNumber(real1,imaginary1);
  20.  
  21.  
  22. //Second Inout
  23. System.out.print("Enter the second complex number in the format r i: ");
  24. //Input Scanner
  25. double real2 = input.nextDouble();
  26. double imaginary2 = input.nextDouble();
  27. ComplexNumber compNum2 = new ComplexNumber(real2,imaginary2);
  28.  
  29. }
  30.  
  31. public static void calculateResults(){
  32. Calculator resSum = new Calculator();
  33. resSum.addTwoNumbers(compNum1, compNum2);
  34.  
  35. //call the subtraction for resDifference
  36.  
  37. //call the multiplication for resProduct
  38. }
  39.  
  40. public static void displayResults(){
  41.  
  42. //Addition
  43. System.out.println();
  44. //Subtraction
  45. System.out.println();
  46. //Multiplication
  47. System.out.println();
  48. //termination
  49. System.out.println("--- The program has terminated ---");
  50. }
  51.  
  52. public class ComplexNumber {
  53. public double real; //real part of the complex number
  54. public double imaginary; //imaginary part of the complex number
  55.  
  56. public ComplexNumber(double real, double imaginary){
  57. this.real=real;
  58. this.imaginary= imaginary;
  59. }
  60. }
  61.  
  62. public class Calculator{
  63.  
  64. private ComplexNumber compNum1;
  65. private ComplexNumber compNum2;
  66.  
  67. public Calculator(ComplexNumber compNum1,ComplexNumber compNum2){
  68. this.compNum1 = compNum1;
  69. this.compNum2 = compNum2;
  70. }
  71.  
  72. public ComplexNumber addTwoNumbers(ComplexNumber compNum1, ComplexNumber compNum2) { //Adds two complex numbers
  73. ComplexNumber result = new ComplexNumber(compNum1.real + compNum2.real, compNum1.imaginary + compNum2.imaginary);
  74. return result;
  75. }
  76. //SUBTRACTION
  77. public ComplexNumber subTwoNumbers(ComplexNumber compNum1, ComplexNumber compNum2) { //Subtracts two complex numbers
  78. ComplexNumber result = new ComplexNumber(compNum1.real - compNum2.real, compNum1.imaginary - compNum2.imaginary);
  79. return result;
  80. }
  81. //MULTIPLICATION
  82. public ComplexNumber mulTwoNumbers(ComplexNumber compNum1, ComplexNumber compNum2){ //Multiplies two complex numbers
  83. ComplexNumber result = new ComplexNumber((compNum1.real * compNum2.real) - (compNum1.imaginary * compNum2.imaginary), (compNum1.imaginary * compNum2.real) + (compNum1.real * compNum2.imaginary));
  84. return result;
  85. }
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement