I have an arrayList of objects called Gear. Each object has attributes of String Name, String Type, Int rateOfFire and Int Damage. I also have a function that calculates damage per second (DPS) for each weapon by multiplying damage by rateOfFire. The problem I'm having is that this function prints off the damage of each weapon in a list, but i would also like the total DPS of all weapons in the list.
This is my method:
public static void getDPS()
{
for (int i = 0; i < Gear.size(); i++)
{
int damage = Gear.get(i).damage;
int fireRate = Gear.get(i).fireRate;
int DPS =(damage*fireRate)/60;
System.out.println("DPS for weapon " + i+1 + " is: " +DPS);
System.out.println("Total DPS= " );
}
}
And this is my output:
DPS for weapon 01 is: 10
Total DPS=
DPS for weapon 11 is: 12
Total DPS=
Any advice would be greatly appreciated as I am only a novice to programming!
"..." + i+1 + "..."into"..." + (i+1) + "...": without the parenthesis since the operators have the same order of precedence,"..."+iis applied first, and the1is concatenated as string after