Please Help, Urgent(C_SCAN)


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Please Help, Urgent(C_SCAN)

  1. #1
    Join Date
    Mar 2004
    Posts
    1

    Please Help, Urgent(C_SCAN)

    I have develop a C-SCAN disk algorithms but don why my code didn't work pls help, it is urgent

    import java.io.*;
    import java.util.*;

    public class CSCAN
    {
    private Vector requested;
    private Vector requests;
    private float heads;
    private float tracks;
    private float sectors;
    private float RPM;
    private float seekRate;
    private boolean debug;
    static Access preAcc;
    }

    public CSCAN (Vector access,float head,float track,float sector,float rpm,float seekrate,boolean deb)
    {
    requests=new Vector();
    requests=access;
    requested=new Vector();
    heads=head;
    tracks=track;
    sectors=sector;
    RPM=rpm;
    seekRate=seekrate;
    debug=deb;
    preAcc=new Access();
    }

    private boolean valid(Access acc)
    {
    if (acc.track>=tracks||acc.sector>=sectors||acc.head>=heads)
    return(false);
    if(preAcc!=null&&preAcc.requestTime>acc.requestTime)
    return(false);
    return(true);
    }
    public void simulate()
    {
    float curTime=0;
    float curTrack=0;
    float curSector=0;
    float distance=0;
    float reads=0;
    float latency=0;
    float readTime=0;

    System.out.println("Using Circular-SCAN");
    if(debug)
    System.out.println("Starting heads at <0,0>");
    int index=0;
    int ic;
    Access acc=new Access();
    while (true)
    {
    while (index<requests.size())
    {
    acc=(Access)requests.elementAt(index);
    if(acc.requestTime>curTime)
    break;
    else
    {
    index++;
    if (valid(acc))
    {
    preAcc=acc;
    requested.addElement(acc);
    if(debug)
    System.out.println("Read request: <"+acc.track+","+acc.sector+","+acc.head+">");
    }
    else
    if(debug)
    System.out.println("Read request: <"+acc.track+","+acc.sector+","+acc.head+"> Invalid request");
    }
    }
    boolean exist=true;
    while (exist)
    {
    exist=false;
    for(ic=0;ic<requested.size();ic++)
    {
    acc=(Access)requested.elementAt(ic);
    if (acc.track==curTrack)
    {
    exist=true;
    break;
    }
    }
    if (exist)
    {
    reads++;
    if(debug)
    System.out.println("Move heads to: <"+acc.track+","+acc.sector+","+acc.head+">");
    requested.remove(acc);
    if (curSector>acc.sector)
    {
    latency+=(float)(sectors-curSector+acc.sector)*60/sectors/RPM;
    curTime+=(float)(sectors-curSector+acc.sector)*60/sectors/RPM;
    }
    else
    {
    latency+=(float)(acc.sector-curSector)*60/sectors/RPM;
    curTime+=(float)(acc.sector-curSector)*60/sectors/RPM;
    }
    readTime+=curTime-acc.requestTime;
    curSector=acc.sector;
    if(debug)
    System.out.println("Read <"+acc.track+","+acc.sector+","+acc.head+">");
    while (index<requests.size())
    {
    acc=(Access)requests.elementAt(index);
    if(acc.requestTime>curTime)
    break;
    else
    {
    index++;
    if (valid(acc))
    {
    preAcc=acc;
    requested.addElement(acc);
    if(debug)
    System.out.println("Read request: <"+acc.track+","+acc.sector+","+acc.head+">");
    }
    else
    if(debug)
    System.out.println("Read request: <"+acc.track+","+acc.sector+","+acc.head+"> Invalid request");
    }
    }
    }
    }
    if (requested.isEmpty()&&index==requests.size())
    break;
    if (curTrack==(tracks-1))
    {
    curTrack=0;
    curTime+=(float)(tracks-1)/seekRate;
    distance+=tracks-1;
    curSector=(float)(sectors*RPM/60*(tracks-1)/seekRate+curSector)%sectors;
    }
    else
    {
    curTime+=(float)1/seekRate;
    distance++;
    curTrack++;
    curSector=(float)(sectors*RPM/60/seekRate+curSector)%sectors;
    }
    }
    System.out.println("Total number of Reads:"+reads);
    System.out.println("Total distance traveled:"+distance);
    if(reads==0)
    System.out.println("No read at all");
    else
    {
    System.out.println("Average Seek time:"+(float)distance/seekRate/reads+" seconds");
    System.out.println("Average latency:"+latency/reads+" seconds");
    System.out.println("Average total read time:"+readTime/reads+" seconds");
    }
    System.out.println("Press any key to continue...");
    try
    {
    System.in.read();
    System.in.skip(1);
    }
    catch (IOException exce)
    {
    }
    }
    }

    Please help

  2. #2
    Join Date
    Feb 2004
    Posts
    541
    well i don't know why it doesn't work, but when posting code (especially when theres a lot) you should enclose it in code tags. [ CODE ] and [ /CODE ] (without the spaces). This will indent it all nicely and make it much more readable

  3. #3
    Join Date
    Feb 2004
    Posts
    808

    Re: Please Help, Urgent(C_SCAN)

    Originally posted by derickloo
    [B]I have develop a C-SCAN disk algorithms but don why my code didn't work pls help, it is urgent

    import java.io.*;
    import java.util.*;
    Code:
    public class CSCAN
    {
    		private Vector requested;
    		private Vector requests;
    		private float heads;
    		private float tracks;
    		private float sectors;
    		private float RPM;
    		private float seekRate;
    		private boolean debug;
    		static Access preAcc;
    }
    Just to reinforce mikebarr81's point about indentation... if you go and get yourself a capable text editor like www.ultraedit.com, and then ask it to "reindent selection" on your entire code.. you will see it is indented.

    you will also see your constructor is indented at level 0, which means you some how closed your class before you wrote the constructor

    if you look at the fragment of your code i have posted above, you can see that you open a new class.. declare a load of class variables, then close the class.

    fyi a typical class looks like this:

    Code:
    public class CLASSNAME{
    
      //class variables go here
    
      public CLASSNAME(){ //this is a constructor
      }
    
      public RETURNTYPE METHODNAME(PARAMETERS){
    
        //method variables go here
    
        //method code goes here
      }
    
      //..more methods go here..
    }
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center