Results 1 to 3 of 3
  1. #1
    l jsym l is offline Member
    Join Date
    Nov 2009
    Rep Power

    Default Need Help in a java program

    What im trying to do is create a program that reads users names and their total votes...the problem i am having thats its not actually printing any of the stuff that I really want it to so i'm really confused....

    Their also might be other logic wrong with it, i am new at JAVA programming and hope to get better!

    If you can help me at all please let me know

    import java.util.*;

    public class Election
    static Scanner console = new Scanner(;

    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;
    String output;

    winner = winner();


    //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 =;
    names[i] = name;

    System.out.print("Please enter the candidates total votes: ");
    vote = console.nextInt();
    votes[i] = 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];

    //find the average
    while (count < percents[count])
    percents[count] = votes[count]/sum;


    //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]);


    I dont know how to do the code boxes for this forum website because im new and couldnt find it in the faq....sorry for the long post :S

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Rep Power


    Put System.out.printlns at critical points in your program to see the values of the variables and the execution paths that your program is taking. System.out.println saves lives.

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Rep Power


    another suggestion.u put what u want to do exactly in paper.

    Then translate the above as a code.

    no exit conditions in ur code...just put comments on what u want to do above all methods.
    Last edited by RamyaSivakanth; 11-04-2009 at 12:23 PM.

Similar Threads

  1. execute java program within java program
    By popey in forum New To Java
    Replies: 2
    Last Post: 10-22-2009, 05:32 PM
  2. Need to run a java program within a java program
    By peterdfl in forum New To Java
    Replies: 2
    Last Post: 12-11-2008, 07:44 AM
  3. Java Program for doing FTP
    By Rajesh_J2EE in forum New To Java
    Replies: 1
    Last Post: 12-06-2008, 03:35 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts