I cannot get this program to run. It will compile no problem, but it will not run properly and allow me to input the necessary values.
I have to basically build a calculator that will allow me to input double values and calculate complex numbers. My only problem is reading the inputs, it is NOT working. The input has to follow this format: 1.1 1.1 + 1.1 1.1 * 2.2 2.2
The second number of each pair is the Bi number. Obviously the i is being left out because it isn't necessary. The objects at the bottom nested into the if-statements are all in order in the class that contains them. I just need help getting the program to read my inputs.
import java.util.Scanner;
public class Calculator
{
public static void main (String args[])
{
double Real1;
double Real2;
double Real3;
double Imag1;
double Imag2;
double Imag3;
double RResult;
double IResult;
char operator1;
char operator2;
Scanner input = new Scanner(System.in);
Complex calc = new Complex();
System.out.printf( "Geben Sie bitte 3 komplexe Zahlen und 2 Operatoren ein: " );
Real1 = input.nextDouble();
Imag1 = input.nextDouble();
String str1 = input.nextLine();
operator1 = str1.charAt(0);
//operator1 = operator1.charAt(0);
Real2 = input.nextDouble();
Imag2 = input.nextDouble();
String str2 = input.nextLine();
operator2 = str2.charAt(1);
Real3 = input.nextDouble();
Imag3 = input.nextDouble();
if (operator1 == '+' && operator2 == '*')
{
calc.complexAddMult(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '+' && operator2 == '-')
{
calc.complexAddSub(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '-' && operator2 == '+')
{
calc.complexSubAdd(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '-' && operator2 == '*')
{
calc.complexSubMult(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '*' && operator2 == '+')
{
calc.complexMultAdd(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '*' && operator2 == '-')
{
calc.complexMultSub(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
}
}
I have to basically build a calculator that will allow me to input double values and calculate complex numbers. My only problem is reading the inputs, it is NOT working. The input has to follow this format: 1.1 1.1 + 1.1 1.1 * 2.2 2.2
The second number of each pair is the Bi number. Obviously the i is being left out because it isn't necessary. The objects at the bottom nested into the if-statements are all in order in the class that contains them. I just need help getting the program to read my inputs.
import java.util.Scanner;
public class Calculator
{
public static void main (String args[])
{
double Real1;
double Real2;
double Real3;
double Imag1;
double Imag2;
double Imag3;
double RResult;
double IResult;
char operator1;
char operator2;
Scanner input = new Scanner(System.in);
Complex calc = new Complex();
System.out.printf( "Geben Sie bitte 3 komplexe Zahlen und 2 Operatoren ein: " );
Real1 = input.nextDouble();
Imag1 = input.nextDouble();
String str1 = input.nextLine();
operator1 = str1.charAt(0);
//operator1 = operator1.charAt(0);
Real2 = input.nextDouble();
Imag2 = input.nextDouble();
String str2 = input.nextLine();
operator2 = str2.charAt(1);
Real3 = input.nextDouble();
Imag3 = input.nextDouble();
if (operator1 == '+' && operator2 == '*')
{
calc.complexAddMult(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '+' && operator2 == '-')
{
calc.complexAddSub(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '-' && operator2 == '+')
{
calc.complexSubAdd(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '-' && operator2 == '*')
{
calc.complexSubMult(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '*' && operator2 == '+')
{
calc.complexMultAdd(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
if (operator1 == '*' && operator2 == '-')
{
calc.complexMultSub(Real1,Real2,Real3,Imag1,Imag2,Imag3);
calc.displayResult();
}
}
}