Quang Pham's Profile User Rating: -----

Reputation: -2 Dishonored
Group:
Members
Active Posts:
37 (0.2 per day)
Joined:
18-November 12
Profile Views:
415
Last Active:
User is offline May 14 2013 10:14 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   Quang Pham has not set their status

Posts I've Made

  1. In Topic: Payroll Processing Program

    Posted 2 May 2013

    I improved on the employee processing program and came up with employee and payroll classes which worked.
    /**
     * Payfile, hirefile, and firefile.
     * 
     * @Quang Pham 
     * @4/8/13
     */
    
    public class Employee implements Comparable
    {
        
            Comparable cp;
            public String firstName;
            public String lastName;
            public String gender;
            public int tenure;
            public String rate;
            public double salary;
       
           //Constructor for objects of class Employee
           public Employee(String firstName, String lastName, String gender, int tenure, String rate, double salary)
           {
               //Initialize instance variables
               this.firstName = firstName;
               this.lastName = lastName;
               this.gender = gender;
               this.tenure = tenure;
               this.rate = rate;
               this.salary = salary;
            }
            
            public Employee(String firstName, String lastName, String gender)
            {
                this.firstName = firstName;
                this.lastName = lastName;
                this.gender = gender;
            }
            
            public String getLastName()
            {
                return lastName;
            }
            
            public int compareTo(Object o)
            {
                Employee e = (Employee) o;
                return lastName.compareTo(e.getLastName());
            }
        }
      
    /*        Payfile
    DEBBIE     STARR           F 3 W 1000.00
    JOAN       JACOBUS         F 9 W  925.00
    DAVID      RENN            M 3 H    4.75
    ALBERT     CAHANA          M 3 H   18.75
    DOUGLAS    SHEER           M 5 W  250.00
    SHARI      BUCHMAN         F 9 W  325.00
    SARA       JONES           F 1 H    7.50
    RICKY      MOFSEN          M 6 H   12.50
    JEAN       BRENNAN         F 6 H    5.40
    JAMIE      MICHAELS        F 8 W  150.00
    
            Hirefile
    BARRY      ALLEN           M 0 H    6.75
    NINA       PINELLA         F 0 W  425.00
    LANE       WAGGER          M 0 W  725.00
            
            Firefile
    JEAN       BRENNAN         F
    RICKY      MOFSEN          M
    */
    
    /**
     * Print table of employees and manipulate employee list.
     * 
     * @Quang Pham 
     * @3/12/13
     */
    import java.io.*;
    import java.util.Scanner;
    
    public class Payroll
    {
        ObjectList employeeList;
    
        public Payroll()
        {
            employeeList = new ObjectList();
        }
    
        public void getEmployees() throws IOException
        //getEmployees() adds employee to payroll.
        {
    
            Scanner readEmployees= new Scanner(new File("payfile.txt"));
            String [] employeeInfo; 
            String line;
            String firstName;
            String lastName;
            String gender;
            int tenure; 
            String rate;
            double salary;
         
    
            while(readEmployees.hasNext()){
                line= readEmployees.nextLine();
                employeeInfo= line.split("[ ]+");
                firstName= employeeInfo[0];
                lastName= employeeInfo[1];
                gender= employeeInfo[2];
                tenure= Integer.parseInt(employeeInfo[3]);
                rate= employeeInfo[4];
                salary=Double.parseDouble(employeeInfo[5]);
                employeeList.addLast(new Employee(firstName,lastName,gender,tenure,rate,salary));
            }
        }
    
       
        /*public Payroll(LineWriter lw)
        {
            this.lw = lw;
            this.firstname = new ObjectList();
            this.lastname = new ObjectList();
            this.gender = new ObjectList();
            this.tenure = new ObjectList();
            this.payrate = new ObjectList();
            this.salary = new ObjectList();
            this.output = new ObjectList();
            this.input = new ObjectListNode();
        } 
        */
    
        /*public void readfile()
        {
        int n = 0;
        File file = new File("payfile.txt");
        try{
        System.out.println ("FirstName  LastName  Gender  Tenure  Rate  Salary");
        Scanner scanner = new Scanner(file);//file
        while(scanner.hasNextLine())
        {
        String line = scanner.nextLine();
        Scanner lineScanner = new Scanner(line);
        lineScanner.useDelimiter("\\s+");
    
        while(lineScanner.hasNext())
        {
    
        firstname.insert(lineScanner.next());
        lastname.insert(lineScanner.next());
        gender.insert(lineScanner.next());
        tenure.insert(lineScanner.next());
        payrate.insert(lineScanner.next());
        salary.insert(lineScanner.next());
        }
        //Print employee payroll
        /*System.out.println ("firstname: " + firstname);
        System.out.println ("lastname:  " + lastname);
        System.out.println ("gender:  " + gender);
        System.out.println ("tenure:  " + tenure);
        System.out.println ("payrate:  " + payrate);
        System.out.println ("salary:  " + salary);
        System.out.println ("  ");
    
        System.out.println ("line" + n + ":  " + line);
        n = n + 1;
        }
    
        System.out.println ("  ");
        System.out.println ("There are " + n + " employees in the company.");
        System.out.println ("  ");
        }
        catch(FileNotFoundException e)
        { e.printStackTrace();} 
        }
    
        /*public void insert()
        {
        // File file = new File("payfile.txt");
        /*
        try{
        Scanner scanner = new Scanner(file);
    
        while(scanner.hasNextLine())
        {
        String line = scanner.nextLine();
        Scanner lineScanner = new Scanner(line);
        lineScanner.useDelimiter("\\s+");
        while(lineScanner.hasNext())
        {
    
        //emp.firstname = linescanner.next();
    
        firstname.insert(lineScanner.next());
        lastname.insert(lineScanner.next());
        gender.insert(lineScanner.next());
        tenure.insert(lineScanner.next());
        payrate.insert(lineScanner.next());
        salary.insert(lineScanner.next());
    
        //Print employee payroll
        /*System.out.println ("firstname: " + firstname);
        System.out.println ("lastname:  " + lastname);
        System.out.println ("gender:  " + gender);
        System.out.println ("tenure:  " + tenure);
        System.out.println ("payrate:  " + payrate);
        System.out.println ("salary:  " + salary);
    
        System.out.println ("line:  " + line);
    
        }
    
        //ol.insertAfter();
    
        }        
        } catch(FileNotFoundException e)
        { e.printStackTrace();}
         */
    
        /*public void printer(LineWriter lw)
        {
        String msg = " FirstName " + " LastName " + " Gender " + " Tenure " +
        " PayRate " + " Salary "; 
        output.insert(msg);
        //System.out.println(msg);
        //ObjectListNode p = list;
    
        while (oln != null);
        {
        System.out.println(output.getFirst());
        System.out.println("  " + firstname.getFirst() + "     " + lastname.getFirst() + "\t" + gender.getFirst() +
        "\t" + tenure.getFirst() + "\t" + payrate.getFirst() + "\t" + salary.getFirst());
        //System.out.println(output.getSecond());
        //System.out.println(" " + firstname.getSecond() + "     " + lastname.getSecond() + "\t" + gender.getSecond() +
        //    "\t" + tenure.getSecond() + "\t" + payrate.getSecond() + "\t" + salary.getSecond());
    
        // System.out.println(output.getLast());
        System.out.println("  " + firstname.getLast() + "     " + lastname.getLast() + "\t" + gender.getLast() +
        "\t" + tenure.getLast() + "\t" + payrate.getLast() + "\t" + salary.getLast());
    
        // oln.getNext();
        // oln.getInfo();
    
        //traverse linked list and print next employee entries.
        // ol.traverse(); 
        //{
        p = list;
        while (p != null) 
        {
        System.out.println(p.getInfo());
        p = p.getNext();
    
        System.out.println("  " + firstname.getFirst() + "     " + lastname.getFirst() + "\t" + gender.getFirst() +
        "\t" + tenure.getFirst() + "\t" + payrate.getFirst() + "\t" + salary.getFirst());
    
        System.out.println(" " + firstname.getLast() + "    " + lastname.getLast() + "\t" + gender.getLast() +
        "\t" + tenure.getLast() + "\t" + payrate.getLast() + "\t" + salary.getLast());
    
        }  
    
                        
        /**
         * employeeTable()-traverse employeeList and outputs each node into a table format
         */
        public void employeeTable()
        {
            Employee node;    
            ObjectListNode p = employeeList.getFirstNode();
            //print header
            System.out.println("Name                 Gender          Tenure            Rate             Salary");
            //print each employee
            while (p != null) {
                node=(Employee)p.getInfo();
                System.out.printf("%s %s\t\t%s\t\t%d\t\t%s\t\t%.2f\n",node.firstName,node.lastName,node.gender,node.tenure,node.rate,node.salary);
                p = p.getNext();
            }
            System.out.println();//for a space in output
        }
    
        /**
         * numEmployees()-traverse list and returns number of employees(using count method in object list)
         */
        public void numEmployees(){
            System.out.println("Number of Employees in Company: "+ employeeList.size()+ "\n");
        }
    
        /**
         * women()-output first names of women on the payroll. 
         */
        public void women(){
            Employee employee;    
            ObjectListNode p = employeeList.getFirstNode();
            String gender;
    
            System.out.println("Women on payroll:");
            while (p != null) {
                employee=(Employee)p.getInfo();
                gender=employee.gender;
                if(gender.equals("F")){
                    System.out.println(employee.firstName);
                }
                p = p.getNext();
            }
            System.out.println();
        }
    
        /**
         * experienced()-output weekly employees who make more than $35,000 and is with the company for at least
         * 5 years. 
         */
        public void experienced(){
            final int WEEKS_IN_YEAR=52;
            Employee employee;    
            ObjectListNode p = employeeList.getFirstNode();
            double yearlySal; //how much money that employee makes a year
    
            while (p != null) {
                employee=(Employee)p.getInfo(); 
                if((employee.rate).equals("W")){
                    yearlySal=(employee.salary)*WEEKS_IN_YEAR;
                    if(yearlySal>35000 && employee.tenure >= 5 )
                    {
                        System.out.println("Weekly employees who make more than $35,000 and with the company for 5 years.");
                        System.out.println(employee.firstName+" "+employee.lastName);
                    }
                }
                p = p.getNext();
            }
            System.out.println(); 
        }
    
        /**
         * method raise()- give raises to some employees and print out their names and new salaries
         */
        public void raise(){
            Employee employee;    
            ObjectListNode p = employeeList.getFirstNode();
            String rate;
            double oldSalary;
            //headings
            System.out.println("Employees who recieved a raise");
            System.out.println("Name\t\t\tNew Salary");
    
            while (p != null) {
                employee=(Employee)p.getInfo();
                rate=employee.rate;
                oldSalary=employee.salary;//salary at the start
                if(rate.equals("H")){
                    if(oldSalary< 10.00){
                        employee.salary+= .75;
                    }
                }
                else {//if rate is weekly
                    if(oldSalary<350.00){
                        employee.salary+= 50.00;
    
                    }
                }
                if(oldSalary<employee.salary)//if recieved a raise
                    System.out.printf("%s %s\t\t%.2f\n",employee.firstName,employee.lastName,employee.salary);
                p = p.getNext();
            }
            System.out.println(); //add space in output
        }
    
        /**
         * method alphaOrder()- puts list in order by last name
         * 
         */
        public void alphaOrder(){
            ObjectList newList= new ObjectList();//the ordered list
            Object object;
            ObjectListNode p= new ObjectListNode();
            Employee employee;
            while (employeeList.getFirstNode()!= null) 
            {
                object=employeeList.removeFirst();
                newList.insert(object);
            }
            employeeList=newList;
            p=employeeList.getFirstNode();
            System.out.println("Employees in alphabetical order by last name and their salaries.");
            //print the employees
            while(p!= null)
            {
                
                employee=(Employee)p.getInfo();
                System.out.printf("%s %s\t%.2f\n",employee.firstName,employee.lastName,employee.salary);
                p = p.getNext();
            }
            System.out.println();      
        }
    
        /**
         * method hireEmployees- reads hirefile and inserts them into the linked list
         */
        public void hireEmployees() throws IOException{
            Scanner newEmployees= new Scanner(new File("hirefile.txt"));//read new employees
            ObjectListNode p;
            Employee employee;
            String [] employeeInfo;
            String line;
            String firstName;
            String lastName;
            String gender;
            int tenure; 
            String rate;
            double salary;
    
            while(newEmployees.hasNext()){
                line=newEmployees.nextLine();
                employeeInfo= line.split("[ ]+");
                firstName= employeeInfo[0];
                lastName= employeeInfo[1];
                gender= employeeInfo[2];
                tenure= Integer.parseInt(employeeInfo[3]);
                rate= employeeInfo[4];
                salary=Double.parseDouble(employeeInfo[5]);
                employeeList.insert((Object)new Employee(firstName,lastName,gender,tenure,rate,salary));
            }
    
            p= employeeList.getFirstNode();
            System.out.println("List afer certain employees were hired.");
            while(p!= null){
                employee=(Employee) p.getInfo();
                System.out.println(employee.firstName+" "+employee.lastName);
                p = p.getNext();
            }
            System.out.println();
        }
    
        /**
         * method fireEmployees()- reads firefile and fires employees by removing from linked list
         */
        public void fireEmployees() throws IOException{
            Scanner toFire= new Scanner(new File("firefile.txt"));//read new employees
            String [] employeeInfo;
            ObjectListNode p;
            Employee employee;
            String line;
            String firstName;
            String lastName;
            String gender;
            int tenure; 
            String rate;
            double salary;
            System.out.println("List after certain employees were fired.");
            while(toFire.hasNext()){
                line=toFire.nextLine();
                employeeInfo= line.split("[ ]+");
                firstName= employeeInfo[0];
                lastName= employeeInfo[1];
                gender= employeeInfo[2];
                employeeList.remove((Object)new Employee(firstName,lastName,gender));
            }
    
            p=employeeList.getFirstNode();
            while(p!=null){
                employee=(Employee)p.getInfo();
                System.out.println(employee.firstName+" "+employee.lastName);
                p = p.getNext();
            }
            System.out.println();
    
        }
    }
    
    //public void femalesInCompany();
    //while ol.gender == 'F';
    
    //System.out.println(firstname);
    //p = p.getNext();
    
    //sort list(); //sort nodes according to last name();
    //print salaries of employees
    /*insert (hirefile.txt)(); //insert hirefile into linked list
    {
    
    }
    // while (oln != null)
    return newfile1;
     */
    
    /*delete (firefile.txt)(); //delete firefile from linked list
    {
    
    }
    // while (oln != null)
    return newfile2;
     */
    
    // a.)  Read data from payfile.txt into ObjectList and ObjectListNode.
    
    // b.)  Traverse the list and output info field of each ObjectListNode into table format.
    
    // c.)  Traverse the list and output the number of employees in company.
    
    // d.)  Traverse the list and output the first name of all women employees.
    
    // e.)  The first name, last name, and salary of weekly employees who make more than $35,000 per year and who have been 
    // with the company for at least five years.
    
    // f.)  Give a raise of $.75 per hour to employees who are paid on an hourly basis and make less than $10.00 per hour.
    
    // g.)  Give a raise of $50.00 per week to employees who are paid on a weekly basis and make less than $350.00 per week.
    
    // h.)  Output first name, last name, and new salaries for employees who got a raise.
    
    // i.)  Sort the nodes of linked list into alphabetical order according to last name and print first and last names and
    
    // j.)  Print the salaries for each employee on the payroll.
    
    // k.)  Insert the hirefile.txt employees into payroll and print first and last names of each employee.
    
    // l.)  Delete the firefile.txt emplyees from payroll and print first and last names of each employee.
    
    
    
  2. In Topic: Infix to Postfix Translation

    Posted 5 Mar 2013

    View Postburakaltr, on 05 March 2013 - 02:03 PM, said:

    Yes Sir , but you have given -1 on that to me :(/>((

    I couldn't open the code before.
  3. In Topic: Infix to Postfix Translation

    Posted 5 Mar 2013

    View Postburakaltr, on 05 March 2013 - 02:03 PM, said:

    Yes Sir , but you have given -1 on that to me :(/>((

    I couldn't open the code before.
  4. In Topic: Infix to Postfix Translation

    Posted 5 Mar 2013

    This is my improved InfixToPostfix Program.
    /**
     * Driver to start execution of program.
     * 
     * @Quang Pham 
     * @2/21/13
     */
    import java.io.*;
    
    import java.util.Scanner;
    
    public class Driver
    {
        LineWriter lw;
        public Driver (LineWriter lw)
        {
            lw = new LineWriter("csis.txt");   
        }
        String infix = "";
        Scanner keyboard = new Scanner(System.in);
    
        public static void main(String[] args)throws IOException
        {
            LineWriter lw = new LineWriter("csis.txt");
            InfixToPostfix inf = new InfixToPostfix();
            //ObjectStack obj = new ObjectStack();
            EvalPostfix evl = new EvalPostfix();
            Output out = new Output();
            System.out.println ("These are the infix statements.");
            //infix = keyboard.nextString();
    
            Scanner fileScan = new Scanner(new File("infix.txt"));
            while (fileScan.hasNext())
            {
                String buf = fileScan.nextLine();
                System.out.println(buf);
            }
            
            System.out.println ("These are the postfix equations.");
            
            
            System.out.println ("These are the postfix equations evaluated.");
            
            
            lw.close();
        }
    }
    /**
     * Translate infix to postfix.
     * 
     * @Quang Pham 
     * @2/21/13
     */
    
    import java.util.*;
    public class InfixToPostfix
    {
        //stack class also containing the intopostfix method
      
        //InfixToPostfix inf = new InfixToPostfix(); 
        ObjectStack obj = new ObjectStack();
        //EvalPostfix evl = new EvalPostfix();
        
        int i,j;
        char postfix[];
        
            boolean isOperand(char ch)
            {
                if((ch>='a'&&ch<='z')||(ch>=0&&ch<='9'))
                    return true;
                else 
                    return false;
    
            }
    
            boolean isOperator(char ch)
            {
                if(ch=='+'||ch=='-'||ch=='*'||ch=='/')
                    return true;
                else 
                    return false;
    
            }
    
            void IntoPost(String str)
            {
                postfix = new char[str.length()];
                char ch;
    
                j=0;
    
                for(i=0;i<str.length();i++)
                {
                    ch = str.charAt(i);
                    if(ch=='(')
                        obj.push (ch);
                    else if(isOperand(ch))
                    {
                        postfix[j++]=ch;
                    }
                    else if(isOperator(ch))
                    {
                        obj.push (ch);
                    }
                    else if(ch==')')
                    {
                        //ch = obj.pop();
                        while (ch!= '(')
                        {
                            postfix[j++] = ch;
                            //ch = obj.pop();
                        }
                    }
                    //System.out.println (postfix[]);
                }
    
            }
    
            void disp()
            {
                for(i=0;i<postfix.length;i++)
                {   
                    System.out.print(postfix[i]);
                }
            }
        }
    /**
     * Evaluate postfix equation.
     * 
     * @Quang Pham
     * @2/21/13
     */
    public class EvalPostfix
    {
        //InfixToPostfix inf = new InfixToPostfix();
        ObjectStack obj = new ObjectStack();
        //EvalPostfix evl = new EvalPostfix();
        
        String str = "";
        char postfix[];
        int top;
    
        public int EvalPostfix(String Object[]) 
        {
            String Operand = "";
            String Operator = "";
            String ObjectStack = "";
            int number1 = 0;
            int number2 = 0;
            int result = 0;
            char ch;
            char postfix[];
            String str = "";
            postfix = new char[str.length()];
    
            for (int j = 0; j < str.length(); j++) 
            {
                ch = str.charAt(j);
                if (ch == (Integer)(number1)) 
                {
                    obj.push(ch);
                } 
                else 
                {
    
                    //number1 = obj.pop(); 
                    //number2 = obj.pop();
                    switch (ch) 
                    {
                        case '+':
                        result = number1 + number2;
                        break;
                        case '-':
                        result = number1 - number2;
                        break;
                        case '*':
                        result = number1 * number2;
                        break;
                        case '/':
                        result = number1 / number2;
                        break;
                        case '%':
                        result = number1 % number2;
                        break;
                    }
                }
            }
    
            return result;
        }
    
        public static void main(String[] args) 
        {
            ObjectStack obj = new ObjectStack(100);
            String y = new String("(z * j)/(b * 8) ^2");
            String x = new String("10 3 + 9 *");
            //TestingClass clas = new TestingClass(st);
    
            //clas.test(y);
            //System.out.println(ObjectStack.test(y));
    
            //clas.EvalPostfix(x);
        }
    
        public boolean isStackEmpty()
        {
            if (top == 0)
            {
                System.out.println("Stack is empty " + "Equation Good");
                return true;
            } else
                System.out.println("Equation is No good");
            return false;
        }
    
        public void reset()
        {
            top = -1;
        }
    
        public void showStack() 
        {
            System.out.println(" ");
            System.out.println("Stack Contents...");
            for (int j = top; j > -1; j--)
            {
                System.out.println(postfix[j]);
            }
            System.out.println(" ");
        }
    
        public void showStack0toTop()
        {
            System.out.println(" ");
            System.out.println("Stack Contents...");
            for (int j = 0; j >= top; j++) 
            {
                System.out.println(postfix[j]);
            }
            System.out.println(" ");
        }
    
    }
    /**
     * Object stack of equations.
     * 
     * @Quang Pham 
     * @12/21/13
     */
    public class ObjectStack
    {
        String ObjectStack;
        
        String ObjectStackInterface;
    
        private Object[] item;
        private int top;
        private int size;
    
        public ObjectStack()
        {
            size = 100;
            item = new Object[size];
            top = -1;
        }
    
        public ObjectStack(int max)
        {
            size = max;
            item = new Object[size];
            top = -1;
        }
    
        public boolean isEmpty()
        {
            return top == -1;
        }
    
        public boolean isFull()
        {
            return top == size-1;
        }
    
        public void clear()
        {
            top = -1;
        }
    
        public void push(Object x)
        {
            if (isFull()) 
            {
                System.out.println("Push Runtime Error: Stack Overflow");
                System.exit(1);
            }
            item[++top] = x;
        }
    
        public Object pop()
        {
            if (isEmpty())
            {
                System.out.println("Pop Runtime Error: Stack Underflow");
                System.exit(1);
            }
            return item[top--];
        }
    
        public Object top() 
        {
            if (isEmpty())
            {
                System.out.println("Top Runtime Error: Stack Underflow");
                System.exit(1);
            }
            return item[top];
        }
    
    }
    
    


    Do you know how to make it compile better and run better?
  5. In Topic: Infix to Postfix Translation

    Posted 5 Mar 2013

    This is my improved InfixToPostfix Program.
    /**
     * Driver to start execution of program.
     * 
     * @Quang Pham 
     * @2/21/13
     */
    import java.io.*;
    
    import java.util.Scanner;
    
    public class Driver
    {
        LineWriter lw;
        public Driver (LineWriter lw)
        {
            lw = new LineWriter("csis.txt");   
        }
        String infix = "";
        Scanner keyboard = new Scanner(System.in);
    
        public static void main(String[] args)throws IOException
        {
            LineWriter lw = new LineWriter("csis.txt");
            InfixToPostfix inf = new InfixToPostfix();
            //ObjectStack obj = new ObjectStack();
            EvalPostfix evl = new EvalPostfix();
            Output out = new Output();
            System.out.println ("These are the infix statements.");
            //infix = keyboard.nextString();
    
            Scanner fileScan = new Scanner(new File("infix.txt"));
            while (fileScan.hasNext())
            {
                String buf = fileScan.nextLine();
                System.out.println(buf);
            }
            
            System.out.println ("These are the postfix equations.");
            
            
            System.out.println ("These are the postfix equations evaluated.");
            
            
            lw.close();
        }
    }
    /**
     * Translate infix to postfix.
     * 
     * @Quang Pham 
     * @2/21/13
     */
    
    import java.util.*;
    public class InfixToPostfix
    {
        //stack class also containing the intopostfix method
      
        //InfixToPostfix inf = new InfixToPostfix(); 
        ObjectStack obj = new ObjectStack();
        //EvalPostfix evl = new EvalPostfix();
        
        int i,j;
        char postfix[];
        
            boolean isOperand(char ch)
            {
                if((ch>='a'&&ch<='z')||(ch>=0&&ch<='9'))
                    return true;
                else 
                    return false;
    
            }
    
            boolean isOperator(char ch)
            {
                if(ch=='+'||ch=='-'||ch=='*'||ch=='/')
                    return true;
                else 
                    return false;
    
            }
    
            void IntoPost(String str)
            {
                postfix = new char[str.length()];
                char ch;
    
                j=0;
    
                for(i=0;i<str.length();i++)
                {
                    ch = str.charAt(i);
                    if(ch=='(')
                        obj.push (ch);
                    else if(isOperand(ch))
                    {
                        postfix[j++]=ch;
                    }
                    else if(isOperator(ch))
                    {
                        obj.push (ch);
                    }
                    else if(ch==')')
                    {
                        //ch = obj.pop();
                        while (ch!= '(')
                        {
                            postfix[j++] = ch;
                            //ch = obj.pop();
                        }
                    }
                    //System.out.println (postfix[]);
                }
    
            }
    
            void disp()
            {
                for(i=0;i<postfix.length;i++)
                {   
                    System.out.print(postfix[i]);
                }
            }
        }
    /**
     * Evaluate postfix equation.
     * 
     * @Quang Pham
     * @2/21/13
     */
    public class EvalPostfix
    {
        //InfixToPostfix inf = new InfixToPostfix();
        ObjectStack obj = new ObjectStack();
        //EvalPostfix evl = new EvalPostfix();
        
        String str = "";
        char postfix[];
        int top;
    
        public int EvalPostfix(String Object[]) 
        {
            String Operand = "";
            String Operator = "";
            String ObjectStack = "";
            int number1 = 0;
            int number2 = 0;
            int result = 0;
            char ch;
            char postfix[];
            String str = "";
            postfix = new char[str.length()];
    
            for (int j = 0; j < str.length(); j++) 
            {
                ch = str.charAt(j);
                if (ch == (Integer)(number1)) 
                {
                    obj.push(ch);
                } 
                else 
                {
    
                    //number1 = obj.pop(); 
                    //number2 = obj.pop();
                    switch (ch) 
                    {
                        case '+':
                        result = number1 + number2;
                        break;
                        case '-':
                        result = number1 - number2;
                        break;
                        case '*':
                        result = number1 * number2;
                        break;
                        case '/':
                        result = number1 / number2;
                        break;
                        case '%':
                        result = number1 % number2;
                        break;
                    }
                }
            }
    
            return result;
        }
    
        public static void main(String[] args) 
        {
            ObjectStack obj = new ObjectStack(100);
            String y = new String("(z * j)/(b * 8) ^2");
            String x = new String("10 3 + 9 *");
            //TestingClass clas = new TestingClass(st);
    
            //clas.test(y);
            //System.out.println(ObjectStack.test(y));
    
            //clas.EvalPostfix(x);
        }
    
        public boolean isStackEmpty()
        {
            if (top == 0)
            {
                System.out.println("Stack is empty " + "Equation Good");
                return true;
            } else
                System.out.println("Equation is No good");
            return false;
        }
    
        public void reset()
        {
            top = -1;
        }
    
        public void showStack() 
        {
            System.out.println(" ");
            System.out.println("Stack Contents...");
            for (int j = top; j > -1; j--)
            {
                System.out.println(postfix[j]);
            }
            System.out.println(" ");
        }
    
        public void showStack0toTop()
        {
            System.out.println(" ");
            System.out.println("Stack Contents...");
            for (int j = 0; j >= top; j++) 
            {
                System.out.println(postfix[j]);
            }
            System.out.println(" ");
        }
    
    }
    /**
     * Object stack of equations.
     * 
     * @Quang Pham 
     * @12/21/13
     */
    public class ObjectStack
    {
        String ObjectStack;
        
        String ObjectStackInterface;
    
        private Object[] item;
        private int top;
        private int size;
    
        public ObjectStack()
        {
            size = 100;
            item = new Object[size];
            top = -1;
        }
    
        public ObjectStack(int max)
        {
            size = max;
            item = new Object[size];
            top = -1;
        }
    
        public boolean isEmpty()
        {
            return top == -1;
        }
    
        public boolean isFull()
        {
            return top == size-1;
        }
    
        public void clear()
        {
            top = -1;
        }
    
        public void push(Object x)
        {
            if (isFull()) 
            {
                System.out.println("Push Runtime Error: Stack Overflow");
                System.exit(1);
            }
            item[++top] = x;
        }
    
        public Object pop()
        {
            if (isEmpty())
            {
                System.out.println("Pop Runtime Error: Stack Underflow");
                System.exit(1);
            }
            return item[top--];
        }
    
        public Object top() 
        {
            if (isEmpty())
            {
                System.out.println("Top Runtime Error: Stack Underflow");
                System.exit(1);
            }
            return item[top];
        }
    
    }
    
    


    Do you know how to make it compile better and run better?

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Click here to e-mail me

Friends

Comments

Quang Pham has no profile comments yet. Why not say hello?