Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Provide me all necssary Screenshort, Commentds and make all class are sep

ID: 3740288 • Letter: P

Question

Please Provide me all necssary Screenshort, Commentds and make all class are separate with highlight:(I use eclipse)

Requirements

The purpose of this project is to gain an understanding of using recursion to solve problems.

Arithmetic Expression Evaluator:

The purpose of the project is to gain an understanding of Java recursion. Therefore recursion should be used. Stacks should not be used.

That is, have the following procedures: expression, term, and factor. You call expression first. It always calls term (based on the BNF description). Upon return it checks for a + or – or end of expression string. In the case of + or – it calls expression (recursively) (based on the BNF description) and then does the addition or subtraction.

You do the same for term and factor following the BNF description.

You don’t need any stacks. Just use normal Java recursion calling : expression, term, and factor based on the BNF description.

Write a Java application or applet that asks a user to enter an arithmetic expression, and then compute and print out the result. The expression may contain parenthesis, *, /, +, - and numbers. Unary plus and minus do not need to be supported. Normal Java evaluation precedence should be used. For example:

(1 + 2) * (6 / 2 + 3) = 18

BNF (Backus-Naur Form) is commonly used in compilers to describe the language to be accepted. A BNF definition of an arithmetic expression is:

<expression> ::= <term> + <expression> |

<term> - <expression> |

<term>

<term>      ::= <factor> * <term> |

               <factor> / <term> |

     <factor>

<factor>   ::= (<expression>) |

   <float> |

   <int>

You may use the above BNF definition as a basis for your implementation. The BNF definition should show you how to call the various functions recursively if you name your functions expression, term and factor. You may use Google searches to help with this project, but you may not use any code found by these searches.

Grading Criteria:

Methods must be of appropriate length – usually less than 1 page in length

Appropriate private and public access modifiers must be used. Almost always data is private and methods are public although you may certainly have private or protected methods if appropriate.

Meets program specifications as described above

The program is robust with no runtime errors or problems

Program is readable

Comments

Use Javadocs conventions (Appendix H)

Include comments on the class as a whole including

Description of program

Your name (use @author)

Date (due or date you started or last modified)

Source of any “borrowed” code

For each method include

Concise description of what method does

Arguments for each method (use @param)

Returned value (use @returns)

Exceptions which are thrown (@throws)

Consistent and correct indenting

Meaningful identifiers

Normal capitalization conventions are used

The source of any "borrowed" code is clearly identified

Explanation / Answer

Answer: See the code below:

1. enum FactorType: FactorType.java

---------------------------------------------

package expressionevaluator;

/**
* FactorType
*
*/
public enum FactorType {
   EXPR,FLOAT,INT
}

--------------------------------------

2. Factor class: Factor.java

----------------------------------------

package expressionevaluator;

/**
* Factor class
*
*/
public class Factor {
   private String str; //contents of factor
   private boolean factorFlag; //if factor, then true
   private FactorType factorType; //type of factor
   /**
   * @param str
   * @param
   */
   Factor(String str, FactorType type) {
       this.str = str;
       this.factorFlag = true;
       this.factorType = type;
   }
   /**
   * @return the str
   */
   public String getStr() {
       return str;
   }
   /**
   * @param str the str to set
   */
   public void setStr(String str) {
       this.str = str;      
   }
   /**
   * @return the factorType
   */
   public FactorType getFactorType() {
       return factorType;
   }
   /**
   * @param factorType the factorType to set
   */
   public void setFactorType(FactorType factorType) {
       this.factorType = factorType;
   }
   /**
   * @return the factorFlag
   */
   public boolean isFactor() {
       return factorFlag;
   }  
}

----------------------------------------------

3. Term class: Term.java

----------------------------------------------

package expressionevaluator;

/**
* Term class
*
*/
public class Term {
   private String str; //contents of term
   private boolean termFlag; //true if it is term

   /**
   * @param str
   */
   public Term(String str) {
       this.str = str;
       this.termFlag = true;
   }

   /**
   * @return the str
   */
   public String getStr() {
       return str;
   }

   /**
   * @param str the str to set
   */
   public void setStr(String str) {
       this.str = str;
   }

   /**
   * @return the termFlag
   */
   public boolean isTermFlag() {
       return termFlag;
   }
}

----------------------------------------------

4. main() function: ArithmaticExpressionEvaluator.java

-----------------------------------------

/**
* AirthmaticExpressionEvaluator class
*
*/
public class AirthmaticExpressionEvaluator {
  
   /**
   * Evaluates an expression
   */
   public static void expression()
   {
      
   }
  
   /**
   * Checks if it is a term.
   */
   public static Term term(String str)
   {
       if(str.contains("*"))
       {
           String str1 = str.substring(0, str.indexOf('*'));
           String str2 = str.substring(str.indexOf('*'),str.length()-1);
           return new Term(factor(str1)+"*"+term(str2));
       }
       else if(str.contains("/"))
       {
           String str1 = str.substring(0, str.indexOf('/'));
           String str2 = str.substring(str.indexOf('/'),str.length()-1);
           return new Term(factor(str1)+"/"+term(str2));
       }
       else
           return new Term(factor(str).getStr());
   }
  
   /**
   * Checks if it is a factor
   */
   public static Factor factor(String str)  
   {
       if(str.startsWith("("))
       {
           str = str.substring(1, str.length()-1);
           return new Factor(str,FactorType.EXPR);          
       }
       else if(str.matches("\d*\.?\d*"))
       {
           return new Factor(str,FactorType.FLOAT);          
       }
       else if(str.matches("\d+"))
       {
           return new Factor(str,FactorType.INT);          
       }
       else
           return factor(str);      
   }
   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       String str = "((1 + 2) * (6 / 2 + 3))";
       Factor f = factor(str);
       if(f.isFactor())
           System.out.println("true");
       else
           System.out.println("false");
   }

}

--------------------------------------------