Reputation:
class Memory{
private int[] memoryArray;
private int size;
public Memory(int n)
{size = n;
memoryArray = new int[n];
for(int i=0;i<n;i++)
memoryArray[i] = -1;
}
public void write (int loc,int val)
{if (loc >=0 && loc < size)
memoryArray[loc] = val;
else
System.out.println("index out of range");
}
public int read (int loc)
{return memoryArray[loc];
}
}
Here is my program to test it...
class Test{
public static void main(String[] args)
{
Memory mymem = new Memory(100);
mymem.write(98 , 4);
int x;
x = mymem.read(98);
System.out.println(mymem);
mymem.dump();
for(int i=0;i<size;i++)
if(i%10==0)
System.out.println(memoryArray[i]);
else
System.out.println(memoryArray[i]);
}
}
So when I type in java Memory to run it I get an error saying "Exception in thread "main" java.lang.NoSuchMethodError:main and when I run java Test it outputs [email protected] can I fix this?
Upvotes: 1
Views: 213
Reputation: 59983
Your Memory
class does not have a main()
method.
You probably want to type java Test
.
Regarding your other problem, memoryArray
isn't visible from your Test
class. And Memory
doesn't have a dump
method.
Upvotes: 5