在代码中,mem是类内存和getMDR以及getMAR ruturn int。当我尝试编译代码时,我得到以下错误.....我该如何解决这个问题?
Computer.java:25: write(int,int) in Memory cannot be applied to (int)
Input.getInt(mem.write(cpu.getMDR()));
^
Computer.java:28: write(int,int) in Memory cannot be applied to (int)
mem.write(cpu.getMAR());
以下是计算机的代码:
class Computer{
private Cpu cpu;
private Input in;
private OutPut out;
private Memory mem;
public Computer()
{
Memory mem = new Memory(100);
Input in = new Input();
OutPut out = new OutPut();
Cpu cpu = new Cpu();
System.out.println(in.getInt());
}
public void run()
{
cpu.reset();
cpu.setMDR(mem.read(cpu.getMAR()));
cpu.fetch2();
while (!cpu.stop())
{
cpu.decode();
if (cpu.OutFlag())
OutPut.display(mem.read(cpu.getMAR()));
if (cpu.InFlag())
Input.getInt(mem.write(cpu.getMDR()));
if (cpu.StoreFlag())
{
mem.write(cpu.getMAR());
cpu.getMDR();
}
else
{
cpu.setMDR(mem.read(cpu.getMAR()));
cpu.execute();
cpu.fetch();
cpu.setMDR(mem.read(cpu.getMAR()));
cpu.fetch2();
}
}
}
以下是Memory的代码:
class Memory{
private MemEl[] memArray;
private int size;
public Memory(int s)
{size = s;
memArray = new MemEl[s];
for(int i = 0; i < s; i++)
memArray[i] = new MemEl();
}
public void write (int loc, int val)
{if (loc >=0 && loc < size)
memArray[loc].write(val);
else
System.out.println("Index Not in Domain");
}
public int read (int loc)
{return memArray[loc].read();
}
public void dump()
{
for(int i = 0; i < size; i++)
if(i%1 == 0)
System.out.println(memArray[i].read());
else
System.out.print(memArray[i].read());
}
}
以下是getMAR和getMDR的代码:
public int getMAR()
{
return ir.getOpcode();
}
public int getMDR()
{
return mdr.read();
}
答案 0 :(得分:1)
您的Memory类有一个方法write(int,int)。 你用一个int来调用它。好像是write(int)。
Java抱怨说:“Memory中的Computer.java:28:write(int,int)不能应用于(int)”。所以要么你缺少你的位置(loc)参数或你的值(val)参数;取决于应该实际执行的代码。