I am working on the following Java application

Write a program that allows the user to enter the last names of five candidates in a local election and the votes received by each candidate. The program should then output each candidate’s name, the votes received by that candidate, and the percentage of the total votes received by the candidate.<< so far my program can do this<<

if the user enters a last name in small letters the program should display the surname with the first character in capitals <<< im really not sure how to do this on this program,please help<<<..

this is the code so far:

import java.util.*;
import java.text.NumberFormat;

public class Election

{

public static void main(String[] args)
{
String[] names = {args[0],args[2],args[4],args[6],args[8]};

int[] votes = {(integer.getInteger(args[1]).intValue()),(integer.getInteger(args[3]).intValue()),
(integer.getInteger(args[5]).intValue()), (integer.getInteger(args[7]).intValue()),
(integer.getInteger(args[9]).intValue())};

String winner = "";
int winnerVotes = 0;
int totalVotes = 0;

for(int j = 0; j < votes.length; j++);
{
totalVotes += votes[j];
}

NumberFormat formatter = NumberFormat.getNumberInstance();
formatter.setMinimumIntegerDigits(1);
formatter.setMaximumFractionDigits(2);

System.out.println("\nCandidate Votes Received % of Total Votes");
System.out.println("--------- --------------- ---------------");

for(int j = 0; j<names.length; j++)
{
if (votes[j] > winnerVotes)
{
winner = names[j];
winnerVotes = votes[j];
}

System.out.println(
                  names[j] + "\t\t"
          + (int)votes[j] + "\t\t"
                  + (formatter.format(
                  ( (double)votes[j] / totalVotes )*100)));
}

System.out.println("Total " + totalVotes);
System.out.println("The winner of the election is " + winner);
}
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

You might consider:
a) Sticking with the thread that you already started for this: http://www.daniweb.com/forums/thread212868.html

You didn't bother to inquire further about anything mentioned in that thread. Show some consideration on the matter.

b) Using code tags when you post code so it doesn't come out one big left-aligned wall of text.

Edited 3 Years Ago by happygeek: fixed formatting

Comments
seconded.

OK, i didnt really look at your code to much, but this is what you need to do. You need to break the string up into char's using this method: getChars(). Store this in an array list. You should then find then store this in an ArrayList. Then you need to make the 0 array a capital using toUpper(). Then find the array value that is equal to a whitespace and then make that value + 1 toUpper() to make that in capitals as well. If you want more help or me to actually code it for you, just ask :)

There is absolutely no need to create a separate array list just to convert a character or two to uppercase.

you would create an arraylist because, you dont know how long the names would be to start of with. Plus with arraylists you can easily convert char's because all you want to do is convert two. Then you print the arraylist. If you wanted you could do a 5 dimensional arraylist for the 5 names. Its a very simple option that will solve your problem.

OK, i didnt really look at your code to much, but this is what you need to do. You need to break the string up into char's using this method: getChars(). Store this in an array list. You should then find then store this in an ArrayList. Then you need to make the 0 array a capital using toUpper(). Then find the array value that is equal to a whitespace and then make that value + 1 toUpper() to make that in capitals as well. If you want more help or me to actually code it for you, just ask :)

Thank you so much. i kind of get what i need to do but not really sure how to..soo please please if you could code it for me , i would really appreciate it :)...

Coding your homework for you is not the purpose of this forum and jakx12 should not be offering to do so. That is entirely against the spirit of these forums.

you would create an arraylist because, you dont know how long the names would be to start of with. Plus with arraylists you can easily convert char's because all you want to do is convert two. Then you print the arraylist. If you wanted you could do a 5 dimensional arraylist for the 5 names. Its a very simple option that will solve your problem.

I am still saying that there is no need for an ArrayList. All you need is a couple of methods from the String class.

Thank you so much. i kind of get what i need to do but not really sure how to..soo please please if you could code it for me , i would really appreciate it :)...

Read these two methods:
String.substring(int,int)
String.toUpperCase()
The burden is on you to make an effort and ask questions about what you don't understand and what you have tried.

ezza is right, it would be better if you code it yourself. How about you try and then you show us what you have done, if it does not work then tell me and ill actually do it for you. But its better to try.

This article has been dead for over six months. Start a new discussion instead.