mercredi 26 août 2020

How do I add a condition on my main class

I was tasked to create a program that will let the user choose either to compute the area and perimeter of either a rectangle or triangle. However, I am having a problem with the perimeter part of triangle because the perimeter of a rectangle should be a+b>c or b+c> a, and this is the condition representation that I'd like to use: a+b>c, b+c>a, a+c>b,a!=0, b!=0, c!=0. By the way, I used abstract methods as it is what our professor taught us today. Here is my main class code:

public class Main {
  public static void main(String[]args) {
        Scanner in = new Scanner(System.in);
        int choice = 0;
        System.out.println("[1] Rectangle \n[2] Triangle\n Input your choice:");
        choice = in.nextInt();
        Rectangle obj = new Rectangle(0,0);
        Triangle obj1 = new Triangle(0,0,0,0,0);
    if (choice == 1)
    {
          System.out.println("You chose rectangle.");
          System.out.println("Please input width: ");
          obj.setData1(in.nextInt());
          System.out.println("Please input length: ");
          obj.setData2(in.nextInt());
          obj.computePerimeter();
          obj.computeArea();
          obj.display();
    }
    else if (choice == 2) 
    {

        System.out.println("You chose triangle.");
        System.out.println("Please input value for a: ");
        obj1.setData1(in.nextInt());
        System.out.println("Please input value for b: ");
        obj1.setData2(in.nextInt());
        System.out.println("Please input value for c: ");
        obj1.setC(in.nextInt());
        System.out.println("Please input value for base: ");
        obj1.setBase(in.nextInt());
        System.out.println("Please input value for height: ");
        obj1.setHeight(in.nextInt());
        obj1.computePerimeter();
        obj1.computeArea();
        obj1.display();
    
    } else{
       System.out.println("Invalid value.");
   }
  }
}

Arm template if condition

I am trying to implement if condition for the arm template. Idea is from the parameter to read if it suppose to deploy in prod or nonprod sub and have the subnets predefined. Then deploy storage and add some subnets to the storage account virtual network list.

The following line causing troubles:

"virtualNetworkRules": "[if(equals(parameters('Sub'), 'nonprod'),'variables('nonprodvirtualNetworkSubnets').virtualNetworkRulesCopy', 'variables('prodvirtualNetworkSubnets').virtualNetworkRulesCopy', )]",

All help is much appreciated.

"Parameters": {

"Sub": {
    "type": "string",
    "defaultValue": "nonprod",
    "metadata": {
      "description": "Prod or nonprod sub"
    }
  }
},
"variables": {
    "subscriptionId": "[subscription().subscriptionId]",
    "resourcegroupName": "[toUpper(concat(parameters('splitSubscriptionName')[0], '-', parameters('splitSubscriptionName')[1], '-', parameters('splitSubscriptionName')[2], '-02-NET-RSG'))]",
    "virtualNetworkname": "[toLower(concat(parameters('splitSubscriptionName')[0], '-', parameters('splitSubscriptionName')[1], '-', parameters('splitSubscriptionName')[2], '-02-NET-', parameters('splitSubscriptionName')[3], '-00-net'))]", 
    "storageAccountType": "Standard_LRS", //  "allowedValues": ["Standard_LRS", "Standard_GRS", "Standard_ZRS", "Premium_LRS"]
    "blobServicesName": "default",
    "VirtualNetworkExternalId": "[concat('/subscriptions/', variables('subscriptionId'), '/resourceGroups/', variables('resourcegroupName'), '/providers/Microsoft.Network/virtualNetworks/', variables('virtualNetworkname'), '/subnets/')]",
    "nonprodAllowedSubnets": [
      "mngm00-devtest-sub",
      "mngm01-devtest-sub",
      "mngm02-devtest-sub"
    ],
    "prodAllowedSubnets": [
      "mngm00-prod-sub",
      "mngm01-prod-sub"      
    ],
    "nonprodvirtualNetworkSubnets": {
      "copy": [
        {
          "name": "virtualNetworkRulesCopy",
          "count": "[length(variables('nonprodAllowedSubnets'))]",
          "input": {
            "id": "[concat(variables('VirtualNetworkExternalId'), variables('nonprodAllowedSubnets')[copyIndex('virtualNetworkRulesCopy')])]",
            "action": "Allow",
            "state": "Succeeded"
          }
        }
      ]
    },
    "prodvirtualNetworkSubnets": {
      "copy": [
        {
          "name": "virtualNetworkRulesCopy",
          "count": "[length(variables('prodAllowedSubnets'))]",
          "input": {
            "id": "[concat(variables('VirtualNetworkExternalId'), variables('prodAllowedSubnets')[copyIndex('virtualNetworkRulesCopy')])]",
            "action": "Allow",
            "state": "Succeeded"
          }
        }
      ]
    }
  },
  "resources": [
    {
      
      "type": "Microsoft.Storage/storageAccounts",
      "apiVersion": "2019-04-01",
      "name": "[parameters('storageAccountName')]",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "[variables('storageAccountType')]"
      },
      "kind": "[parameters('storageAccountKind')]",
      "properties": {
        "accessTier": "[parameters('accessTier')]",
        "supportsHttpsTrafficOnly": true,
        "allowBlobPublicAccess": false,
        "networkAcls": {
          "bypass": "AzureServices",
          "virtualNetworkRules": "[if(equals(parameters('Sub'), 'nonprod'),'variables('nonprodvirtualNetworkSubnets').virtualNetworkRulesCopy', 'variables('prodvirtualNetworkSubnets').virtualNetworkRulesCopy', )]",
          "defaultAction": "Deny"
        },
        "encryption": {
          "services": {
            "file": {
              "enabled": true
            },
            "blob": {
              "enabled": true
            }
          },
          "keySource": "Microsoft.Storage"
        }
      }
    }
]
}


