I am trying to use a 2D array to store voting data, and use a one dimensional array to store names of candidates, names of subdivisions, and hold the total amount of votes for candidates and subs. From the main method i need initialize these arrays using initialization lists: 2D array with all the voting data (but not the totals), candidate names, subdivision names then calculate the total votes for each candidate and subdivision then print out the results
I have began to create the methods needed in order to initialize and fill the arrays, but i am stuck on what i need to do in order to continue
{
private static int[][] Data;
private static String[] names;
private static String[] SubDivs;
private static int[] totalvoteCand;
private static int[] totalvoteSub;
// method to initialize data array
public static void InitData()
{
int[][] tempData = {{600, 800, 800, 800},
{700, 700, 700, 900},
{800, 700, 800, 700},
{400, 450, 300, 1300},
{900, 900, 900, 1000}};
Data = tempData;
String[] tempNames = { {Audrey, Brian, Elizabeth, Peter, Zachary} };
tempNames = names;
String[] tempSub = { {Aberdeen, Brock, Sahali, Valleyview} };
tempSub = SubDivs;
}// end of init
//*************************************************************//
public static void calcCandVotes() // calculates candidate votes
{
totalvoteCand = new int[data[0].length];
int tempTotal;
for(int i = 0; i<data.length;i++) {
tempTotal = 0;
for(x = 0; x<data[0].length;x++){
tempTotal += tempTotal + data[i][x];
}
totalVoteCand[i] = tempTotal;
}
}//end of calc cand
//*************************************************************//
public static void calcSubVotes() // calculates subdivision votes
{
totalvoteSub = new int[data[0].length];
int tempTotal;
for(int i = 0; i<data[0].length; i++) {
tempTotal = 0;
for(x = 0; x<data.length; x++){
tempTotal += tempTotal + data[x][i];
}
totalvoteSub[x] = tempTotal;
}
}// end of calc sub ******************************************//
public static void printArray() // print method, hopefully.
{
for(int i = 0; i<data.length;i++)
{
for (int x=0; x<data[0].length;x++)
System.out.print(Data[i][x] + "\t");
System.out.println();
}
}
//***************************end of print array****************************************