Assignment J3
- Complete the development of class Strand.java.
Our .class version of Strand was used in assignment J2.
- File Strand.java defines an instance variable
and three methods for you. DO NOT CHANGE THEM OR ADD ANY OTHER instance
variables
- The methods we designed and implemented are
- public Object clone()
- Return a new duplicate of the Strand object.
- Java requires that the clone() return type be Object.
Because every Java class is an extension (specialization) of Object,
the clone() method can return a Strand object.
- String casting: produce a string representation of the strand
- public String toString()
- Return a string representation of the Strand object.
- Splicing: Modify a strand by appending another strand to it.
- public void splice(Strand otherStrand)
- Updates the Strand object so that it represents the
concatenation of its previous representation with the nucleotide sequence
of otherStrand.
The methods we chose to implement should provide insight on how you can
implement the other methods.
- You are to design and implement the following methods.
- Construction: build a Strand by either default or specific
construction
- public Strand()
- Configure the newly created Strand object to represent an empty
nucleotide sequence.
- public Strand(String s)
- Configure the newly created Strand object to represent the
nucleotide sequence denoted by string s.
- Slicing: Remove a nucleotide subsequence from a strand.
- public Strand slice(int i1, int i2)
- Updates the Strand object by deleting the nucleotide
subsequence beginning at i1 and ending at i2-1.
- The method returns a representation of the deleted nucleotide
subsequence.
- Duplication: Produce a new copy of a strand. In Java parlance, this
behavior is referred to as cloning. Given the genetic information being
represented, the name is very apropos.
- Analysis: Report whether a strand contains a particular nucleotide
sequence; report the nucleotide at a particular location; and report the
nucleotide sequence at a particular sequence of strand locations.
- public int has(Strand s)
- Returns the index of the first occurrence of nucleotide sequence s in
the Strand object. If the object does not contain sequence s, then -1 is
returned,
- public Strand substrand(int i1)
- Returns the nucleotide in the Strand object with index i1.
- public Strand substrand(int i1, int i2)
- Returns the nucleotide sequence corresponding to the subsequence in
the Strand object starting with index i1 and ending with index i2-1.
Several of the methods that you must develop currently have a dummy
placeholder statement in them. The placeholders allow the class to successfully
compile. A placeholder is to be removed after you have added your code. For
example, here is the listing for one substrand() methods as given in
Strand.java.
public Strand substrand(int i) {
// TO BE COMPLETED *********
return null; // delete this line after you have written the
method
}
Because substrand() is suppose to return a Strand, the method would not
compile without some sort of return value. The dummy return provides that value.
For your information here are our implementations of toString(), splice(),
and clone()
// toString(): return String representation of the object
public String toString() {
String result = "< " + this.nucleotideSequence + " >";
return result;
}
// splice(): append the Strand with another strand
public void splice(Strand otherStrand) {
// determine the concatenation components
String leading = this.nucleotideSequence;
String trailing = otherStrand.nucleotideSequence;
// update strand to be a concatenation
this.nucleotideSequence = leading + trailing;
}
// clone(): duplicate the existing strand
public Object clone() {
// duplicate the sequence
String duplicateSequence = new String(nucleotideSequence);
// return a new Strand using the duplication
Strand result = new Strand(duplicateSequence);
return result;
}