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

java code wont compile, So I have this code that is supposed to read a file with

ID: 3855256 • Letter: J

Question

java code wont compile,

So I have this code that is supposed to read a file with a DNA sequence and print out the three reading frames but it wont compile.

mport java.io.*;

import java.util.*;

public class readfile {

private Scanner x;

public void openFile(){

try{

x = new Scanner(new File("hwk3.seq.txt"));

}

catch(Exception e){

System.out.println("could not find file");

}

}

public void readFile(){

while(x.hasNext()){

String a = x.next();

System.out.printf("%s ",a);

}

class test1{

public void main(String[] args) {

readfile r = new readfile();

r.openFile();

r.readFile();

}

private static void showAminoAcids(Sequence s)

{

System.out.println("Sequence: " + s.getSequence() + " ");

ArrayList<String> codons;

for(int i = 1; i <= 3; i++)

{

codons = s.codon(i);

System.out.println("Codons Frame " + i +":");

s.codon2aa(codons);

System.out.println(" ");

}

  

System.out.println("**************** ");

}

}

  

Explanation / Answer

The code is not compiling because of these mistakes -

Following is the corrected code -

import java.io.*;

import java.util.*;

public class readfile {

private Scanner x;

public void openFile(){

try{

x = new Scanner(new File("hwk3.seq.txt"));

}

catch(Exception e){

System.out.println("could not find file");

}

}

public void readFile(){

while(x.hasNext()){

String a = x.next();

System.out.printf("%s ",a);

}

}

class test1{

public void main(String[] args) {

readfile r = new readfile();

r.openFile();

r.readFile();

}

private static void showAminoAcids(Sequence s)

{

System.out.println("Sequence: " + s.getSequence() + " ");

ArrayList<String> codons;

for(int i = 1; i <= 3; i++)

{

codons = s.codon(i);

System.out.println("Codons Frame " + i +":");

s.codon2aa(codons);

System.out.println(" ");

}

}

System.out.println("**************** ");

}

}

}