Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

Write a Java program to read and simulate the execution of a program written in a highly simplified programming language. Each line in the input contains one statement. There are no declaration...

1 answer below »
Write a Java program to read and simulate the execution of a program written in a highly simplified programming language. Each line in the input contains one statement. There are no declaration statements; all values are of type double. Statements in the language are in the following forms: Simple Statements Meaning variable = expression The expression consists of variables, constants, and the simple arithmetic operators (+, -, *, /) with blanks as delimiters. It is evaluated left to right and the result is placed in the variable. Note that there is no hierarchy among the operators and parentheses are not allowed. PRINT variable The value of the variable should be displayed with two digits to the right of the decimal point. GOTO n Execution moves to the nth line of the program. The first line in the program is line 1. Conditional Statement Meaning IF variable IS value THEN simpleStatement If the variable is equal to value (a variable or a constant), the simpleStatement is performed. End of Program Marker Meaning END This is the last statement in a program. There are no statements following this. When execution reaches this statement, the program is terminated. The GUI will include a “Next Program” button which allows the user to select a file containing a program to be executed. The program in the selected file is then executed and the output (result of the PRINT statements) should be displayed in a scrollable text area. NOTE Use of an array is NOT acceptable in this assignment. As in Lab 1, you will be given code for the GUI. Also, error checking is required












code is:






import javax.swing.*;

import java.awt.event.*;

import java.io.*;

import java.util.*;





public class Lab2 extends JFrame implements ActionListener {



JButton open = new JButton("Next Program");



JTextArea result = new JTextArea(20,40);



JLabel errors = new JLabel();



JScrollPane scroller = new JScrollPane();







public Lab2() {



setLayout(new java.awt.FlowLayout());



setSize(500,430);



setDefaultCloseOperation(DISPOSE_ON_CLOSE);



add(open); open.addActionListener(this);



scroller.getViewport().add(result);



add(scroller);



add(errors);



}







public void actionPerformed(ActionEvent evt) {



result.setText("");
//clear TextArea for next program



errors.setText("");



processProgram();



}







public static void main(String[] args) {



Lab2 display = new Lab2();



display.setVisible(true);



}







String getFileName() {



JFileChooser fc = new JFileChooser();



int returnVal = fc.showOpenDialog(this);



if (returnVal == JFileChooser.APPROVE_OPTION)



return fc.getSelectedFile().getPath();



else



return null;



}





/************************************************************************/

/* Put your implementation of the processProgram method here. */

/* Use the getFileName method to allow the user to select a program. */

/* Then simulate the execution of that program. */

/* You may add any other methods that you think are appropriate. */

/* However, you should not change anything in the code that I have */

/* written. */

/************************************************************************/





}

Answered Same Day Mar 24, 2023

Solution

Shweta answered on Mar 24 2023
22 Votes
a = 2+4.0
= a+3
PRINT
a =a+1
c = a+6.0
PRINT c
if a IS 9 THEN GOTO 4
PRINT
END
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here