Question

Java Code: I am using the code below but it will not compile. PROGRAM: using System;...

Java Code: I am using the code below but it will not compile.

PROGRAM:

using System;
//import java.util.Scanner;
//Create the class that would perform the simulation.
public class Simulator
{
   public static void main(String[] args)
   {
       //list of SML instructions
       const int READ_INS = 10;
       const int WRITE_INS = 11;
       const int LOAD_INS = 20;
       const int STORE_INS = 21;
       const int ADD_INS = 30;
       const int SUBTRACT_INS = 31;
       const int MULTIPLY_INS = 32;
       const int DIVIDE_INS = 33;
       const int BRANCH_INS = 40;
       const int BRANCH_NEG_INS = 41;
       const int BRANCH_ZERO_INS = 42;
       const int HALT_INS = 43;
  
   //variabes for storing the instruction and its details.
   int accumulator;
   int instructionCounter;
int op_oprnd;
   int op_Code;
   int instructionRegister;
  
       //simpletron memArray
   int[] memArray;
  
   //number of instructions entered in memArray
   int index = 0;

      /* Method to run the simpletron simulator*/
   }


  

ERROR MESSAGE:

Simulator.java:1: error: class, interface, or enum expected
using System;
^
Simulator.java:9: error: illegal start of expression
const int READ_INS = 10;
^
Simulator.java:10: error: illegal start of expression
const int WRITE_INS = 11;
^
Simulator.java:11: error: illegal start of expression
const int LOAD_INS = 20;
^
Simulator.java:12: error: illegal start of expression
const int STORE_INS = 21;
^
Simulator.java:13: error: illegal start of expression
const int ADD_INS = 30;
^
Simulator.java:14: error: illegal start of expression
const int SUBTRACT_INS = 31;
^
Simulator.java:15: error: illegal start of expression
const int MULTIPLY_INS = 32;
^
Simulator.java:16: error: illegal start of expression
const int DIVIDE_INS = 33;
^
Simulator.java:17: error: illegal start of expression
const int BRANCH_INS = 40;
^
Simulator.java:18: error: illegal start of expression
const int BRANCH_NEG_INS = 41;
^
Simulator.java:19: error: illegal start of expression
const int BRANCH_ZERO_INS = 42;
^
Simulator.java:20: error: illegal start of expression
const int HALT_INS = 43;
^
  

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Error details:In java const is not used instead of that final is used.

Below is the code that compiles successfully.

Simulator.java :

import java.util.Scanner;

//Create the class that would perform the simulation.
public class Simulator {
   public static void main(String[] args) {
       // list of SML instructions
       final int READ_INS = 10;
       final int WRITE_INS = 11;
       final int LOAD_INS = 20;
       final int STORE_INS = 21;
       final int ADD_INS = 30;
       final int SUBTRACT_INS = 31;
       final int MULTIPLY_INS = 32;
       final int DIVIDE_INS = 33;
       final int BRANCH_INS = 40;
       final int BRANCH_NEG_INS = 41;
       final int BRANCH_ZERO_INS = 42;
       final int HALT_INS = 43;

       // variabes for storing the instruction and its details.
       int accumulator;
       int instructionCounter;
       int op_oprnd;
       int op_Code;
       int instructionRegister;

       // simpletron memArray
       int[] memArray;

       // number of instructions entered in memArray
       int index = 0;

       /* Method to run the simpletron simulator */
   }
}

Add a comment
Know the answer?
Add Answer to:
Java Code: I am using the code below but it will not compile. PROGRAM: using System;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT