dimanche 31 janvier 2016

Need to include the sum of participation

I am using Math.random to include participation of students from a group (separate class). I successfully created the output, but now need to know how to show the sum of participation of students within the group.

public class student  
{
String firstName; 
String lastName; 
String participation;  

student (String a, String b, String p) 
{ 
firstName = a; 
lastName = b; 
participation = p; 
} 
String getName() 
{ 
return firstName + " " + lastName + " " + participation; 
} 
String whatsUp()
{
double r;
int myNumber;
String participation="";
r = Math.random();
myNumber = (int) (r * 3.0)+1;

switch(myNumber)
{
case 1:
participation = "participation is " + Math.floor((Math.random() 
* 10) + 1);
break;
case 2:
participation = "participation is " + Math.floor((Math.random() 
* 10) + 1);
break;
case 3:
participation = "participation is " + Math.floor((Math.random() 
* 10) + 1);
break;
}

return participation;
}
} 




Aucun commentaire:

Enregistrer un commentaire