title: How to call and test method with the same name?
body: <p>I've been given an assignment that aims to test the validity of a calculator. They have given us a default class to go by which looks like this:</p>
  
  <pre><code>public class Calculator {
          Double x;
          /*
          * Chops up input on ' ' then decides whether to add or multiply.
          * If the string does not contain a valid format returns null.
          */
          public Double x(String x){
                  return new Double(0);
          }
  
          /*
          * Adds the parameter x to the instance variable x and returns the answer as a Double.
          */
          public Double x(Double x){
                  System.out.println("== Adding ==");
                  return new Double(0);
          }
  
          /*
          * Multiplies the parameter x by instance variable x and return the value as a Double.
          */
          public Double x(double x){
                  System.out.println("== Multiplying ==");
                  return new Double(0);
          }
  
  }
  </code></pre>
  
  <p>You are suppose to expand upon this class that aims to be a test harness. The following instructions to do so are as follows:</p>
  
  <ol>
  <li>Create a method called testParser().</li>
  <li>Tests that x("12 + 5") returns a Double with the value 17.</li>
  <li>Tests that x("12 x 5") returns a Double with the value 60.</li>
  <li>Tests that x("12 [ 3") returns null because [ is not a valid operator.</li>
  </ol>
  
  <p>Here are the current changes I have made:</p>
  
  <pre><code>public class TestCalculator {
          Double x;
          /*
          * Chops up input on ' ' then decides whether to add or multiply.
          * If the string does not contain a valid format returns null.
          */
          public Double x(String x){
                  return new Double(0);
          }
          public void testParsing() {
  
  
  
          }
          /*
          * Adds the parameter x to the instance variable x and returns the answer as a Double.
          */
          public Double x(Double x){
                  System.out.println("== Adding ==");
                  x("12 + 5");
                  return new Double(0);
          }
          /*
          * Multiplies the parameter x by instance variable x and return the value as a Double.
          */
          public Double x(double x){
                  System.out.println("== Multiplying ==");
                  x("12 x 5");
                  return new Double(0);
          }
  }
  </code></pre>
  
  <p>What I am mostly confused about is how I am able to call the actual methods as they haven't been given any unique name to call and you cannot change the name of the methods because that changes the data type. Also why are they using a String data type to add and multiply numbers? Any help on how to begin to write the testParsers() method would be very helpful. Thanks.</p>