Java - Error Message Help

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2010-03-29T04:04:45Z Indexed on 2010/03/29 4:13 UTC
Read the original article Hit count: 326

Filed under:

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

© Stack Overflow or respective owner

Related posts about java