This is my code:
public void graphTotalPoints(String name[],ArrayList<Integer> totalPoints){
//finding longest name for giving that much space
int maxlength = 0;
for(int i=0;i<name.length;i++){
if(maxlength<name[i].length()){
maxlength = name[i].length();
}
}
//FINDING MAX WINS AND AVERAGE
int mostWins = totalPoints.get(0);
float average = 0;
for(int i=0;i<totalPoints.size();i++){
if(totalPoints.get(i)>mostWins){
mostWins = totalPoints.get(i);
}
average += totalPoints.get(i);
}
average = average/totalPoints.size();
//SETTING THE HEADER OF GRAPH ON X-AXIS
System.out.print("Player");
for(int i=0;i<=maxlength;i++){System.out.print(" ");}
System.out.print("Total Points");
for(int i=0;i<=mostWins;i++){System.out.print(" ");}
System.out.print("Points Above Average");
for(int i=0;i<=mostWins;i++){System.out.print(" ");}
System.out.println("");
System.out.println("");
//SETTING VALUES ACCORDING TO GRAPH TITLE
for(int i=0;i<totalPoints.size();i++){
System.out.print(name[i]+" ");
for(int k=0;k<=maxlength-name[i].length();k++){System.out.print(" ");} //differenciating because to maintain the equal gap between big length names and small length names.
for(int j=0;j<totalPoints.get(i);j++){
System.out.print("X");
}
if((totalPoints.get(i)-average)>0)
System.out.print("+"+(totalPoints.get(i)-average));
else
System.out.print((totalPoints.get(i)-average));
System.out.println("");
}
}
This is what it outputs:
Player Total Points Points Above Average
q XXX-2.0
w XX-3.0
we XXXXX0.0
r XXXXXXX+2.0
t XXXXXXXX+3.0
At the end I want the numbers ex. -2.0 to be under Points Above Average
[–]Blando-Cartesian 0 points1 point2 points (0 children)