help required
hey guys
i want to construct a program which manages a 0.25kb cache
i want to write a class organising the cache using direct mapping
the program takes address references in the range 0 .. 1023
and determines whether a given address reference is a hit or miss.
It also computes the Miss rate every time a miss is encountered
and at the end displays of the cache contents.
it also assumes that the address holds 8 bytes
i have had a go at writing the code but am unable to get it to compile im getting an error saying "count has private access in java.util.hashtable
i would very grateful if someone could point out where im going wrong and if the code is looking right in general.
thanks
oops
here it is
import java.util.Hashtable;
import java.lang.Math;
/**
* Write a description of class DirectMapping here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class CacheMapper extends Hashtable
{
private boolean hitOrMiss = false;
private final long upperBound = 0x03ff;
private final long lowerBound = 0x000;
private Hashtable ht = new Hashtable();
public static void main(String[] args)
{
if(args.length > 0)
{
++count;
long address = 0;
long count = 0;
long miss = 0;
double missRate = 0.0;
CacheMapper cm = new CacheMapper();
cm.ht.SetCapacity(0x0250);
if( (Math.ParseInt(args[0]) > cm.lowerBound)
&&
(Math.ParseInt(args[0]) < cm.upperBound))hitOrMiss = true;
if(cm.hitOrMiss)
{
address = Math.ParseInt(args[0]);
cm.ht.put(address);
}
else
{
missRate = ( ++miss / count );
}
if(cm.ht.size > 0x0250)
{
}
}
}
}
You have a lot of errors. count is indeed a private member of HastTable, so you can't access it, even from a subclass (protected is the access level that let's subclasses see it). HashTable doesn't have any of these methods/members: SetCapacity(int), put(long), or size. Math doesn't have a ParseInt(String) method either. You're probably thinking of Integer.parseInt. Notice that methods start with lower-case letters, especially api methods.