Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7952643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:55:20+00:00 2026-06-04T02:55:20+00:00

This is my Config File(Test.txt) CommandA 75% CommandB 15% CommandC 10% I wrote a

  • 0

This is my Config File(Test.txt)

CommandA   75%
CommandB   15%
CommandC   10%

I wrote a multithreading program in which I am reading the files line by line but not sure how should I do the above question in which this much percentage(75%) of random calls go to CommandA, and this much percentage(15%) of random calls go to CommandB and same with CommandC.

public static void main(String[] args) {

            for (int i = 1; i <= threadSize; i++) {
                new Thread(new ThreadTask(i)).start();
            }
        }

class ThreadTask implements Runnable {

        public synchronized void run() {
            BufferedReader br = null;

            try {
                String line;

                br = new BufferedReader(new FileReader("C:\\Test.txt"));

                while ((line = br.readLine()) != null) {
                    String[] s = line.split("\\s+");
                    for (String split : s) {
                    System.out.println(split);
                }
            }

            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (br != null)br.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }

        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:55:21+00:00Added an answer on June 4, 2026 at 2:55 am

    Get a random number 1-100. If the number is 1-75 do command A, 76-90 do command B, 91-100 do command C.

    EDITED for comment:

    There are two ways I would consider doing this. If you only have the three commands (A, B, C) then you can do a simple:

        int[] commandPercentages = {75, 15, 10};        
        int randomNumber = 90;
    
        if((randomNumber -= commandPercentages[0]) < 0) {
            //Execute Command A
        }
        else if((randomNumber -= commandPercentages[1]) < 0) {
            //Execute Command B
        }
        else {
            //Execute Command C
        }
    

    if you have a lot of complicated commands you can set up the commands like so:

    private abstract class Command {
        int m_percentage;       
        Command(int percentage) {
            m_percentage = percentage;
        }       
        int getPercentage() {
            return m_percentage;
        }
        abstract void executeCommand();
    };
    
    private class CommandA extends Command {        
        CommandA(int percentage) {
            super(percentage);
        }
        @Override
        public void executeCommand() {
            //Execute Command A
        }       
    }
    
    private class CommandB extends Command {        
        CommandB(int percentage) {
            super(percentage);
        }
        @Override
        public void executeCommand() {
            //Execute Command B
        }
    
    }
    

    and then choose the command like so:

        Command[] commands = null;  
        int randomNumber = 90;
    
        commands[0] = new CommandA(75);
        commands[1] = new CommandB(25);
    
        for(Command c: commands) {
            randomNumber -= c.getPercentage();
            if(randomNumber < 0) {
                c.executeCommand();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My config file looks like this: title = myTitle; otherTitle = myOtherTitle; when I
This is my web.config file contents: <?xml version=1.0?> <configuration> <system.webServer> <httpErrors errorMode=Detailed /> <asp
i read data from my config file like this: ip_vlan1 = 10.10.($id+100).5 ip_vlan2 =
I have this variable defined in my web.config file : <appSettings> <add key =version
I'm using this code to read the connection string from my app.config file but
Please refer to this post. I have become able to configure my web.config file
config.php put at the root level, this file will be included in any pages.
I have a php file that looks like this: <?php include(config.php); // put the
ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes
Looking in the android sdk folders, I've found a file called values/config.xml . This

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.