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

In this project, you will develop a program that receives infix expressions, con

ID: 646777 • Letter: I

Question

In this project, you will develop a program that receives infix expressions, convert them to postfix expressions, and then evaluate the produced post expressions. Use a stack and a queue in your program implementing the algorithms discussed in class.

If you have the time and inclination, you may submit, in addition to the specified keyboard input calculator, a version that uses a graphical interface. This interface should have button for each of the numeric digits and decimal, operators, clear and quit, and a enter key to be used between adjacent floating point inputs. The GUI version of the program should have its main() method in a separate class called RPNCalcGUI. Thus, the two version are executed as two separate programs. The GUI version of the program will be worth up to an addition 50% in the grading process. You may use the java.io and java.lang class libraries (and the java.awt or javax.swing library if you are doing the extra credit GUI - you should write any such GUI code yourself, rather than using generators in some IDE). I know I did not cover this topic. It is a chance for you to demonstrate your motivation to make the deficiency on the midterm exam.

Using the following expressions to test your program:

1. 10 * (5

Explanation / Answer

Register to Electrofrinds   Member Login

    Home
    Articles
    Interview Questions
    Projects
    Question and Answer
    Source Codes
    Seminar Resources

electrofriends.com > Source Codes > Software Programs > Java > Advanced programs > Java program that converts infix expression into postfix form

Java program that converts infix expression into postfix form

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

  

import java.io.*;
class stack
{
   char stack1[]=new char[20];
   int top;
   void push(char ch)
   {
       top++;
       stack1[top]=ch;
   }
   char pop()
   {
       char ch;
       ch=stack1[top];
       top--;
       return ch;
   }
   int pre(char ch)
   {
       switch(ch)
       {
           case '-':return 1;
           case '+':return 1;
           case '*':return 2;
           case '/':return 2;
       }
       return 0;
   }
   boolean operator(char ch)
   {
       if(ch=='/'||ch=='*'||ch=='+'||ch=='-')
           return true;
       else
           return false;
   }
   boolean isAlpha(char ch)
   {
       if(ch>='a'&&ch<='z'||ch>='0'&&ch=='9')
           return true;
       else
           return false;
   }
   void postfix(String str)
   {
       char output[]=new char[str.length()];
       char ch;
       int p=0,i;
       for(i=0;i<str.length();i++)
       {
           ch=str.charAt(i);  
           if(ch=='(')
           {
               push(ch);
           }
           else if(isAlpha(ch))
           {
               output[p++]=ch;
           }
           else if(operator(ch))
           {
               if(stack1[top]==0||(pre(ch)>pre(stack1[top]))||stack1[top]=='(')
           {
               push(ch);
           }
           }
           else if(pre(ch)<=pre(stack1[top]))
           {
               output[p++]=pop();
               push(ch);
           }
           else if(ch=='(')
           {
               while((ch=pop())!='(')
               {
                   output[p++]=ch;
               }
           }
       }
       while(top!=0)
       {
           output[p++]=pop();
       }
       for(int j=0;j<str.length();j++)
       {
           System.out.print(output[j]);  
       }
   }
}
class intopost
{
   public static void main(String[] args)throws Exception
   {
       String s;
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       stack b=new stack();
       System.out.println("Enter input string");
       s=br.readLine();
       System.out.println("Input String:"+s);
       System.out.println("Output String:");
       b.postfix(s);
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote