I have to calcualte a total score for a bowling game here is the code for my class
I cant figure out what is wrong, its something with the loop I think, basically its supposed to track score for every player and keep a running total output sample
/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template */
package cis.entity;
import cis.util.CisUtility;
import java.util.Scanner;
/**
*
* @author mm
*/
public class Game {
private static final int NUMBER_OF_ENDS = 10;
private static final int NUMBER_OF_PLAYERS = 4;
private static final String[] player = new String[NUMBER_OF_PLAYERS];
private static final int[][] scores = new int[NUMBER_OF_PLAYERS][NUMBER_OF_ENDS];
int[] totals = new int[NUMBER_OF_PLAYERS];
public void addPlayer() {
for (int counter = 0; counter < player.length; counter++) {
player[counter] = CisUtility.getInputString("Enter name of player #" + (counter + 1));
}
}
public void addScores() {
for (int endIndex = 0; endIndex < NUMBER_OF_ENDS; endIndex++) {
for (int playerIndex = 0; playerIndex < player.length; playerIndex++) {
scores[playerIndex][endIndex] = CisUtility.getInputInt("Enter score number " + (endIndex + 1) + " score for " + player[playerIndex] + "---->");
showScores();
}
}
}
public void showScores() {
System.out.println("Player \tEnd #1 \tEnd #2 \tEnd #3 \tEnd #4 \tEnd #5\tEnd #6 \tEnd #7 \tEnd #8 \tEnd #9 \tEnd #10 \tTotals");
for (int playerIndex = 0; playerIndex < NUMBER_OF_PLAYERS; playerIndex++) {
System.out.print(player[playerIndex] + "\t");
for (int endIndex = 0; endIndex < NUMBER_OF_ENDS; endIndex++) {
System.out.print(scores[playerIndex][endIndex] + "\t" + totals[0]);
}
System.out.println("\n");
}
}
public void calculateTotal() {
for (int playerIndex = 0; playerIndex < NUMBER_OF_PLAYERS; playerIndex++) {
for (int endIndex = 0; endIndex < NUMBER_OF_ENDS; endIndex++) {
totals[0] += scores[playerIndex][endIndex];
}
}
}
}