Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 708801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:25:55+00:00 2026-05-14T04:25:55+00:00

In the Code, mem is a of Class Memory and getMDR and getMAR ruturn

  • 0

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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:25:55+00:00Added an answer on May 14, 2026 at 4:25 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I can't understand why does the following code produce memory leaks (I am using
Instruments tells me there's a mem leak in this code, but I can't seem
I experience a segfault on the following code: I have an abstract class A
I try to get this code running. I am almost there but I got
Code that is untestable really annoys me. The following things make oo-code untestable: global
Code #include <OOLua/oolua.h> class foo { public: int bar(); }; OOLUA_CLASS_NO_BASES(foo)//class has no bases
I have this code in JavaScript: function change() { document.getElementById(mem).className = 'gif'; } The
This page (from C++ in action book) shows code: class Link { friend class
when from a java class i try to acces a item of my strings.xml
I'm trying to control mem leaks in my code. In my general header file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.