4
In my main
I’m calling the method stats
:
user.stats(ctr);
The method stats
in itself:
public void stats (int num)
{
int i;
float total=0, perc;
for (i=0;i<num;i++)
{
total = total + sensors[i].statistics.getTotalConsumption(sensors[i].statistics.data[]);
}
}
The class users
:
public class Users implements IUsers{
protected int id;
protected String name;
protected int age;
protected String email;
protected String phone;
protected Sensors sensors[] = new Sensors[10];
float cost;
float goal;
public Users()
{
}
public void stats (int num)
{
int i;
float total=0, perc;
for (i=0;i<num;i++)
{
total = total + sensors[i].statistics.getTotalConsumption(sensors[i].statistics.data[]);
}
}
}
The main
:
public class UserTest
{
public static void main ( String args[] )
{
int id, rg, cpf, cnpj, num, age, ctr=0;
String name, name2, description, description2, email, phone, c, g, sex;
Sensors sensors[];
float cost, goal;
Users user = new Users();
while (ctr!=num)
{
user.sensors[ctr] = new Sensors();
name2 = JOptionPane.showInputDialog("Nome do aparelho ligado ao sensor");
description = JOptionPane.showInputDialog ("Localização do aparelho");
user.sensors[ctr].setNome(name2);
user.sensors[ctr].setDescription(description);
ctr++;
}
/*exibir estatísticas*/
user.stats(ctr);
}
}
But both in the method call and in the assignment of the total variable, is giving the error illegal start of expression
. If anyone can help I’m grateful.
Where and how the declaration of
sensors
?– ramaral
See if you’re using the words
public
orprivate
within one method or if you are declaring one method within another.– ramaral
protected Sensors Sensors[] = new Sensors[10];
– poirot
This statement is being made where? Check my second comment.
– ramaral
this statement is within the Users class, as well as the Stats method
– poirot
post your main and the class that contains the Stats method so that it is better to identify what is happening.
– Dener
ready, updated
– poirot
was just a glitch in copying time
– poirot