Avatar of abdullahkhaled007

abdullahkhaled007's solution

to RNA Transcription in the Java Track

Published at Oct 23 2019 · 0 comments
Test suite

Given a DNA strand, return its RNA complement (per RNA transcription).

Both DNA and RNA strands are a sequence of nucleotides.

The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).

The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U).

Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:

  • G -> C
  • C -> G
  • T -> A
  • A -> U


For more help on how to solve this exercise, please refer to the tutorial provided as part of the hello world exercise: TUTORIAL.md


Go through the setup instructions for Java to install the necessary dependencies:


Running the tests

You can run all the tests for an exercise by entering the following in your terminal:

$ gradle test

Use gradlew.bat if you're on Windows

In the test suites all tests but the first have been skipped.

Once you get a test passing, you can enable the next one by removing the @Ignore("Remove to run test") annotation.


Hyperphysics http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class RnaTranscriptionTest {

    private RnaTranscription rnaTranscription;

    public void setUp() {
        rnaTranscription = new RnaTranscription();

    public void testEmptyRnaSequence() {
        assertEquals("", rnaTranscription.transcribe(""));

    @Ignore("Remove to run test")
    public void testRnaTranscriptionOfCytosineIsGuanine() {
        assertEquals("G", rnaTranscription.transcribe("C"));

    @Ignore("Remove to run test")
    public void testRnaTranscriptionOfGuanineIsCytosine() {
        assertEquals("C", rnaTranscription.transcribe("G"));

    @Ignore("Remove to run test")
    public void testRnaTranscriptionOfThymineIsAdenine() {
        assertEquals("A", rnaTranscription.transcribe("T"));

    @Ignore("Remove to run test")
    public void testRnaTranscriptionOfAdenineIsUracil() {
        assertEquals("U", rnaTranscription.transcribe("A"));

    @Ignore("Remove to run test")
    public void testRnaTranscription() {
        assertEquals("UGCACCAGAAUU", rnaTranscription.transcribe("ACGTGGTCTTAA"));

class RnaTranscription {

    int i;

    String transcribed = "";
    String transcribe(String dnaStrand) {
        int length = dnaStrand.length();
        for (i = 0; i < length; i++) {
            if (dnaStrand.charAt(i) == 'G') {
                transcribed += "C";
            } else if (dnaStrand.charAt(i) == 'C') {
                transcribed += "G";
            } else if (dnaStrand.charAt(i) == 'T') {
                transcribed += "A";
            } else if (dnaStrand.charAt(i) == 'A') {
                transcribed += "U";
            } else {
                throw new IllegalArgumentException("Invalid input");

        return transcribed;

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?