In: Computer Science
IN PSEUDOCODE AND JAVA SOURCE CODE PLEASE:
Program 0 (Warm-up, 40 pts): Deoxyribonucleic acid, or DNA, is comprised of four bases: (G)uanine, (C)ytosine, (A)denine and (T)hymine. Ribonucleic acid, or RNA, is different than DNA in that it contains no Thymine; thymine is replaced with something called (U)racil. For this assignment, you will create an array of 255 characters. You must start by filling the array with random characters of G, C, A and T. You must then print out the array. Next, replace all the instances of Thymine with Uracil. Finally, you must print out the array again. In your solution, you must write at least one function that contributes to the solution. You must use the length attribute of the array in your answer.
Sample run
CATGGCGTCTTGCCAAGGCGGTTCCTTGTCTTGATGATGGCTGCGAGTTCCGAGTCGCCTTTTCTATGAGTCGCGAAGTATGCGGTCAAATTATGCTTGTCCGCTGTACTAGGCCCACGGATCTCCTCAGACAGCGTCGATGTCGGAATTCGCGGGGAGGAATACTAAACATGCTGAAGTTGATACATGTACAATTGCCGCGAACCAGGTGCACAGGGTGCCCAACGATCCATGTGGAACGAGAGCGATCTAGCC
CAUGGCGUCUUGCCAAGGCGGUUCCUUGUCUUGAUGAUGGCUGCGAGUUCCGAGUCGCCUUUUCUAUGAGUCGCGAAGUAUGCGGUCAAAUUAUGCUUGUCCGCUGUACUAGGCCCACGGAUCUCCUCAGACAGCGUCGAUGUCGGAAUUCGCGGGGAGGAAUACUAAACAUGCUGAAGUUGAUACAUGUACAAUUGCCGCGAACCAGGUGCACAGGGUGCCCAACGAUCCAUGUGGAACGAGAGCGAUCUAGCC
PSEUDOCODE
step 1) intitialize an array of length 255
step 2) generate random numbers in range 1 to 4 inclusive
step 3) Associate each number with an alphabet (G,C,A,T) and store it in the array
step 4) Print the original array
step 5) Traverse the array and replace 'T" with 'U'
step 6) Print the modified array
PROGRAM
import java.util.*;
public class Main
{
public static int randomnum () //This function generates the random
numbers in range 1 to 4
{
Random random = new Random ();
int num = 0;
while (true)
{
num = random.nextInt (5);
if (num != 0)
break;
}
return num;
}
public static void display (char arr[]) //this function is used
to print the array
{
for (int i = 0; i < 255; i++)
System.out.print (arr[i]);
System.out.println ();
}
public static void main (String[]args)
{
char arr[] = new char[255];
Map < Integer, Character > map = new HashMap <> ();
//Map is used to map numbers 1 to 4 to required alphabets
map.put (1, 'G');
map.put (2, 'C');
map.put (3, 'A');
map.put (4, 'T');
for (int i = 0; i < 255; i++)
{
arr[i] = map.get (randomnum ()); //populating the array
randomly
}
System.out.println("Original array is:\n ");
display (arr); //printimg original array
for (int i = 0; i < 255; i++)
{
if (arr[i] == 'T')
arr[i] = 'U'; //replacing T with U
}
System.out.println("\nModified array is:\n ");
display (arr); //printing modified array
}
}
OUTPUT

CODE

