mardi 28 février 2017

How to return 1 String in case there are multiple IF statements

How can I return 1 value, in case I have some IF statements?

For example, when I choose Shopify, it calls a new method that allows me to type into console some need credentials and then append all typied data into 1 String and return that String(test) to Main class. In case, I choose Bigcommerce, it calls pretty much the same method and append all needed credentials for Biggcomerce into 1 String(test2) as well. But in this case public String credentailsCollector() should return test2.

How can I do that? Thanks.

public class CartCredentialsCollector {
//it should return something like this: 
//store_url=https://test.myshopify.com&apiKey=myapikey&apiPassword=myapipassword

public String credentailsCollector() throws IOException {

    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

    System.out.println("Do you want to connect a new shopping cart ('yes'/'no')");
    String newConnection = bufferedReader.readLine();
    if (newConnection.equals("no")) {
        bufferedReader.close();
    } else {
        System.out.println("Specify your shopping cart. It works with Shopify and Bigcommerce only");
        String newShoppingCart = bufferedReader.readLine();
        if (newShoppingCart.equals("Shopify")) {
            ShopifyCredentialsHandler sch = new ShopifyCredentialsHandler();
            String test = sch.shopifyCredentialsHandler();
        }
        else if (newShoppingCart.equals("Bigcommerce")) {
        BigcommerceCredentialsHandler bch = new BigcommerceCredentialsHandler();
        String test2 = bch.bigcommerceCredentialsHandler()
        }

        else {
            System.out.println("This method works with Shopify and Bigcommerce. Try to connect a Shopify or Bigcommerce store.");
            bufferedReader.close();
        }
    }
    // Here I need to return test (in case I choose "Shopify") or test2 (in case I choose "Bigcommerce"). How can I do that?
    }
}

Aucun commentaire:

Enregistrer un commentaire