a Create a new Java class that represents a nucleotide one o
a. Create a new Java class that represents a nucleotide, one of the basic building blocks of life. Your nucleotide class should have the following properties:
i. A base, which is a single character that must be either \'a\', \'c\', \'g\', \'t\', or \'n\'.
ii. A boolean flag which indicates if the nucleotide is degenerate.
You must write a constructor that initializes both properties and accessor methods. If the base character that is passed to your constructor is not one of the four characters listed above, then you should default to \'n\'. No methods other than the constructor are required.
b. Using your nucleotide object, create a new Java class that represents a bacteria. An instance of bacteria consists of a genome (a collection of nucleotides), and a species (a String).
You must create a constructor which accepts a String and a collection, and uses those to initialize the species and the collection of nucleotides.
Your bacteria class should also have one instance method:
1. Bacteria binaryFission(): performs a deep copy of the instance and returns a new instance of Bacteria.
Solution
public class Nucleotide {
private static final char[] NUCLEOTIDE_BASE = {\'a\', \'c\', \'g\', \'t\', \'n\'};
// Instance variables
private char base;
private boolean isDegenerate;
/**
* Constructor
* @param base
* @param isDegenerate
*/
public Nucleotide(char base, boolean isDegenerate) {
if (String.valueOf(NUCLEOTIDE_BASE).contains(String.valueOf(base)))
this.base = base;
else
this.base = NUCLEOTIDE_BASE[4];
this.isDegenerate = isDegenerate;
}
/**
* @return the base
*/
public char getBase() {
return base;
}
/**
* @return the isDegenerate
*/
public boolean isDegenerate() {
return isDegenerate;
}
}
import java.util.ArrayList;
import java.util.List;
public class Bacteria {
// Instance variables
private List<Nucleotide> genome;
private String species;
/**
* Default Constructor
*/
public Bacteria() {
this.genome = null;
this.species = null;
}
/**
* Constructor
*
* @param genome
* @param species
*/
public Bacteria(List<Nucleotide> genome, String species) {
this.genome = genome;
this.species = species;
}
/**
* Performs a deep copy of the instance and returns a new instance of
* Bacteria
*
* @return
*/
public Bacteria binaryFission() {
Bacteria newBacteria = new Bacteria();
List<Nucleotide> newList = new ArrayList<Nucleotide>();
for (int i = 0; i < this.genome.size(); i++) {
newList.add(i, this.genome.get(i));
}
newBacteria.genome = newList;
newBacteria.species = this.species;
return newBacteria;
}
}

