Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Help in Scheduling please????

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help in Scheduling please????

    Hi am new here and as well to java.. Let me come straight to my problem.. My Problem is as follows:

    There are a number of customers waiting to use a machine. Each customer is allotted a time for which he can use the machine.. The customer with the minimum time is allowed to use the machine first followed by the next customer. this process continues till all have finished their alloted times.

    the ques is using time of customers are int[] using_time{10,7,3,4,11}
    the time alloted for the machine is int time=5;


    Now i have to return an array in the order in which the customer with the minimum balance started to use that is in this example first the customer at position 3 will use then cust at pos 4 followed by7 and the customer at the last position 5 will use last.. Again the cycle continues with the customer at position 2 who has a balance of 2 will use the machine.. This is more like a Round Robin algorithm problem... The difficulty i am having is in returning an array of the position of the customers who first started to use the machine with the minimum balance... The answer to this one is
    {3,4,2,1,5,2,1,5,5}
    ---the index numbers of the persons starting with the minimum balance

    well the code i wrote is very very very very bad but this is what i could manage
    class Machine
    {
       int[] get_time(int b[],int t)
    {
        int[] index=new int[b.length]; // array to store index positions
        int[] diff=new int[b.length];  //array to store difference
        for(int i=0;i<b.length;i++)
    {
        if(b[i]<=t)
      {
        index[i]=i+1;
      }
    }
     
    for(int i=0;i<b.length;i++)
    {
      if(b[i]>t)
    {
     diff[i]=b[i]-5;
         if(diff[i]<5)
       {
          index[i]=i+1;
        }
    }
    }
    for(int i=0;i<b.length;i++)
    {
      if(diff[i]>t)
    {
        index[i]=i+1;
       diff[i]=diff[i]-5;
    }
     
     
     
    }
     return index;
    }
     
     
     
    public static void main(String args[]) 
    {
     
    int[] bt = {10, 7, 3, 4, 11};
    int time_alloted=5;
    int[] output=new Machine().get_time(bt,time_alloted);
    if(output.length>0){
     
    for(int i=0;i<output.length;i++)
    {
      System.out.println(output[i]);
    }
    }
    }
    }

    The answer i am getting is 0,1,2,3,4,5.. I know my method is wrong but when i break the code down into jus the if-conditions i am getting the index positions like
    if(b[i]>t)
     temp[i]=i+1;
    println(temp[i]);
    I dont know how to combine them and how to reduce the if conditions...Should i use a recursive function so that i can check to see if the difference is greater than time allotted ??? Please help me and i am very very sorry if my question is long as i wanted to give all the details.. Am really sorry for the long quest but plz help me


  2. #2
    Junior Member
    Join Date
    Dec 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help in Scheduling please????

    please guys any help?? still stuck in de problem thought this forums wud be helpfull

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help in Scheduling please????

    Hey, sorry to dredge up an old topic but I have the same question, with the exception of 'jobs' and 'processors' not machines, and I"m required to implement a priority queue...

    Can anyone give an example of how this code would look? Or how to create a 'minimum priority' queue?

    Much appreciated!

Similar Threads

  1. non preemptive scheduling.....challenging!!
    By snehil2009 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 8th, 2009, 03:07 AM
  2. Replies: 1
    Last Post: March 18th, 2009, 06:21 AM