javascript using variables if statement

And please dont recommend another one cuz i tried 2 examples from there and still doesnt work. Just need something to work that string value "va"+i (va1, va2, va3 , va4, va5 etc...) can be used inside if statement even though they appear correct on the console log i cant use it on if statement

       var vu1 = document.getElementById('vu1').value; //get vu value from table
       var va1 = document.getElementById('va1').value; // get va value from table
      
        for(i = 1; i < 6; i++){ //start for loop so i can write "va"+i as (va1 etc)
        window["test"] = "va"+i; //one way of getting that va1 for if statement
        test2=window["test"]; // other way of getting that va1 for if statement
        
        var va = "va"+i;
        var vu = "vu"+i;
        var obj = {va, vu}; //another way of getting that va1 for if statement
        var key = 'va';
        console.log(obj[key]); // all those 3 console logs write the va1 to va5 correctly on consolse
        console.log(test2);
        console.log(window["test"];

        if( va1 to va5(have to say va1 here. "va"+i)  > 0){ //but isnt working this way. When try to use that variable in if statement doesnt work despite the fact that va1 appears right. should i indicate the variable differently?
            dp1 = va1/vu1;
            document.getElementById("dp1").value = dp1;
        }
    }

Count until condition is true

Count how many time will make a sample of two numbers from a vector of 'x <- c(2,4,5,6,8,3)' with replacement before the two numbers add up to '11'. Stop loop as soon as it obtained two numbers exactly equal to 11 and then count how many samples was selected before the stop?

 x <- c(2,4,5,6,8,3)
 y <- c()
 repeat{y <- c(y, sample(x[!x %in% y], 1) )
if( sum(v2) == 11 )
break
 }

I am interested in how many count of sample of two that sum up to did not sum up to 11 before the first samples that did sum up to 11.

Why is my variable not defined? Javascipt

I've already decreal a global variable in a function, but in the other function its says "variable not defined".

function myFunction1 {
  myFunction2();
  myFunction3();
}
funcion myFunction2() {
  computerChoice = "rock";
}

function myFunction3() {
  if (computerChoice == "rock") {
    console.log("rock");
  }
}

Use random gradient from my own Custom list for the Bacckground ( SCSS )

I have my few own combinations of gradient that I want to use in my the website background in different areas.

I want them to Change every time the page refreshes.

I have already coded the gradient at different paces with different degree on gradient angle using 2 variables

$primary-color

$secondary-color

Now, In my variables.scss file, I want to get random pair of primary and secondary color to be taken as these variables value.

Gradient Combinations:

  1. #ffafbd → #ffc3a0

  2. #2193b0 → #6dd5ed

  3. #cc2b5e → #753a88

I want user to experience any one of the above gradient as the background of different <div> tags ( on which i have applied the gradient code ) every time they refresh or new user enters my website

I don't know how to make a conditional statement using 'while' , 'for' , 'if' etc

I'm an introductory member of Python. Currently, I feel difficulty for trying to code with Python in the conditional statement.

I am trying to extract a number of data values that satisfy special conditions.

Let me explain it to you.

'funcs' and 'coeff' defined numpy array.

In[192]: funcs
Out[192]: 
array([[ 1.06661229e-77,  2.79600427e-81, -3.18670959e-82,
     2.44699438e-81,  4.80121022e-82,  5.17937328e-82],
   [-6.85044722e-80,  3.31723764e-82, -1.90092928e-82,
     6.46861276e-82, -5.78786178e-82, -1.00729181e-82],
   [-1.63162271e-66,  3.38187298e-66,  7.57423529e-66,
    -4.09894792e-65,  3.78265103e-65,  1.82943877e-67],
   [-4.95693797e-09, -1.45229642e-08, -1.04330464e-08,
    -2.01224903e-09, -5.35270495e-09, -6.08458972e-09],
   [-2.12823433e-79,  5.82159029e-80, -8.99421065e-80,
    -1.41016928e-79, -1.67255631e-79, -1.86441120e-79],
   [ 3.15461229e-79, -2.36439314e-79, -4.90090515e-80,
     1.09641210e-80,  4.78412802e-80,  8.10728566e-80],
   [-7.73169440e-09, -6.63806299e-09, -3.42737105e-09,
    -1.10738572e-08, -2.55383682e-08, -1.41581744e-08],
   [ 3.22951472e-02, -6.99601691e-02,  2.53791702e-01,
     1.16700285e-01, -6.95036777e-01,  3.20910932e-01],
   [ 1.05815854e-08, -3.05259173e-09, -9.75855424e-09,
    -9.37246653e-09,  8.68981664e-10, -6.30852393e-09]])

In[193]: coeff
Out[193]: 
array([[ 2.26303373e-83, -2.03621368e-82, -6.42965381e-82,
     4.25254729e-81, -6.07915460e-81,  2.64394236e-81],
   [-8.46364599e-85, -1.16391626e-82,  1.66851234e-81,
    -5.41903835e-81,  6.46938773e-81, -2.59600686e-81],
   [ 5.69414622e-68, -3.52383975e-66,  3.28779598e-65,
    -9.51823310e-65,  1.08072939e-64, -4.21845745e-65],
   [ 1.23232073e-04,  4.05304829e-02, -1.17887992e-01,
     2.34849268e-01, -2.21198557e-01,  7.14445930e-02],
   [-7.72065565e-85,  1.50181866e-82, -1.70427344e-81,
     5.19665852e-81, -6.00699921e-81,  2.35776178e-81],
   [ 2.34175985e-84, -2.19865506e-82,  2.29092448e-81,
    -6.85846672e-81,  7.89183700e-81, -3.09769363e-81],
   [ 1.93436945e-04, -1.13538750e-02,  8.67116554e-02,
    -1.33231032e-01,  3.51553202e-02,  2.07234342e-02],
   [-1.55588574e-04,  8.31273435e-03, -7.60387134e-02,
     2.70458606e-01, -3.75730885e-01,  1.72915967e-01],
   [ 1.93436968e-04, -1.13538762e-02,  8.67116650e-02,
    -1.33231056e-01,  3.51553445e-02,  2.07234255e-02]])

Here i introduce the special condition that 'funcs' are smaller than '10^-9' and the 'coeff' is greater than '10^-4' as shown in the code below.

funcs_valid = np.all(np.abs(funcs) < 10**-9, axis=1)

coeff_valid = np.all(np.abs(coeff) > 1e-4, axis=1)

both_valid = coeff_valid & funcs_valid

However, My goal must be at least one true element of 'both_valid' array.

In [159]: both_valid
Out[159]: array([False, False, False, False, False, False, False, False, False])

The results of the above coding are as follows. So I changed criterion value of 'funcs' to 10^-7 instead of 10^-9. The results are as follows.

In [199]: both_valid
Out[199]: array([False, False, False,  True, False, False,  True, False,  True])

And my final goal is to get a 'coeff' when I meet this condition. The results are as follows.

In[203]: coeff[both_valid]
Out[203]: 
array([[ 1.23232073e-04,  4.05304829e-02, -1.17887992e-01,
     2.34849268e-01, -2.21198557e-01,  7.14445930e-02],
   [ 1.93436945e-04, -1.13538750e-02,  8.67116554e-02,
    -1.33231032e-01,  3.51553202e-02,  2.07234342e-02],
   [ 1.93436968e-04, -1.13538762e-02,  8.67116650e-02,
    -1.33231056e-01,  3.51553445e-02,  2.07234255e-02]])

Finally, What i want is to get a 'coeff' array when at least one of the 'both_valid' array elements satisfy 'true' when i start the change the criterion value of 'funcs' from 10^-10 to 10^-1.

I would appreciate it if Python experts could help me with coding that meets the above conditions.