Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

Calculator Assignment

Modify a calculator program that currently displays the Abstract Syntax Tree (AST) structure after parsing an input expression. Instead of printing the AST, enhance the program to evaluate the expression and display the result. Add support for the binary "%" remainder (modulo) operator and introduce variables with the assignment operator "=".

Key steps to implement the assignment operator and variables:

  1. Introduce a new static attribute in the AstNode class to represent variables:
  2. Add a method isIdentifier() to the TokenStream class to detect variables:
  3. Modify the primaryRule() in AstNode to handle variables and variable assignment:
  4. Handle new node types in the AstNode evaluate() method for variables and assignment:

These changes allow the calculator to evaluate expressions, support variables, and handle variable assignments. Users can create and use variables in subsequent expressions.

EmployeeJava Type: 

package week3;
import static week3.MainApp.*;

public enum EmployeeType {
    FULL_TIME  (EMPLOYEE_FULL_TIME),
    PART_TIME  (EMPLOYEE_PART_TIME),
    CONSULTANT (EMPLOYEE_CONSULTANT);

    private int value;

    public int getValue() {
        return value;
    }

    private EmployeeType( int value ) {
        this.value = value;
    }
    
    @Override
    public String toString() {
        if (this.ordinal() == FULL_TIME.ordinal() ) {
            return "FT";
        } else if (this.ordinal() == PART_TIME.ordinal() ) {
            return "PT";
            
        } else {
            return "CONSULTANT";
        }
    }
}

MAINAPP.java

package week3;

public class MainApp {
    public static final int EMPLOYEE_FULL_TIME = 100;
    public static final int EMPLOYEE_PART_TIME = 200;
    public static final int EMPLOYEE_CONSULTANT = 300;

    private static void printEmployeeType(EmployeeType employeeType) {
        switch (employeeType) {
            case FULL_TIME:
                System.out.println(employeeType.getValue());
                break;
            case PART_TIME:
                System.out.println(employeeType.getValue());
                break;
            case CONSULTANT:
                System.out.println(employeeType.getValue());
                break;
        }
    }//printEmployeeType

    public static void main(String[] args) {
        EmployeeType employeeType = EmployeeType.FULL_TIME;
        printEmployeeType( employeeType );
        
        employeeType = EmployeeType.PART_TIME;
        printEmployeeType( employeeType );
        
        employeeType = EmployeeType.CONSULTANT;
        printEmployeeType( employeeType );
    }//main

}//class MainApp

Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education