Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Primary Election program

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Primary Election program

    hello i am trying to got this program i am doing for school to work. i have tried like 50 different things and can not get it to work. i am very frustrated is anyone could help me!


    The output needs to look like this:


    Candidate Votes Percentage
    Aubrey 616618 49.71%
    Martinez 623926 50.29%
    TOTAL VOTES 1240544 100.00%

    THIS IS WHAT I HAVE (its a mess)

    //Katherine Brewer
    // December 12, 2012
    //PrimaryElection

    import java.util.Scanner; //Brings in a libary that is needed for the Scanner class
    import java.text.*;
    public class PrimaryElection
    {
    static public void customFormat (String pattern, double value )
    {
    DecimalFormat myFormatter = new DecimalFormat(pattern);
    String output = myFormatter.format(value);
    System.out.println(output);
    }

    public static void main(String[]arge)
    {
    int nya; //New york votes
    int nym; //New your votes
    int nja; //New jersey votes
    int njm; //New jersey votes
    int ca; //Connecticut votes
    int cm; //Connecticut votes
    double totalsAubrey; //Total aurbrey
    double totalsMartinez; //Total Martinez
    double totals; //Total
    double PercentagesAubrey; //Percents
    double PercentagesMartinez; //Percents
    double TotalPercentages; //Percents
    Scanner keyboard=new Scanner(System.in);

    //Get votes for Aubrey and Martinez in New york.
    System.out.print(" election results for New York?");
    System.out.println();
    System.out.println("Aubrey:");
    nya=keyboard.nextInt();
    System.out.println();
    System.out.println("Martinez:");
    nym=keyboard.nextInt();
    System.out.println();

    //Get votes for Aubrey and Martinez in New Jersey.
    System.out.print("election results in New Jersey?");
    System.out.println();
    System.out.println("Aubrey:");
    nja=keyboard.nextInt();
    System.out.println("Martinez:");
    njm=keyboard.nextInt();
    System.out.println();

    //Get votes for Aubrey and Martinez in Connecticut.
    System.out.print(" election results in Connecticut?");
    System.out.println();
    System.out.println("Aubrey:");
    ca=keyboard.nextInt();
    System.out.println("Martinez:");
    cm=keyboard.nextInt();
    System.out.println();

    //Total votes for Aubrey
    totalsAubrey = nya + nja + ca;
    //Total votes for Martinez
    totalsMartinez = nym + njm + cm;


    //Display the resulting information.
    System.out.println("Totals");
    totals = nya + nja + ca + nym + njm + cm;

    System.out.println("TotalPercentages");


    System.out.print(nya + nja + ca);
    System.out.print(nym + njm +cm);
    System.out.print("TOTAL VOTES");
    System.out.print(totalsAubrey + totalsMartinez);

    //int at = (totalsAubrey/totals);
    //int mt = (totalsMartinez/totals);
    //customFormat("##.#",at);

    System.out.print("Percentages Aubrey");
    System.out.print("Percentages Martinez");



    }
    }




    System.out.println("Canidate" + " " + "Votes" + " " + "Percentage");
    System.out.println();
    System.out.println("Aubrey" + " " + totalsAubrey PercentagesAubrey);
    System.out.println();
    System.out.println("Martinez" + " " + totalsMartinez PercentagesMartinez);
    System.out.println();
    System.out.printf("TOTAL VOTES" + " " + total TotalPercentages);


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Primary Election program

    Can you explain what the problem is? If there are errors, copy the full text and paste it here.

    One problem I see with what you posted is the end of the code is missing.

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Beginner Assignment help, election simulation
    By YellowDinosaur in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 23rd, 2012, 03:35 PM
  2. Jpa Primary key generation
    By rdheepan in forum JDBC & Databases
    Replies: 5
    Last Post: December 13th, 2011, 03:44 AM
  3. auto-increment of primary key
    By hundu in forum Enterprise JavaBeans
    Replies: 1
    Last Post: May 15th, 2010, 10:55 AM
  4. Election Java Problem
    By ronz in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 13th, 2009, 04:30 PM
  5. Java program for election voting machine
    By bruint in forum File I/O & Other I/O Streams
    Replies: 15
    Last Post: May 20th, 2009, 10:07 PM