Results 1 to 5 of 5
Like Tree2Likes
  • 2 Post By doWhile

Thread: Call Different Task Based on their Percentage

  1. #1
    raihan26 is offline Member
    Join Date
    Mar 2010
    Posts
    18
    Rep Power
    0

    Default Call Different Task Based on their Percentage

    Java Code:
        Task1, X% 
        Task2, Y%
        Task3, Z%
        ----
        TaskN, N%
    
        And X + Y + Z + . . .  + N = 100%
    Question:- The above Config File have some type of weighing to Different Tasks (execute Task1 X% of the time, execute Task2 Y% of the time and execute Task3 Z% of the time and etc etc. Total weighing should add up to 100%.

    Code that I wrote:- I wrote a program in which I am reading the files line by line and stored all the lines in the ArrayList of String, and then I generated some random number between 1 and 100. So for example there are three Tasks-

    Java Code:
    Task1 75%
        Task2 15%
        Task3 10%

    Get a random number between 1-100. If the number is 1-75 do Task1, 76-90 do Task2, 91-100 do Task3. But how I can expand this for any Config File having N Tasks with any percentage number. I am stuck on this part.

    Java Code:
    private static Random r = new Random();
        	            private final static int Low = 1;
        	            private final static int High = 100;
                        String sCurrentLine;
                        ArrayList<Integer> percentageCalls = new ArrayList<Integer>();
            
            			br = new BufferedReader(new FileReader("S:\\config.txt"));
            			
                        int R = r.nextInt(High-Low) + Low;
            			
            			ArrayList<List<String>> allLines = new ArrayList<List<String>>();
            			while ((sCurrentLine = br.readLine()) != null) {
            				allLines.add(Arrays.asList(sCurrentLine.split("\\s+")));
            				Collections.shuffle(allLines);
            			}
            			
            			for (List<String> s1 : allLines) {
            				percentageCalls.add(Integer.parseInt(s1.get(0)));
            			}
            			Collections.sort(percentageCalls, Collections.reverseOrder());

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    raihan26 is offline Member
    Join Date
    Mar 2010
    Posts
    18
    Rep Power
    0

    Default Re: Call Different Task Based on their Percentage

    Hi Fubarable, Any suggestion will be appreciated on my question.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,236
    Rep Power
    19

    Default Re: Call Different Task Based on their Percentage

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

    Default Re: Call Different Task Based on their Percentage

    Hi Fubarable, Any suggestion will be appreciated on my question.
    I recommend being forthright up front with crossposting...think of it from our perspective - we do this unpaid, in our spare and valuable time...what a slap in the face it is to find we spent our time trying to answer a question that has been answered (or even discussed) elsewhere. Given this, you shouldn't be surprised when a cross post is found by someone other than the original poster and activity and comments on your post(s) (at least those productive to you) diminish to zero.
    Last edited by doWhile; 05-16-2012 at 06:07 AM.
    DarrylBurke and Fubarable like this.

Similar Threads

  1. Time Based View of Call logs.
    By Raguram in forum Android
    Replies: 0
    Last Post: 04-08-2012, 03:46 AM
  2. Transfer file get percentage complete
    By LG87 in forum Networking
    Replies: 5
    Last Post: 06-16-2011, 09:04 PM
  3. Load percentage of an image
    By trishtren in forum Java 2D
    Replies: 0
    Last Post: 04-15-2011, 02:02 PM
  4. is there is any java based call center dialer?
    By 435.mahesh in forum Java Software
    Replies: 0
    Last Post: 03-06-2009, 06:20 AM
  5. Percentage/decimal points?
    By Exhonour in forum New To Java
    Replies: 6
    Last Post: 01-16-2009, 10:35 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •