Answered step by step
Verified Expert Solution
Question
1 Approved Answer
NAStrand ( Abstract Class ) [ 3 6 marks ] This class represents an NA strand; it is abstract because we don t know which
NAStrand Abstract Class marks
This class represents an NA strand; it is abstract because we dont know which bases a strand allows unless we know whether it is RNA or DNA. However, a lot of the behaviour of an NAStrand can be implemented without knowing the exact bases. Your task is to fill in the constructors and methods according to the specifications below, using implementations based on those discussed in lecture. The provided implementations are incorrect, but should be enough to compile and run the failing local and autograder tests.
Fields
char bases The allowable bases for this strand.
char a Array to store the sequence of bases in the strand.
int n The number of bases in the strand.
int j Starting index of the NAStrand in the array.
Constructor
NAStrandchar bases
Initializes the array and other fields.
Abstract Methods
public abstract boolean isPairchar x char y
Returns whether x and y are considered a base pair for the respective subclass.
Methods
public char getBases
Returns the allowable bases.
public boolean isBasechar x
Returns whether or not character x is a valid base for this strand.
If youve implemented getBases and isBase, you should pass the local and autograder tests.
public void addint i char x throws IllegalArgumentException, IndexOutOfBoundsException
Adds the base x at index i in the strand.
Throws an IndexOutOfBoundsException if the index is out of bounds.
Throws an IllegalArgumentException if the base is not valid.
public void addchar x throws IllegalArgumentException
Adds the base x to the end of the strand.
Throws an IllegalArgumentException if the base is not valid.
public char getint i throws IndexOutOfBoundsException
Returns the base at the specified index i in the strand.
Throws an IndexOutOfBoundsException if the index is out of bounds.
If youve implemented add and get, you should pass some local and autograder tests.
public int size
Returns the number of bases in the strand.
public void clear
Clears the strand so that it has no bases.
If youve implemented size and clear, you should pass some local and autograder tests.
public char setint i char x throws IllegalArgumentException, IndexOutOfBoundsException
Sets the base at index i in the strand to x
Returns the value originally at index i in the strand.
Throws an IndexOutOfBoundsException if the index is out of bounds.
Throws an IllegalArgumentException if the base is not valid.
public char removeint i throws IndexOutOfBoundsException
Removes and returns the base at the specified index i in the strand.
Throws an IndexOutOfBoundsException if the index is out of bounds
If youve implemented remove and set, you should pass some local and autograder tests.
public void spliceInint i NAStrand q throws IllegalArgumentException, IndexOutOfBoundsException
Splices another NAStrand q into this strand at the specified index i
Throws an IndexOutOfBoundsException if the index is out of bounds.
Throws an IllegalArgumentException if this and q are not the same type.
public void reverseint i int k throws IndexOutOfBoundsException
Reverses the bases in the NAStrand from index i to index kinclusive
Throws an IndexOutOfBoundsException if either index is out of bounds.
Throws an IndexOutOfBoundsException if k i
Finally, you should test spliceIn and reverse both locally and on the autograder.
Desired Complexity
marks
method
time complexity
extra space complexity
constructor
O
O
getBases
O
O
isBase
O
O
addx
OA
Oresize
addix
Omini niA
Oresize
geti
O
O
size
O
O
clear
O
O
setix
O
O
removei
Omini niA
Oresize
spliceIni q
Omini ninqA
Oresize
reverseik
Oki
O
Examples
RNA.getBases
DNA.getBasesx
ACGUother order ok
ACGTother order ok
x
RNA.isBasex
DNA.isBasex
x
RNA.isBasex
DNA.isBasex
U
true
false
T
false
true
A
true
true
C
true
true
NAStrand
method
output
NAStrand post
addA
A
A
addC
AC
AC
addB
IllegalArgumentException
AC
addG
IndexOutOfBoundsException
AC
addB
IndexOutOfBoundsException
AC
get
A
AC
AC
get
IndexOutOfBoundsException
C G G A
size
C G G A
size
C G G A
clear
NAStrand
method
output
NAStrand post
A
setC
A
C
AG
setC
G
AC
AC
setB
IllegalArgumentException
AC
setG
IndexOutOfBoundsException
AC
setB
IndexOutOfBoundsException
AC
remove
C
A
A
remove
IndexOutOfBoundsException
remove
IndexOutOfBoundsException
NAStrand
method
NAStrand post
n
nq
AAG
spliceCG
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started