Hi I'm having difficulting creating a class called Input to accept the users input, I then want this input to go to my class called Memory.
I'm truely stumped does anyone have any idea? or could point me in the right direction?
Thank You
Cameron.
Hi I'm having difficulting creating a class called Input to accept the users input, I then want this input to go to my class called Memory.
I'm truely stumped does anyone have any idea? or could point me in the right direction?
Thank You
Cameron.
"Having difficulty" how?
Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!
Er... what exactly do you mean? We'll need more info to help you out.I then want this input to go to my class called Memory
- Mike
Sorry for being so vauge in my last post, I am trying to simulate the process of a computer.
What I need to do is write lines on the console at the end of each step in the program from a text file. This text file represents the machine code instruction for a cpu.
The cpu instruction set is:
1/ Read next instruction into memory.
2/ Input from keyboard.
3/ Write memory to output.
4/ Push memory onto Stack.
5/ Add stack to memory.
6/ Pop stack into memory.
7. Halt.
The lines being output to the console will be in columns such as:
Instruction
1
adding
3
2
Input
10
Memory
0
adding
adding
10
Stack
0
0
0
0
Output
adding
adding
(there is more but this is the start)
The instruction column shows each line in the program text file.
I'm using classes that represent components in the computer e.g. CPU, PROGRAM, MEMORY, INPUT, ALU etc.
Now I don't want you guys to think I'm one of those posters who has joined asking you to do this for me, it's just that I have no idea what to do next I have done a basic INPUT class but not the kind of INPUT I need to accomplish this task.
My input class:
import java.io.*;
import java.util.*;
/**
* Used to recieve input from the user.
*
* Cameron Lett
* 8/4/07
*/
public class Input
{
/**
* Constructor for objects of class input
*/
public static void main (String[] args) throws java.io.IOException
{
try
{
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Input a number: ");
String line = stdin.readLine();
System.out.println("Adding");
stdin.close();
}
catch (IOException io)
{
System.err.println("IO Exception Caught");
io.printStackTrace();
}
}
}
So any pointers or advice would be greatly appreciated.
Thanks.
Last edited by drummond; 04-28-2007 at 08:09 AM.
fair enough, I will try to help ...
it's not a working code but something like that ...
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Input a number: ");
String line = stdin.readLine();
boolean is_loop = true;
while (is_loop) {
switch (line.strim()) {
case "1": //read instruction into memory
String line = stdin.readLine();
Momory.push(line); //momory should be stack.
break;
case "2": line = stdin.readLine();
3/ Write memory to output.
4/ Push memory onto Stack.
5/ Add stack to memory.
6/ Pop stack into memory.
break;
case "7": is_loop = false;
default: //do nothing
break;
}
}
stdin.close();
ken
Hoobin.com
Bookmarks