title: Variables incorrect; fraction calculator; JAVA
body: <p>I have my code here which i have posted on here before and have been helped before.  The variables seem to be incorrect and i am unsure why. I entered the fraction 1/2 + 3/4 and am getting the answer 8/4. i know it has to do with the variables because when i run the debugger it says that "a" = 1, 'b'= 1, 'c'=4, and 'd'=4.  'a' and 'd' are correct in the way i want them, going from 'a' through 'd' from left to right. i think i know where the problem is but i dont know how to fix it.  I think the problem with 'b' has to do with this line of code </p>
  
  <pre><code>b = Integer.parseInt("1");
  </code></pre>
  
  <p>Here is my full code </p>
  
  <p>import java.util.*;</p>
  
  <pre><code>public class Calculator {
  public static void main(String[] args) {
  System.out.println("Please enter two fractions to add, subtract, multiply, or divide\nor\nType             'quit' to exit the program.");
  Boolean on = true;
  Scanner console = new Scanner(System.in);
  while (on) {
      String input = console.nextLine();
      if (input.equalsIgnoreCase("quit")) {
          on = false;
      } else
          System.out.println(run(input));
  }
  }
  public static String run(String input) {
  int indexOfSecondSpace = 0;
  int indexOfOperation = 0;
  String firstNumber = "0";
  String secondNumber = "0";
  int beginning = input.indexOf(" ") + 1;
  int end = input.indexOf(" ", beginning);
  String operator = input.substring(beginning, end);
  if (input.contains("+") == true) {
  indexOfOperation = input.indexOf("+");
  } else if (operator.equals("-")) {
  indexOfOperation = input.indexOf("-");
  } else if (operator.equals("*")) {
  indexOfOperation = input.indexOf("*");
  } else if (operator.equals("/")) {
  indexOfOperation = input.indexOf("/");
  }
  firstNumber = (input.substring(0, input.indexOf(" ")));
  secondNumber = (input.substring(beginning + 1));
  int a = 0;
  int b = 0;
  int c = 0;
  int d = 0;  
  if (firstNumber.contains("/")) {
  a = Integer.parseInt(firstNumber.substring(0,firstNumber.indexOf("/")));
  b = Integer.parseInt(firstNumber.substring(0,firstNumber.indexOf("/")));
  } else if (!firstNumber.contains("/"))
  a = Integer.parseInt(input.substring(0, input.indexOf(" ")));
  b = Integer.parseInt("1");
  {
      if (secondNumber.contains("/")) {
      c = Integer.parseInt(secondNumber.substring(secondNumber.indexOf("/")+1));
      d = Integer.parseInt(secondNumber.substring(secondNumber.indexOf("/")+1));
      } else if (!secondNumber.contains("/")) {
      c = Integer.parseInt(secondNumber.substring(secondNumber.length()));
      d = Integer.parseInt("1");
      }
  }
  String res = calculate(input, a, b, c, d) ;
  return res;
  }
  public static String calculate(String input, int a, int b, int c, int d){
  if (input.contains ("+"))
  {
      System.out.println("your answer is " + (a*d + b*c)+"/" +(b*d));
  }
  else if  (input.contains("-"))
  {
      System.out.println("your answer is " + (a*d - b*c)+ "/" +(b*d));
  }
  else if (input.contains("/"))
  {
      System.out.println("your answer is " + (a*d)/(b*c)+ "/" +(b*d));
  }
  else if (input.contains("*"))
  {
      System.out.println("your answer is " + (a*c) +"/" +(b*d));
  }
  return input;
  }
  }
  </code></pre>