Hello below I have a code and Im trying to make it so it cat

Hello, below I have a code and I\'m trying to make it so it cathches all possible exceptions. I tried to use a try catch but now I;m gettiing two errors. Before I added the try catch to the program it ran correctly. Can you tell me what those two errors mean? Also this is a Java program.

import java.util.Scanner;

/**
* Demonstrates the use of a stack to evaluate postfix expressions.
*
* @author Lewis and Chase
* @version 4.0
*/
public class PostfixTester   
{
    /**
     * Reads and evaluates multiple postfix expressions.
     */
    public static void main(String[] args)
    {
       try{
        String expression, again;
        int result;
   
        Scanner in = new Scanner(System.in);
     
        do
        {
            PostfixEvaluator evaluator = new PostfixEvaluator();
   System.out.println(\"Enter a valid post-fix expression one token \" +
          \"at a time with a space between each token (e.g. 5 4 + 3 2 1 - + *)\");
   System.out.println(\"Each token must be an integer or an operator (+,-,*,/)\");
            expression = in.nextLine();

            result = evaluator.evaluate(expression);
            System.out.println();
            System.out.println(\"That expression equals \" + result);

G File: PostfixTesterjava ming Asinmen 1 GRASP CSD Java File Edit View Build Project Settings Tools Window Help AI Files Sort By.. C: Users rigationeDrivet Revstring.class FRevstring Java Reada and eval es riitt ple poet 1x expression puolio azatio void nain Strinqr Dras) Postfix Tester Comple Messages GRASP Messages Run llo Interactions GRASI exec javac g PootfixTeater. java. Paet.fixTeater.java :24 errar: cannot find symbol Clea PostfixEvaluator evaluator new Post fixE valuator Copy symbol: clasa PoatfixEvaluator location class Post fix Tester Pos ULixTesler juvd:24 error: find symbol Postfix Evaluator evaluator new Postfix Evaluator symbol class Post fixEvaluator location: class PostfixTester Browse Find Debug Workbench Ask me anything Line:42 Col: 2 Code:0 Top 1 ovs BLK 4:21 P 2/21/2017 T13

Solution

Hi Friend, Error is not because of addition of try catch block. It is because \'PostfixEvaluator\' class is not availavle in same folder. Make sure that PostfixEvaluator class should be inported in your PostfixTester class.

import java.util.Scanner;

/**

* Demonstrates the use of a stack to evaluate postfix expressions.

*

* @author Lewis and Chase

* @version 4.0

*/

public class PostfixTester

{

   /**

   * Reads and evaluates multiple postfix expressions.

   */

   public static void main(String[] args)

   {

       try{

           String expression, again;

           int result;

           Scanner in = new Scanner(System.in);

           do

           {

               PostfixEvaluator evaluator = new PostfixEvaluator();

               System.out.println(\"Enter a valid post-fix expression one token \" +

                       \"at a time with a space between each token (e.g. 5 4 + 3 2 1 - + *)\");

               System.out.println(\"Each token must be an integer or an operator (+,-,*,/)\");

               expression = in.nextLine();

               result = evaluator.evaluate(expression);

               System.out.println();

               System.out.println(\"That expression equals \" + result);

               System.out.print(\"Evaluate another expression [Y/N]? \");

               again = in.nextLine();

               System.out.println();

           }

           while (again.equalsIgnoreCase(\"y\"));

       } catch(Exception e) {

           System.out.println(e.getMessage());

       }

   }

}

Hello, below I have a code and I\'m trying to make it so it cathches all possible exceptions. I tried to use a try catch but now I;m gettiing two errors. Before
Hello, below I have a code and I\'m trying to make it so it cathches all possible exceptions. I tried to use a try catch but now I;m gettiing two errors. Before

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site