简体   繁体   中英

Handling Multiple User Inputs in Java

I have multiple inputs from a user based on that I wrote some methods to perform some operations.

To handle user input I have to use if else if or switch case. Looking for more feasible solutions rather than using multiple if-else or switch cases.

Input samples include radio buttons, checkboxes, dropdowns. So I have already written some methods to perform some operations.

Instead of that is there any feasible solution.

You can create an abstract layer. Something like this:

    public class TestInputs() {

    boolean radioButtonFoo1
    boolean checkBoxFoo2

    public boolean getRadioButtonFoo1() {
    return radioButtonFoo1
    }

    public boolean getCheckBoxFoo2() {
    return checkBoxFoo2
    }

    public TestInputs(boolean radioButtonFoo1, boolean checkBoxFoo2) {
    this.radioButtonFoo1 = radioButtonFoo1
    this.checkBoxFoo2 = checkBoxFoo2
    }

    TestInputs testInputs = new TestInputs(true, false)
    }

Your test case class can extend this TestInputs class so you can call your test data directly:

if (testInputs.getRadioButtonFoo1 == true) {
// do something
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM