ssd3:Practical Quiz 2 Debugging Class DNASequence
来源:互联网 发布:java打开jdk api 编辑:程序博客网 时间:2024/06/06 10:47
/**
* This class represents a DNA sequence of nucleotides 'A', 'T', 'C' and 'G'
* as a sequence of characters in a {@link String} object.
*
* @author author name
* @version 1.0.0
*/
public class DNASequence {
/* Contains the sequence of nucleotides. */
private String sequence;
/* Contains the number of nucleotide A */
private int numberOfA;
/* Contains the number of nucleotide T */
private int numberOfT;
/* Contains the number of nucleotide C */
private int numberOfC;
/* Contains the number of nucleotide G */
private int numberOfG;
/**
* Test driver for class <code>DNA</code>.
*
* @param args not used.
*/
public static void main(String[] args) {
String s = "ATTATCGGGGTAA";
DNASequence dnaSequence = new DNASequence(s);
if ((dnaSequence.getNumberOfA() == 4)
&& (dnaSequence.getNumberOfT() == 4)
&& (dnaSequence.getNumberOfC() == 1)
&& (dnaSequence.getNumberOfG() == 4)) {
System.out.println("Test case 1: get methods passed/n");
} else {
System.out.println("Test case 1: get methods failed !!!/n");
}
if (dnaSequence.twoConsecutive('T')) {
System.out.println("Test case 2: method twoConsecutive passed/n");
} else {
System.out.println(
"Test case 2: method twoConsecutive failed !!!/n");
}
if (dnaSequence.twoConsecutive('A')) {
System.out.println("Test case 3: method twoConsecutive passed/n");
} else {
System.out.println(
"Test case 3: method twoConsecutive failed !!!/n");
}
if (!dnaSequence.twoConsecutive('C')) {
System.out.println("Test case 4: method twoConsecutive passed/n");
} else {
System.out.println(
"Test case 4: method twoConsecutive failed !!!/n");
}
}
/**
* Constructs a <code>DNASequence</code> object that represents the sequence
* of nucleotides indicated by the chars in the <code>string</code> argument
* and counts the occurrences of each nucleotide in the sequence.
*
* @param initialSequence a string with the initial sequence of nucleotides.
*/
public DNASequence(String initialSequence) {
sequence = initialSequence;
countNucleotides();
}
/*
* Counts the occurrences of each nucleotide in the DNA sequence and then
* updates the values of the variables numberOfA, numberOfT, numberOfC, and
* numberOfG .
*/
private void countNucleotides() {
/* int numberOfA = 0;
int numberOfT = 0;
int numberOfC = 0;
int numberOfG = 0; */
numberOfA = 0;
numberOfT = 0;
numberOfC = 0;
numberOfG = 0;
int index = 0;
while (index < sequence.length()) {
char nucleotide = sequence.charAt(index);
if (nucleotide == 'A') {
numberOfA++;
} else if (nucleotide == 'T') {
numberOfT++;
} else if (nucleotide == 'C') {
numberOfC++;
}/* else if (nucleotide == 'G') {
numberOfC++;
} */
else if (nucleotide == 'G') {
numberOfG++;
}
index++;
}
return;
}
/**
* Obtains the number of occurrences of nucleotide A in the sequence.
*
* @return the number of occurrences of nucleotide A.
*/
public int getNumberOfA( ) {
return numberOfA;
}
/**
* Obtains the number of occurrences of nucleotide T in the sequence.
*
* @return the number of occurrences of nucleotide T.
*/
public int getNumberOfT( ) {
return numberOfT;
}
/**
* Obtains the number of occurrences of nucleotide C in the sequence.
*
* @return the number of occurrences of nucleotide C.
*/
public int getNumberOfC( ) {
return numberOfC;
}
/**
* Obtains the number of occurrences of nucleotide G in the sequence.
*
* @return the number of occurrences of nucleotide G.
*/
public int getNumberOfG( ) {
return numberOfG;
}
/**
* Checks if the nucleotide specified by the argument occurs in two
* consecutive locations in the DNA sequence.
*
* @param input a <code>char</code> that represent the nucleotide.
* @return <code>true</code> if the specified nucleotide occurs two
* consecutive locations in the sequence.
* Returns <code>false</code> otherwise.
*/
public boolean twoConsecutive(char input) {
int index = 1;
/* while (index < sequence.length() - 1) { */
while (index < sequence.length()) {
int indexOfFirstNucleotide = index - 1;
char firstNucleotide = sequence.charAt(indexOfFirstNucleotide);
char secondNucleotide = sequence.charAt(index);
/* if ((firstNucleotide == input) || (secondNucleotide == input)) {
return true;
} */
if ((firstNucleotide == input) && (secondNucleotide == input)) {
return true;
}
index++;
}
return false;
}
}
考察:
对程序进行调试。
调试的快捷操作:F5 起调试
F9 设断点
F10 断点处开始调试 跳过函数
F11 进入函数内部
- ssd3:Practical Quiz 2 Debugging Class DNASequence
- ssd3:Practical Quiz 1 SecondsCalculator
- ssd3:Practical Quiz 1 iCarnegie Information
- ssd3 Multiple-Choice Quiz 2
- SSD3 Multiple-Choice Quiz 1
- SSD3 Multiple-Choice Quiz 3
- SSD3 : Multiple-Choice Quiz 4
- ssd3 Multiple-Choice Quiz 1
- SSD 3 Practical Quiz 2 答案
- DNASequence
- SSD 3 Practical Quiz 1 答案
- Debugging the Development Process: Practical Strategies
- Inside Class Loaders: Debugging
- NSHipster Quiz #2
- SSD3-Quiz1
- SSD3-Quiz5
- SSD3-exercise1
- SSD3-EXAM1
- 微软一站式示例代码浏览器 第二版 CTP发布
- 有关项目管理的飞鸽传书2007官网
- ShellExecute与组件的注册
- 我有一个幸福的家
- returnValue的理解
- ssd3:Practical Quiz 2 Debugging Class DNASequence
- 基于ASP.NET Web Application的插件动态编译反射实现,附DEMO
- pietty中文乱码问题解决
- [C#学习笔记]C#继承知识总结
- ural 1038 Spell Checker
- 言寡尤,行寡悔,禄在其中矣。
- 恒心
- instanceof和typeof都能用来判断一个变量是否为空或是什么类型的变量。
- 感受母爱