Original Post
Hey, I have recently posting a bunch of threads pretty much just asking for you guys to tell me how to fix my problems and I'm sorry for it. I hate to ask for this again, because I feel that I am a nuisance but here I go. The program that I have been writing and have tons and tons of problems on is almost done, i think :S. I know my formatting is wrong but I can't see how wrong it is because nothing will print. I have no idea why it wont print, I've tried contacting other friends who know JAVA but can't get a hold of anyone so I came to this resort. I hope someone can figure out this problem and once again I understand if anyone doesn't want to help me. My (rough) code is: Like i said earlier, this code is completely a rough sketch haha. I know my formatting is wrong, but i think my logic is right? It might not be but All i need to know is why its not printing out. I can figure everything else out on my own. Once again im sorry and I thank you all for the help!
import java.util.*;
public class Election
{
static Scanner console = new Scanner(System.in);
static String[] names = new String[5];
static int[] votes = new int[5];
static double[] percents = new double[5];
public static void main(String[] args)
{
String winner;
inputC();
percent();
winner = winner();
print(winner);
}
System.exit(0);
//create void method to input names and scores into two separate arrays
public static void inputC()
{
String name;
int vote;
//get the names and votes
for (int i = 0; i < names.length; i++)
{
System.out.print("Please enter the candidates last name: ");
name = console.next();
names = name;
System.out.print("Please enter the candidates total votes: ");
vote = console.nextInt();
votes = vote;
}
}
//create method that calculates the percent of votes recieved
public static void percent()
{
int count = 0;
int sum = 0;
//find the total sum
while(count < votes.length)
sum = sum + votes[count];
count++;
//find the average
while (count < percents[count])
{
percents[count] = votes[count]/sum;
count++;
}
}
//create a method that finds the winner by total votes
public static String winner()
{
int winnerInt;
int maxIndex = 0;
for (int index = 1; index < votes.length; index++)
if (votes[maxIndex] < votes[index])
maxIndex = index;
//winnerInt = votes[maxIndex];
return names[maxIndex];
}
//create a method that prints out the data in a format as shown on pg. 620, problem 7.
public static void print(String win)
{
System.out.printf("%2d%n", "Candidate" + "Votes Received" + "% of Total Votes");
for (int w = 0; w < names.length; w++)
{
System.out.printf("%2d%n", names[w] + votes[w] + percents[w]);
}
}
}