Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You? 3. Activities 3.1 Substring Searching 1. Open the DnaAnalysis.java and data/H1Ninucleotide.txt files 2. Modify the main method to read in a DNa subsequence from

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
You? 3. Activities 3.1 Substring Searching 1. Open the DnaAnalysis.java and data/H1Ninucleotide.txt files 2. Modify the main method to read in a DNa subsequence from the command line (and to echo an error and exit if it is not provided) 3. The code to read in and process the nucleotide sequence is already provided. Observe how it works: a static block is executed when the class is loaded up by the JVM (before any methods are ever called). This allows you to do any static initialization of variables. The loadDnaFromFile() method has been written for you. It reads in the file line by line concatenating it into one large string. It then trims out all whitespace using a regular expression 4. Implement the countSubsequences() method to count the number of occurrences of the provided subsequence. You may want to keep the Java String documentation open to find any method(s) that will help you process the DNA string: 3.2 File Processing 1. Open Baseball.java the Tean.java source files. The Team class has already been implemented for you. Recall from lab 2 you can create an instance of an object by using the new keyword to call the class's constructor. For example: // Huskers had 8 wins, 4 losses: Team t = new Team("Huskers", 8, 4); 2. Much of the code has been provided for you, including code to sort the teams by win percentage and print them out (study this code as it may be useful in future assignments). 3. Finish implementing the loadData() method by adding code to open the mlb_nl_2011.csv data file (in the data directory), process it line-by-lie and create individual Tean instances. 3.2.1 File Output In this activity, you will write a method to output the sorted team list to a file rather than the standard output. To output to a file, use the class which supports easy output to files. A full example: try to Printwriter pw = new Printwriter("path/to/filename.txt"); pw.write("you can output a string directly using this method!"); pw.printf("Or you can use printfi "); pw.close(); } catch (FileNotFoundException fote) ( throw new RuntineException(infe); > Baseball.java 2 DnaAnalysis.java Team.java H1N1nucleotidett 30 import java.io.File; 6 70 /** 8 * Processes DNA data and counts the number of instances that a particular DNA 9 * subsequence appears. 10 11 */ 12 public class DnaAnalysis ! 13 14 private static final String DNA_FILE "data/H1Ninucleotide.txt"; 15 private static final String RNA 16 170 static 18 11 load the contents of the file statically when the class 19 11 is loaded) 20 DNA = loadDnaFromFile(): 21 } 22 230 /** 24 * Loads a DNA string from the (@link #DNA_FILE} and returns it as a string with 25 *all whitespace removed. 26 27 * @return 28 290 public static String LoadDnaFromFile() { 30 31 Scanner s = null; 32 33 S = new Scanner(new File(DNA_FILE)); 34 } catch (FileNotFoundException e) { 35 throw new RuntimeException(e); 36 } 37 38 String dna - "" 39 40 while (s.hasNextLine()) { 41 dna 1 s.nextLine(); 42 43 11 close the scanner s.close(); 45 // strip all whitespace 46 dna - dna.replaceAll("\\$", "); 47 returnar R Problems Javadoc Declaration O errors, 3 warnings, others Description Path Location Type Warnings (3 items) try { 44 Resource > Witable Smart Insert 1:1:0 MacBook Air Baseball.java DnaAnalysis.Java Team.java H1N1nucleotide.txt 31 Scanner s = null; 32 try { 33 S = new Scanner(new File(DNA_FILE)); 34 } catch (FileNotFoundException e) { 35 throw new RuntimeException(e); 36 } 37 3B String dna = "; 39 40 while (s.hashextLine()) { 41 dna te S.nextLine(); 42 43 11 close the scanner 44 S.close(); 45 // strip all whitespace 46 dna = dna.replaceAll("\\s+", "); 47 return dna; 48 } 49 580 ** 51 Counts the number of times subsequence appears in the 52 * (@link #DNA) string 53 54 * @return 55 560 public static int countSubsequences(String subsequence) { 57 258 // TODO: implement 59 return 0; 60 } 61 620 public static void main(String args[]) { String subsequence = null; 65 int count - countSubsequences(subsequence); 67 68 System.out.println(subsequence" appears " + count + " times"); 69 70 } 71 72 ) 23 R Problems Javadoc Declaration O errors, 3 warnings, others Description Resource Path Location Warnings (3 items) pel 63 64 66 | writable Smart Insert 1:1:0 H1N1nucleotide.txt Baseball.java DnaAnalysis.java Team.java 1 gsatcattacttataaaaasaasast tagatanat.cagas. 2 atatattaacatsaacaasassaastttastastagasaa 3 tsaatggtttc aaattagsang.saattsstattst 4 gasstattaat gastatatas 5 tataagaatse gggato. 6 gaaccattsa sts.cssstt 7.tsttcttgastsa gggssttast tasatts 8 saatagaascatti aggags aac.csta 9 ataagctatsst tacaast 10 saagatttaatsaatcasttaatsagsaas isttatsa 11 taatagsatsaattagctaacaattag 12 gasaatgggg taaag acaacataa 13 taacagas gaga: tatattgag 14 aasasaagi catat gttsttas 15 tttastat ggsst 16 satacaagi aagatagtsaa 17 atsagtsgaaat staattatsactatgaggaa 18 tastsetat tagtaaa cacatatatat 19 gsagggataas st.saatcgascatastats 20 tttcaassag tatsasa. gatasatatas 21 agtaggat: aat.ssa gacaana 22 cagacagttat agtatcatstag aatga 23 agtaaaaga atacag ttga 24 atagagaga attagttcaaga tttta 25 agataatt gaacggata taggasagasaa 26 taasttstsaa atcet: 27 tggt sag aas 28 taacaggas t.taa 29 astaatsagag agas tagast 30 agsaggagcag.at ttttgtagtataaasagtaasa. 31 ctataggttagtsttagssagasaatastaast 32 I Declaration B. Problems Javadoc O errors. 3 warnings. O others Locati * Baseball.java DnaAnalysis.java Team.java H1N1nucleotide.txt 30 import java.util.ArrayList;/ 7 80 /** 9 * Processes a comma-separated value (CSV) file of win/loss data from the 2011 10 * National League MLB season. It sorts the teams (best record to worst) and 11 * prints a report to the standard output. 12 13 * @author skaucke 14 15 */ 16 public class Baseball { 17 18 private static final String ETLE_NAME = "datalb_nl_2011.csv"; 19 200 public static List loadData() { 21 22 List teams = loadData(); 34 35 System.out.println("Teams: "); 36 for (Team t : teams) ( 37 System.out.println(t); 38 } 39 480 Collections.sort(teams, new Comparator Teams() { 410 @Override 42 public int compare(Team a, Team b) { return b.getWinPercentage().compareTo(a.getWinPercentage()); } 46 }); 1 47 48 System.out.println(" Sorted Teams: "); 49 for (Team t teams) { 58 System.out.println(t); 51 } 52 53 > 54 55) 43 44 45 Declaration Problems Javadoc O errors, 3 warnings, others Description > Warnings (3 items) Resource Path Ilocation Type Writable Smart Insert 1:10 Baseball.java OnaAnalysis.java Team Java HIN1 nucleotide.txt 10 public class Team { 11 12 public final String name; 13 public final Integer wins; 14 public final Integer loss; 15 160 public Team(String name, Integer wins, Integer loss) { 17 this.name = name; 18 this.wins = wins; 19 this. loss = loss; 20 21 220 public String getName() { 23 return this.name; 24 } 25 260 public Integer getwins() { 27 return this.wins; 28 } 1 29 300 public Integer getloss() { 31 return this. loss; 32 } 33 340 *** 35 * Returns the win percentage (on the scale (0, 1]) of 36 * this team. 37 * @return 38 390 public Double getwinPercentage() { 40 return this.wins / (double) (this.wins + this. loss); 41 } 42 A430 public String toString() { 44 return this.name="1" + this.wins + ", " + this. loss + "" 45 } 46 470 @Override A48 public int hashCode() { final int prime - 315 50 int result = 15 51 result - prime result + ((loss su null) 70 loss.hashCode()); 52 result - prime result + (nonews null)? 1 name.hashCode(2 53 result - prine result + ((wins null) 7 0 1 wins.hashCode()); 54 return results 55 56 57 @Override ASB public boolean equals(object obj) { 59 if (this obj) 60 return true R Problems Javadoc Declaration O errors, 3 warnings, o others Description Resource Location Warnings (3 Items) 49 Path IType 44 Baseball.java DnaAnalysis.java Team.java X H1N1nucleotide.txt Return the will percentage Tom the state tu, 1170 56 * this team. 17 * @return 58 */ 890 public Double getWinPercentage() { 30 return this.wins / (double) (this.wins + this. loss); 1 } 12 30 public String toString() { return this.name + " " + this.wins + ", " + this. loss + ")"; 45 } 46 470 @Override 48 public int hashcode() { 49 final int prime - 31; 50 int result = 1; 51 result = prime * result + ((loss == null)? 0 : loss. hashCode()); 52 result = prime * result + ((name == null) ? 0 : name.hashCode()); 53 result - prime * resuq ((wins == null)? 0 : wins.hashcode()); 54 return result; 55 56 570 @Override A58 public boolean equals(object obj) { 59 if (this == obj) return true; if (obj = null) return false; if (getClass() != obj.getClass()) return false; Team other = (Team) obj; if (loss == null) { if (other.Loss != null) return false; } else if (!loss.equals(other. loss)) return false; if (name = null) { if (other.name != null) 73 } else 14 (!name.equals(other.name)) return false; if (wins - null) { 77 if (other.wins l= null) return falses } else if (wins.equals(other.wins)) return false; return true; 60 61 62 63 64 65 66 67 68 69 70 71 72 74 75 76 78 79 80 81 82 83 84 85} 86 } Declaration R Problems Javadoc O errors, 3 warnings, others Description Warnings (3 items) Resource I Path Location Type

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+1. What is the average age of members of your key public? tep

Answered: 1 week ago

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago

Question

2. Discuss the types of messages that are communicated nonverbally.

Answered: 1 week ago