Soru
A: 3 T: 3 C: 3 G: 3 Date: 16/10/2024 due on 30/10/2024 Problem: DNA Sequence Analysis You are given a DNA sequence, which is a string composed of the characters 'A', 'T', 'C' and 'G' Write a program that counts the occurrences of each nucleotide ( 'A' , "T", "C", and 'G' ) in the sequence. Solve this problem using Java implementing it in three different paradigms: 1. Imperative Approach: Write a loop-based solution where you iterate over the sequence, count each nucleotide's occurrences, and display the result. 2. Object-Oriented Approach:Create a class DNAAnalyser that holds the DNA sequence and provides a method countNucleotides to count and return the occurrences of each nucleotide. 3. Functional Approach: Use Java's functional programming features (e.g., Streams and Collectors.groupingBy) to count the occurrences of each nucleotide in a functional style. Input:"ATCGATCGATCG"
Çözüm
3.5
(202 Oylar)
Veli
Usta · 5 yıl öğretmeni
Uzman doğrulaması
Cevap
1. Imperative Approach:```javapublic class DNASequenceAnalysis { public static void main(String[] args) { String sequence = "ATCGATCGATCG"; int[] count = new int[4]; for (int i = 0; i count = sequence.chars() .collect(Collectors.groupingBy(nucleotide -> nucleotide, Collectors.counting())); System.out.println("A: " + count.get('A')); System.out.println("T: " + count.get('T')); System.out.println("C: " + count.get('C')); System.out.println("G: " + count.get('G')); }}```All three approaches will produce the same output for the given input sequence "ATCGATCGATCG":```yamlA: 3T: 3C: 3G: 3```