标题:Debug java代码
取消只看楼主
ddww11
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-3
 问题点数:0 回复次数:1 
Debug java代码
/**
 * 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  {
    private String  sequence;
    private int numberOfA;
    private int numberOfT;
    private int numberOfC;
    private int numberOfG;
    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");
        }
               
    }
    public  DNASequence(String initialSequence)  {

        sequence = initialSequence;
        countNucleotides();
    }
    private void  countNucleotides()  {
        int numberOfA = 0;
        int numberOfT = 0;
        int numberOfC = 0;
        int 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++;
            }
            index++;
        }
        return;
    }
    public int  getNumberOfA( )  {
        return numberOfA;
    }
    public int  getNumberOfT( )  {
        return numberOfT;
    }
    public int  getNumberOfC( )  {
        return numberOfC;
    }
    public int  getNumberOfG( )  {
        return numberOfG;
    }
    public boolean  twoConsecutive(char input)  {
        int index = 1;
        while (index < sequence.length() - 1) {
            int indexOfFirstNucleotide = index - 1;
            char firstNucleotide = sequence.charAt(indexOfFirstNucleotide);
            char secondNucleotide = sequence.charAt(index);
            if ((firstNucleotide == input) || (secondNucleotide == input)) {
                return true;
            }
            index++;
        }
        return false;
    }
}


第一次接触debug,实在不知道代码里面的bug在哪,只看出结果是错误的。麻烦各位指点一下。
搜索更多相关主题的帖子: java Debug 代码 
2008-10-03 20:44
ddww11
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-10-3
得分:0 
回复 2# guoxhvip 的帖子
就是还不会这些啊,正在学……
可以先告诉一下bug是什么吗?
2008-10-04 12:32



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-236266-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.505224 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved