开发者

Java - Error Message Help

In the Code, mem is a of Class Memory and getMDR and getMAR ruturn ints. When I try to compile the code I get the following errors.....how can I fix this?

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());

Here is the code for Computer:

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();
                    }
            }
    }

Here is the code for 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());
    }
}

Here is the code for getMAR and getMDR:

public int getMAR()
{
    return ir.getOpcode();
}
public int getMDR()
{
    return mdr.read();
}


Your Memory class has a method write(int, int). You call it with a single int. As if it was write(int).

Java complains about that: "Computer.java:28: write(int,int) in Memory cannot be applied to (int)". So either you are missing your location (loc) parameter or your value (val) parameter; depending on what code is supposed to be actually doing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