128k views
0 votes
Write a test client which takes a file path as an argument and reads each line one by one. If the current line is valid DNA, print out its complement as well as whether or not it is a Watson-Crick complemented palindrome.

1 Answer

3 votes

Answer:

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.Scanner;

public class WCComplement {

public static boolean palindromeWC(String input){

if(input==null)

return false;

for(int i=0,j=input.length()-1; i<j; i++, j--){

if(input.charAt(i) != input.charAt(j))

return false;

}

return true;

}

public static void main(String[] args) throws IOException {

Scanner sc = new Scanner(System.in);

System.out.print("Enter input file name: ");

String fileName = sc.next();

FileReader fr = new FileReader(fileName);

BufferedReader br = new BufferedReader(fr);

String line;

while((line = br.readLine()) != null){

if(palindromeWC(line))

System.out.println(line+" is Watson-Crick complemented");

}

br.close();

fr.close();

sc.close();

}

}

Step-by-step explanation:

User Serpent
by
5.8k points