Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me code the following in: JAVA Please create the code in as basic wa

ID: 3601120 • Letter: P

Question

Please help me code the following in: JAVA

Please create the code in as basic way as possible, so I can understand it better :)

Full points will be awarded, thanks in advance!

Basic Statistics Your program will first prompt the user to enter a single DNA sequence, which it should validate for legality (i.e., only the four valid bases) you might do this validation by writing a function that takes a String as a parameter and returns a boolean. Re-prompt the user if the input was invalid. Once you have a valid input, compute the following statistics (each should be implemented as a separate function, called from main()). 1. Count the number of occurrences of "C” Determine the fraction of cytosine and guanine nucleotides. For example, if half of the nucleotides in the sequence are either “C" or "G", the fraction should be 0.5 2. A DNA strand is actually made up of pairs of bases- in effect, two strands that are cross- linked together. These two strands are complementary: if you know one, you can always determine the other, or complement, because each nucleotide only pairs up with one other. In particular, “A" and "T" are complements, as are "C" and "G". So, for example, the complement of the sequence AAGGTCT" would be "TTCCAGA". Compute the complement of the input sequence. 3.

Explanation / Answer

dna.java

import java.util.Scanner;
public class dna
{
public static boolean isvalid(String s)
{
for (int i = 0; i< s.length() ; i++)
{
if(s.charAt(i) != 'C' && s.charAt(i) != 'G' && s.charAt(i) != 'A' && s.charAt(i) != 'T' )
{
return false;
}   
}
return true;
}

public static double countc(String s)
{
double c = 0;
for (int i = 0; i< s.length() ; i++)
{
if(s.charAt(i) == 'C' )
{
c = c+1;
}   
}
return c;
}

public static double countcg(String s)
{
double c = 0;
for (int i = 0; i< s.length() ; i++)
{
if(s.charAt(i) == 'C' || s.charAt(i) == 'G' )
{
c = c+1;
}   
}
return c;
}

public static void Complement(String s)
{
String comp = s;
for (int i = 0; i< s.length() ; i++)
{
if(s.charAt(i) == 'C')
{
System.out.print('G');
}   
if(s.charAt(i) == 'G')
{
System.out.print('C');
}   
if(s.charAt(i) == 'A')
{
System.out.print('T');
}   
if(s.charAt(i) == 'T')
{
System.out.print('A');
}   
}
System.out.println("");
}

public static void main(String[] args)
{
String DNA;
while(true)
{
Scanner scanner = new Scanner(System.in);
System.out.println("Enter DNA Sequence: ");
DNA = scanner.next();
if(isvalid(DNA))
{
System.out.println("C-count: " + countc(DNA));   
System.out.println("CG-ratio: " + countcg(DNA)/DNA.length());
System.out.print("Complement: ");   
Complement(DNA);
break;
}
else
{
System.out.println("Please enter Valid DNA Sequence!");   
}
}

}
}


Sample Output:

Enter DNA Sequence:
AATCTATA
C-count: 1.0
CG-ratio: 0.125
Complement: TTAGATAT


Enter DNA Sequence:
AAGATA
C-count: 0.0
CG-ratio: 0.16666666666666666
Complement: TTCTAT

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote