I have writen a code for adding (math +) two arrays. Actually, I have two arrays of a class I have also designed, that has two attributess, one of wich is an integer.
I would like to sum (add element by element) one array on the other by adding the integer attribute of each element to the integer attribute of the other element.
I have a compiling time error that says "unexpected type" in the line I mark with an "<==="
Here is my code:
package practica_2010;
package practica_2010;
/**
* Write a description of class PAGS here.
*
* @author (your name)
* @version (a version number or a date)
*/
//Name I will give to the statistics array's position, so that I can refer them to as "this.statsArray[TRESES]++" whithout needing to
//remember exactly wich was the apropriate index to store the number of digit 3 I have encountered so far
public class statIndex // continene los nombres que van a tener las distintas posiciones o elementos del array de estadísticas.
// static para que sean públicamente visibles sin necesitar instanciar una clase statIndex
// final para que no se creen instancias.
{
public final static int CARACTERES = 0; // characthers. they go in the position 0 of the array
public final static int LETRAS = 1; // letters
public final static int VOCALES = 2; // vowels
public final static int CONSONANTES = 3; // consonnants
public final static int SIMBOLOS = 4; // symbols
public final static int DIGITOS = 5; // digits
public final static int UNOS = 6; // 1s
public final static int DOSES = 7; // 2s
public final static int TRESES = 8; // 3s
public final static int CUATROS = 9; // 4s
public final static int CINCOS = 10;
public final static int SEIS = 11;
public final static int SIETES = 12;
public final static int OCHOS = 13;
public final static int NUEVES = 14;
public final static int CEROS = 15;
public final static int AES = 16; //As, Bs, Cs... Xs, Ys, Zs...
public final static int BES = 17;
public final static int CES = 18;
public final static int DES = 19;
public final static int ES = 20;
public final static int EFES = 21;
public final static int GES = 22;
public final static int HACHES = 23;
public final static int IES = 24;
public final static int JOTAS = 25;
public final static int KAS = 26;
public final static int ELES = 27;
public final static int EMES = 28;
public final static int ENES = 29;
public final static int EÑES = 30;
public final static int OES = 31;
public final static int PES = 32;
public final static int QUES = 33;
public final static int ERRES = 34;
public final static int ESES = 35;
public final static int TES = 36;
public final static int UES = 37;
public final static int UVES = 38;
public final static int DOBLEUVES = 39;
public final static int EQUIS = 40;
public final static int YES = 41;
public final static int ZETAS = 42;
public final static int FPAL = 43;
public final static int FFRAS = 44;
public final static int FPAR = 45;
public final static int FPAG = 46;
public final static int FDL = 47;
public final static int PALABRAS = 48;
public final static int NUMEROS = 49;
public final static int FRASES = 50;
public final static int PARRAFOS = 51;
public final static int PAGINAS = 52;
// public final static int BASICOS = 53;
// public final static int BASICOS = 54;
// public final static int BASICOS = 55;
// public final static int BASICOS = 56;
// public final static int BASICOS = 57;
// public final static int BASICOS = 58;
}
// somebody has suggested that I use a Map, instead of so many constants... in where I have something like 1 corresponds to LETRAS (spanish for letters)
/**
* statItem is a class for storing values of a magnitude statistics: "CHARACTERS: 50" meanning that there are 50 characters.
* It has two values, String and integer, so that the first value matches one of the statIndex (see below) values
* This class is to make objects that forms the Array of statistics of each complex element. Thus, to print statistics of such complex objects, an
* iterator would print statItem.magnitud+" "+statItem.valor. To access a certain magnitude, we use the statIndex constants on the arraylist of statItems
* Each elementoCompuesto object, has this kind of arraylist, statsArray estadisticas. statsArray is an arraylist<statItems>, so, estadisticas[SIMBOLOS] should yield
* a statITem object's reference whose elements can be accessed (estadisticas[SIMBOLOS].getMagnitud is the string "Simbolos")
*/
public class statItem {
private String magnitud;
private Integer valor;
// method to set both values
public void set(String magn, Integer cantidad){
this.magnitud=magn;
this.valor=cantidad;
}
//method to set magnitud
public void set(String magn){
this.magnitud=magn; }
//method to set valor
public void set(Integer cantidad){
this.valor=cantidad;}
//method to give magnitud
public String getMagnitud(){
return this.magnitud;}
//method to give valor
public Integer getValor(){
return this.valor;}
}
/**
* Array de 52 elementos de tipo statItem, que guarda las estadísticas de cada elemento complejo.
*
* @author (your name)
* @version (a version number or a date)
*/
public class statsArray
{
// instance variables - replace the example below with your own
private statItem [] statVect;
/**
* Constructor for objects of class statsArray
*/
public statsArray()
{
statVect = new statItem[52];
}
public void addStats (statItem [] otroVect){
for (int i=0; i<this.statVect.length;i++){
this.statVect[i].getValor()+=otroVect[i].getValor(); //<===
}
}
}