Question

In: Computer Science

randomGenotype() create a valid genotype of size 12, using random values valid genotype contains each of...

randomGenotype()

  • create a valid genotype of size 12, using random values
  • valid genotype contains each of the numbers 1 to 12 exactly once

HERE IS THE CODE

_____________________________________________________________________________________________________________________________________________________

public static Integer [] randomGenotype()
{
    Integer [] genotype = new Integer [boardSize];

    // YOUR CODE GOES HERE
    // DUMMY CODE TO REMOVE:
    genotype = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
    // END OF YOUR CODE

    return genotype;
}

Solutions

Expert Solution

import java.util.Random;
public class RandomNum {
   public static void main(String args[])
   {
       int[] array=randomGenotype();
       for(int i=0;i<12;i++)
           System.out.print(array[i]+" ");
   }
   public static int [] randomGenotype()
   {
   int [] genotype = new int [12];
   Random rand = new Random();
   int num ;
   int i=0;
  
   do
   {
       num = rand.nextInt(100);
       int c=1;
       for(int j=0;j<genotype.length;j++)
       {
           if(genotype[j]==num)
           {
               c=0;
               break;
           }
       }
       if(c==1)
       {
           genotype[i]=num;
           i++;
       }
       else
       {
           continue;
       }
   }while(i<12);

   // YOUR CODE GOES HERE
   // DUMMY CODE TO REMOVE:
   //genotype = new Integer[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
   // END OF YOUR CODE

   return genotype;
   }
}


Related Solutions

Based on the calculated values of Kc for each reaction stoichiometry, which reaction is the valid...
Based on the calculated values of Kc for each reaction stoichiometry, which reaction is the valid one? Fe(aq)3+ + SCN(aq)- FeSCN(aq)2+ The average value of Kc: 369.10 Fe(aq)3+ +2 SCN(aq)- Fe(SCN)2(aq)+ The average value of Kc: 988999.02 Briefly explain your conclusion. Compare the percent difference between the average value and the individual measurements. What does this tell you about the two possible stoichiometries? Do these reactions give consistent values of Kcfor different initial reaction conditions?
A bag contains 12 balls of the same shape and size. Of these, 9 balls are...
A bag contains 12 balls of the same shape and size. Of these, 9 balls are blue, and the remaining 3 balls are red. Suppose that you do the following iterative random experiment: In each iteration, 5 balls are removed randomly (without replacement) from the bag, in such a way that any 5 balls in the bag are equally likely to be the 5 balls that are removed. After doing this, you check whether among the 5 removed balls there...
Research the topics thoroughly using valid, reliable sources. 2-Each student will prepare an 8-12 page research...
Research the topics thoroughly using valid, reliable sources. 2-Each student will prepare an 8-12 page research paper (2-3 pages for each question): double-spaced, Times New Roman and 12-point font. 3-Originality is a “must” in research. Therefore, use your own words when answering questions - DO NOT copy text from your book or any other source. Copied answers will result in a zero on this assessment. 4-Use references, if needed. Please use APA format when citing sources. OB = Organization Behavior...
create a function that sorted tuple by the second values of each tuple. If the values...
create a function that sorted tuple by the second values of each tuple. If the values are the same, sorted by increasing order. Finally returns a list of the first element of each tuple that sorted. def sort_tup(tup): #Code here input : tup1 = [(1, 15), (2, 8), (3, 22), (4, 30), (5, 15)] output: [4,3,1,5,2]
A block of memory contains 40 random words of data. Assume that the values are in...
A block of memory contains 40 random words of data. Assume that the values are in two’s complement representations and are stored in the Read/Write memory area. You need to provide the 40 random words and to include them in an initialization file: assign.ini. Write a program using the ARM assembly programming language to do the following: a) You are required to reverse the word order in a block of 40 random words (Hint: the last word stored in the...
a) If random samples of size 12 are drawn from a population with mean 7 and...
a) If random samples of size 12 are drawn from a population with mean 7 and standard deviation 2 , find the standard error of the distribution of sample means. b) Assume the sample is a random sample from a distribution that is reasonably normally distributed and we are doing inference for a sample mean. Find endpoints of a t-distribution with 0.025 beyond them in each tail if the sample has size n=26. c) Assume the sample is a random...
Introduction to logic: Translate each argument using the letters provided and prove the argument valid using...
Introduction to logic: Translate each argument using the letters provided and prove the argument valid using all eight rules of implication. Sam will finish his taxes and Donna pay her property taxes or Sam will finish his taxes and Henry will go to the DMV. If Sam finishes his taxes, then his errands will be done and he will be stress-free for a time. Therefore, Sam will finish his taxes and he will be stress-free for a time. (S, D,...
Suppose a random sample of size 51 is selected from a population with = 12. Find...
Suppose a random sample of size 51 is selected from a population with = 12. Find the value of the standard error of the mean in each of the following cases (use the finite population correction factor if appropriate). a. The population size is infinite (to 2 decimals). b.The population size is N = 50,000 (to 2 decimals). c. The population size is N = 5,000 (to 2 decimals). d.The population size is N = 500 (to 2 decimals).
ARDUINO Create a function that will ask the user to enter the values for each of...
ARDUINO Create a function that will ask the user to enter the values for each of the three colors (red, green and blue) between 0 and 255. The function should check that the user does not enter a number bigger than 255 or smaller than 0. If this happens, the function should keep asking for a valid number.
Create a random matrix of size 10x10, of integers between 1 and 1000, and use nested...
Create a random matrix of size 10x10, of integers between 1 and 1000, and use nested for loops over the elements of the matrix to find the number of prime elements , as well as the sum of the prime elements in the matrix. You can use MATLAB's built-in function isprime to check if an element is a prime number. You should have these variable: cnt (counts the number of prime elements) sm (sum of prime elements) In the command...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT