I've got the following code for simulation:
class Device
{
char status;//requesting, held, releasing idle
int time, idleTime, waitingTime;
int requestEnds, heldEnds;
//public Device(int myDevice)
//{ this(myDevice, 0); }
public Device(int theTime, char theStatus)
{
time = theTime;
status = theStatus;
//waitingTime = 0;
}
public void next()
{
switch (status)
{
case 'R':
requestEnds = time +1;
if (time==requestEnds)
{
status = 'H';
System.out.println("got the bus"
}break;
case 'H':
heldEnds = (int) (500 * Math.random() + 1);
if (time==heldEnds)
{
status = 'R';
System.out.println("bus realesed"
}break;
case 'L':
status = 'I';
System.out.println("device is idle"
break;
case 'I':
idleTime = (int) (10000 * Math.random() + 1);
System.out.println("Idle time is: " + idleTime);
if (time==idleTime)
{
status = 'R';
System.out.println("device is requesting"
} break;
}
}
public void grant()
{
status = 'H';
}
}
public class Bus
{
char status; //granting, holding
double grantEnds, holdingEnds;
public Bus()
{
status = 'G';
grantEnds = 0;
}
public void next(Device d)
{
switch (status)
{ case 'G': //granting
if(time==grantEnds)
{ System.out.println("Holding device"
status = 'H';
holdingEnds = (int) (500 * Math.random() + 1);
System.out.println("Holding ends at: " + holdingEnds);
}
break;
case 'H':
if(time==holdingEnds)
{ System.out.println("Grant next device"
d.grant();
status = 'G';
grantEnds = time + 1;
System.out.println("Grant ends at: " + grantEnds);
}
break;
}
}
//public static final int devicesNo = 20;
public int time;
//Device[] d;
//Bus bus;
public void main(String[] args)
{
Device[] d = new Device[20];
Bus bus = new Bus();
for(time=0; time<=20; time++)
{
for(int i=0; i<=20; i++)
{
d = new Device(time, 'R');
bus.next(d);
d.next();
}
}
}
}
and this is giving me the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main
I hope someone could tell me why.
Thanks in advance.
class Device
{
char status;//requesting, held, releasing idle
int time, idleTime, waitingTime;
int requestEnds, heldEnds;
//public Device(int myDevice)
//{ this(myDevice, 0); }
public Device(int theTime, char theStatus)
{
time = theTime;
status = theStatus;
//waitingTime = 0;
}
public void next()
{
switch (status)
{
case 'R':
requestEnds = time +1;
if (time==requestEnds)
{
status = 'H';
System.out.println("got the bus"
}break;
case 'H':
heldEnds = (int) (500 * Math.random() + 1);
if (time==heldEnds)
{
status = 'R';
System.out.println("bus realesed"
}break;
case 'L':
status = 'I';
System.out.println("device is idle"
break;
case 'I':
idleTime = (int) (10000 * Math.random() + 1);
System.out.println("Idle time is: " + idleTime);
if (time==idleTime)
{
status = 'R';
System.out.println("device is requesting"
} break;
}
}
public void grant()
{
status = 'H';
}
}
public class Bus
{
char status; //granting, holding
double grantEnds, holdingEnds;
public Bus()
{
status = 'G';
grantEnds = 0;
}
public void next(Device d)
{
switch (status)
{ case 'G': //granting
if(time==grantEnds)
{ System.out.println("Holding device"
status = 'H';
holdingEnds = (int) (500 * Math.random() + 1);
System.out.println("Holding ends at: " + holdingEnds);
}
break;
case 'H':
if(time==holdingEnds)
{ System.out.println("Grant next device"
d.grant();
status = 'G';
grantEnds = time + 1;
System.out.println("Grant ends at: " + grantEnds);
}
break;
}
}
//public static final int devicesNo = 20;
public int time;
//Device[] d;
//Bus bus;
public void main(String[] args)
{
Device[] d = new Device[20];
Bus bus = new Bus();
for(time=0; time<=20; time++)
{
for(int i=0; i<=20; i++)
{
d = new Device(time, 'R');
bus.next(d);
d.next();
}
}
}
}
and this is giving me the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main
I hope someone could tell me why.
Thanks in advance.