类的对象不会保存私有char数组的更改

我必须写一个类,它由字母A,C,G和T的基因组组成。首先,必须在公共基因组中随机创建一个序列(整数长度)。然后,在“删除”方法中,必须删除基因组的随机选择的特征。现在的问题是我的对象g1无法保存此过程的结果。因此,如果我将“ actTGC”作为基因组,则相同的基因组将继续作为输出输出(尽管事实是,保存了所有这些字母的char Array已被更改),而没有被更改。不幸的是,我只能使用这些方法。我不允许创建其他方法(如二传手)。您能帮我一下,告诉我如何在我的对象中保存新序列。

我的JavaScript:

import java.util.Arrays;
public class Genom {

    //length of genome
    private int length = 0;

    //Sequence of aminoacids
    private char[] aminoAcids;

    //vocabulary
    static final char[] ALPHABET = {'A','C','G','T'};  
    /**
     * Construction of the genome 
     */
     public Genom(int length) {        

        this.length = length;
        aminoAcids = new char[length];        
        int zufall = 0;
        for(int i = 0; i < length; i++){
            zufall = Random.generateRandomInt(4);
            aminoAcids[i] = ALPHABET[zufall];                      
        }     
    }
    public char[] getaASequence() {       
        return aminoAcids;
    }
    public int getLength() {        
        return this.length;        
    }
    //returns sequence as a string
    public String toString() {        

        StringBuffer b = new StringBuffer();
        char [] aminoAcids = getaASequence();
        //int length = getLength();
        for(int i = 0; i < aminoAcids.length; i++){
            b.append(aminoAcids[i]);           
        }
        String s = b.toString();
        return s;
    }
    public void deletion() {
        char [] aminoAcids = getaASequence();
        int length = getLength();
        char [] deletedAcid = new char [aminoAcids.length - 1];
        int random = Random.generateRandomInt(aminoAcids.length - 1);        
        int count = 0;
        for(int i = 0; i < aminoAcids.length; i++){
            if(i == random){
                count = count - 1;
            }else{
                deletedAcid[count] = aminoAcids[i]; 
            }
            count++;
        }       
        aminoAcids = new char[deletedAcid.length];
        for(int i = 0; i < deletedAcid.length; i++){
            aminoAcids[i] = deletedAcid[i];
        }
    }
    public static void main(String[] args) {        
        Genom g1 = new Genom(5);        
        g1.deletion();
    }
chenzhaoxia 回答:类的对象不会保存私有char数组的更改

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3167023.html

大家都在问