Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Convert the code to GUI

Have Programming Question? Ask it here!
 
 
 


33
Convert the code to GUI
0 Answer(s)      2 years and 3 months ago
Posted in : Java Beginners


can any one convert My code to GUI code 

import java.util.Scanner;

public class RegistorClass {

 private int accumulator;  private int instructionCounter;  private int instructionRegister;  private int operationCode;  private int operand;  private boolean halt;  private MemoryClass memory;// Operation codes 
// Input/Output operations.  private final int READ = 10;  private final int WRITE = 11;    // Load/Store operations.  private final int LOAD = 20;  private final int STORE = 21;     // Arithmetic operations.  private final int ADD = 30;  private final int SUBTRACT = 31;  private final int DIVIDE = 32;  private final int MULTIPLY = 33;   // Transfer-of-control operations. private final int BRANCH = 40;  private final int BRANCHNEG = 41;  private final int BRANCHZERO = 42;  private final int HALT = 43;public RegistorClass(MemoryClass memory1){

     accumulator = 0;        instructionCounter = 0;       instructionRegister = 0;        operationCode = 0;       operand = 0;        halt = false;         memory = memory1;}   public  int getOperationCode(int word)  {        int operationCode = word / 100;       return operationCode;  }public int getOperand(int word) { 
int operand = word % 100; return operand; } 

public boolean executeNextInstruction() { 

 if (halt)  return false;         // Read next instruction from memory.    instructionRegister = memory.read(instructionCounter);   operationCode = getOperationCode(instructionRegister);   operand =getOperand(instructionRegister);        boolean transferOfControl = false;        //  execute the instruction.   switch (operationCode)  {       case READ:            Scanner scan = new Scanner(System.in);         // Read a word from the keyboard.               System.out.print("Enter an integer: ");                       // Write word to memory.               memory.write(operand, scan.nextInt());             break;            case WRITE:               // Read a word from memory.            int data = memory.read(operand);               // Display the word on the screen             if (!halt)         System.out.println(data);                  break;             case LOAD:            // Load a word from memory into the accumulator.           accumulator = memory.read(operand); //    accumulator=memory[operand];      break;case STORE:            // Store accumulator into memory.           memory.write(operand, accumulator);  // memory[operand]=accumulator;       break;             case ADD:            // Add word from memory to accumulator.             accumulator += memory.read(operand);             break;             case SUBTRACT:            // Subtract word from memory from accumulator.               accumulator -= memory.read(operand);              break;            case DIVIDE:            // Divide accumulator by a word loaded from memory.             int divisor = memory.read(operand);   //divisor=memory[oprand] ;         if (!halt)                 if (divisor == 0)                 {                        System.out.println("*** Attempt to divide by zero ***");                   }                else            accumulator /= divisor;                break;          case MULTIPLY:            // Multiply accumulator by a word loaded from memory.              accumulator *= memory.read(operand);            break;       case BRANCH:            // Branch to location in memory.               instructionCounter = operand;              transferOfControl = true;               break;             case BRANCHNEG:            // Branch to location in memory if accumulator is negative.             if (accumulator < 0)            {              instructionCounter = operand;                 transferOfControl = true;           }            break;case BRANCHZERO: 

   // Branch to location in memory if accumulator is zero.             if (accumulator == 0)      {            instructionCounter = operand;            transferOfControl = true;              }            break;             case HALT:                  System.out.println("*** Simpletron execution terminated ***");              transferOfControl = true;             halt = true;            break;           default:            System.out.println("*** Invalid operation code ***");             halt= true; // break;         }          if (!transferOfControl)            instructionCounter++;   return !halt;  }public void dump() { 
System.out.printf(" accumulator\t\t\t%+05d\n", accumulator); System.out.printf("instructionCounter\t\t %02d\n", instructionCounter); System.out.printf("instructionRegister\t\t%+05d\n", instructionRegister); System.out.printf("operationCode \t\t\t %02d\n", operationCode); 
System.out.printf("operand \t\t\t\t %02d\n", operand);

}public static void main(String[] args) 

 {         System.out.println("*** Welcome to Simpletron! ***");          System.out.println("*** Please enter your program one instruction   ***");         System.out.println("*** (or data word) at a time. I will display    ***");          System.out.println("*** the location number and a question mark (?) ***");         System.out.println("*** You then type the word for that location.   ***");          System.out.println("*** Type -99999 to stop entering your program.  ***");          System.out.println();     MachineClass machine = new MachineClass ();       machine.inputProgramToMemory();      machine.executeProgram();} }

class MachineClass {

private MemoryClass memory1; 
private RegistorClass registor1 ; 
public static final int MEMORY_WORD = 100;

public MachineClass(){       memory1=new MemoryClass( MEMORY_WORD);     registor1=new RegistorClass(memory1);}public void inputProgramToMemory() { 
Scanner input =new Scanner(System.in); 

int memoryWord=0;final int END_OF_INPUT = -9999;      System.out.printf("%02d ? ", memoryWord);int data = input.nextInt();while(data !=END_OF_INPUT)      {         memory1.write(memoryWord,data);   memoryWord++;   System.out.printf("%02d ? ", memoryWord);     data = input.nextInt();}           System.out.println("*** Program loading completed ***");           System.out.println(); }public void computerDump() { System.out.println(); 
System.out.println("REGISTERS:"); 
registor1.dump(); 
System.out.println(); 
System.out.println("MEMORY:"); 
memory1.dump(); } 

// Execute program  public void executeProgram(){        System.out.println("*** Program execution begins  ***");             while (  registor1.executeNextInstruction()) ;                 computerDump(); }}

class MemoryClass {

private int[] memory; public MemoryClass(int amountOfMemoryWord ){ memory = new int[amountOfMemoryWord]; 

} // Write a value to memory.  public void write(int word, int value) {             if (word < 0 || word >= memory.length)        {               System.out.println("*** Attempt to write to a non-existing memory location ***");         }     else memory[word] = value;  }   public int read(int word) {        int value = 0;            if (word < 0 || word >= memory.length)        {      System.out.println("*** Attempt to read from a non-existing  memory location ***");          }        else value = memory[word];       return value;  }    public void dump() {          System.out.print( "   ");       for (int i = 0; i < 10; i++)       System.out.printf("%5d ", i);            System.out.println();            for (int i = 0; i < memory.length; i += 10)        {              System.out.print("  "+ i+ " ");              for (int j = 0; j < 10 && i+j < memory.length; j++)                       System.out.printf("%+05d ", memory[i + j]); //05>>> to print five digits ???                        System.out.println();         }  } `print("code sample");`


thanks,,

Advertisement
View Answers

Related Tutorials/Questions & Answers:
Convert the code to GUI
How to Convert the code to GUI   How to convert a code into GUI
Convert the code to GUI
Is it possible to convert a code into GUI  Is it possible to convert a code into GUI
Advertisements
Convert the code to GUI
Convert the code   How to convert a code to GUI look alike
Convert the code to GUI
Java Code to GUI   can any one convert My code to GUI code
Convert the code to GUI
GUI code  GUI code
Convert the code to GUI
GUI Example  GUI Example code to learn
Convert the code to GUI
GUI Application example  GUI Application example
Convert the code to GUI
Java GUI Class Example  Java GUI Class Example
Convert the code to GUI
GUI Java JSP application  GUI Java JSP application
Convert the code to GUI
GUI Application Development   GUI Application Development
Convert the code to GUI
Write a GUI Application  best way to write a GUI based application
Convert the code to GUI
Java and GUI application Example  Java and GUI application Example
Convert the code to GUI
How to create GUI application in Java   How to create GUI application in Java
Convert the code to GUI ??
Convert the code to GUI ??  hi >> can anyone help me to conver this code to GUI ?? /** * @(#)RegistorClass.java * *. * @author...("*** Invalid operation code ***"); halt= true; // break
Convert the code to GUI
Convert the code to GUI   can any one convert My code to GUI code...: System.out.println("*** Invalid operation code... ??? System.out.println(); } } `print("code sample");` thanks
HOW TO CONVERT THIS CODE INTO GUI
HOW TO CONVERT THIS CODE INTO GUI   System.out.println("\n\t UGANDA CHRISTIAN UNIVERSITY\n"); System.out.println("\n\tFACULTY OF SCIENCE AND TECHNOLOGY\n"); System.out.println("\n BACHELOR OF SCIENCE IN COMPUTER
Convert the code to GUI
GUI example for beginners  GUI example for beginners  sory ,, I will posted my code again import java.util.Scanner; public class...; default: System.out.println("*** Invalid operation code
convert this code to GUI
convert this code to GUI  hello.. this is my code.. import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks
convert this code to GUI
convert this code to GUI  hello.. this is my code.. import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks
convert this code to GUI
convert this code to GUI  hello.. this is my code.. import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.*; class Author{ public String name; public BookList<Book>books=new BookList<Book>(); public Author(){ } public boolean equals(Object node){ return name.equals
convert this code to GUI
convert this code to GUI  import java.util.*; class Author{ public String name; public BookList<Book>books=new BookList<Book>(); public Author(){ } public boolean equals(Object node){ return name.equals
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
convert this code to GUI
convert this code to GUI  import java.util.Scanner; public class StudentGrade { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks; //"this" keyword
Convert this code to GUI - Java Beginners
); } }  hi friend, We have convert your code into GUI...Convert this code to GUI  I have written this.i need to convert the following code to GUI:- import java.awt.*; import java.applet.*; import
How to convert this Java code into GUI?
How to convert this Java code into GUI?   import java.util.Scanner; public class StudentMarks { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks
"Urgent" convert this code to GUI - Swing AWT
"Urgent" convert this code to GUI   please convert for me this code to GUI THE CODES ARE BELOW, CLASS ATMCaseStudy is the driver class that runs all the other classes. its very urgent. //CLASS CashDispenser public class
please convert for me this code to GUI - Swing AWT
please convert for me this code to GUI    THE CODES ARE BELOW, CLASS ATMCaseStudy is the driver class that runs all the other classes. its very urgent. // class ATM import javax.swing.*; import java.awt.*; public
please convert for me this code to GUI - Swing AWT
please convert for me this code to GUI  THE CODES ARE BELOW, CLASS ATMCaseStudy is the driver class that runs all the other classes. its very urgent. // class ATM import javax.swing.*; import java.awt.*; public class ATM
convert to GUI
convert to GUI  import java.util.Scanner; public class Exam { public static void main (String args[]) { int numberStudent, mark, markAplus = 0, markA = 0, markBplus = 0, markB = 0, markBminus = 0, i; int markCplus = 0, markC
GUI convert to celsius program - Java Beginners
GUI convert to celsius program  how to write java GUI program to convert Fahrenheit to Celsius that need user to input value of Fahrenheit... friend, Code to convert Fahrenheit to Celsius : import java.awt.
Java GUI code
Java GUI code  Write a GUI program to compute the amount of a certificate of deposit on maturity. The sample data follows: Amount deposited..., computer 80000.00 (1+7.75 /100)^15   Hi Friend, Try the following code
covert this code to GUI
covert this code to GUI  import java.util.*; class Author{ public String name; public BookList<Book>books=new BookList<Book>(); public Author(){ } public boolean equals(Object node){ return
covert this code to GUI
covert this code to GUI  import java.util.*; class Author{ public String name; public BookList<Book>books=new BookList<Book>(); public Author(){ } public boolean equals(Object node){ return
GUI and how to convert a distance - Java Beginners
GUI and how to convert a distance  i need help.. how to create a GUI application that can be is used to convert a distance unit in miles into its... JLabel("In Inches"); l5=new JLabel("In CM"); b=new JButton("Convert
Rental Code GUI - Java Beginners
Rental Code GUI  dear sir... i would like to ask some code of java GUI form that ask the user will choose the menu to input Disk #: type: title: record company: price: director: no. of copies
Java GUI code- creating a circle
Java GUI code- creating a circle  My assignment is to write a program..., and area. I did my code but I can't seem to figure out the mathematical code...; //GUI components JLabel lClx, lCly, lCircumrx, lCircumry, lRadius
Catching Exceptions in GUI Code - Java Tutorials
.style1 { text-align: center; } Catching uncaught exception in GUI In this section, we will discuss how to catch uncaught exceptions in GUI. Lets see the given below code to identify the uncaught exception : import
Java code to convert pdf file to word file
Java code to convert pdf file to word file  How to convert pdf file to word file using Java
GUI
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml
gui question
gui question  design a gui application for me and write its code in which the user enters a no. in a textfield and onn clicking the button the sum of the digits of the no. should be displayed. hint: suppose the user enters 12
java gui
java gui   friends... good day.. i have doubt in java gui. ? i created 1 java gui application. That has two text fields jtext1,jtext2. case: user... must go to the next text field(jtext2). How can i arrange this. which code can i
GUI framework
GUI framework  what do u mean by GUI framework
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?
How to solve this java code by adding the student marks not in the list of the table. For example -10 and 156 in GUI?  import java.awt.*; import javax.swing.*; import java.awt.event.*; public class MarkStudent { double
GUI component
GUI component  How can a GUI component handle its own events
 

 

 

DMCA.com