Java hw Create a Poll

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • audiokarate
    New Member
    • Sep 2007
    • 16

    #1

    Java hw Create a Poll

    Alright this is my hw problem. I am a newb with java and I am having a hard time coding. This is the problem and at the bottom is what I have so far. Any pointers in the right direction is greatly appreciated.



    When launched, your program will allow multiple voters to pick the presidential candidate of their choice. The program will tally the votes and determine which one is the winner. Note that output to the screen should reflect double spaces after all periods.

    The first input screen will look like this:

    2008 NATIONAL PRESIDENTIAL STRAW POLL

    1. Hillary Clinton (D)
    2. John Edwards (D)
    3. Rudy Giuliani (R)
    4. John McCain (R)
    5. Barack Obama (D)
    6. Mitt Romney (R)
    7. Fred Thompson (R)

    Who is your top choice for President in 2008?

    This is the output screen after every vote.

    Thank you! Your vote has been recorded.

    Enter 'P' to proceed with the next voter.
    Enter 'E' to exit and show the poll results.

    The results will look something like this:

    The winner of the 2008 National Presidential Straw Poll
    is show the name of the candidate in all CAPS.

    1. Hillary Clinton (D) 140
    2. John Edwards (D) 90
    3. Rudy Giuliani (R) 70
    4. John McCain (R) 60
    5. Barack Obama (D) 130
    6. Mitt Romney (R) 80
    7. Fred Thompson (R) 60


    --------------------------------------------------------------------------------------------------------------------
    I am lost and I dont even know if this is right.

    import staugIO.StaugIO ;
    public class RamosEPA3
    {//BEGIN RamosEPA3
    public static void main(String[] args)
    {//BEGIN main


    class Election2008
    {//BEGIN Election2008 class

    //DEFINE VARIABLES AND OBJECTS
    private int choice = 0;
    private int choice1 = 0;
    private int choice2 = 0;
    private int choice3 = 0;
    private int choice4 = 0;
    private int choice5 = 0;
    private int choice6 = 0;
    private int choice7 = 0;
    private int max_vote = 0;
    private String candidateName = " ";
    private char answer = 'P';
    private StaugIO io = new StaugIO();


    //Election2008 CONSTRUCTOR METHOD
    public Election2008()
    {
    }//END Election2008


    //beginVote METHOD
    public void beginVote()
    {
    }//END beginVote



    public void getVote()
    {


    do {

    switch(choice)
    {
    case 1: candidateName = "Hillary Clinton (D)";

    break;
    case 2: candidateName = "John Edwards (D)";

    break;
    case 3: candidateName = "Rudy Giuliani (R)";

    break;
    case 4: candidateName = "John McCain (R)";

    break;
    case 5: candidateName = "Barack Obama (D)";

    break;
    case 6: candidateName = "Mitt Romney (R)";

    break;
    case 7: candidateName = "Fred Thompson (R)";
    tallyVote()
    break;
    default: io.writeInfo("I nvalid choice!");
    io.writeInfo("D o you want to try again?\n\n");



    System.out.prin tln("Enter 'P' to proceed or 'E' to exit: ");

    }//END switch/case
    }
    }//END getVote()
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by audiokarate
    Alright this is my hw problem. I am a newb with java and I am having a hard time coding. This is the problem and at the bottom is what I have so far. Any pointers in the right direction is greatly appreciated.



    When launched, your program will allow multiple voters to pick the presidential candidate of their choice. The program will tally the votes and determine which one is the winner. Note that output to the screen should reflect double spaces after all periods.

    The first input screen will look like this:

    2008 NATIONAL PRESIDENTIAL STRAW POLL

    1. Hillary Clinton (D)
    2. John Edwards (D)
    3. Rudy Giuliani (R)
    4. John McCain (R)
    5. Barack Obama (D)
    6. Mitt Romney (R)
    7. Fred Thompson (R)

    Who is your top choice for President in 2008?

    This is the output screen after every vote.

    Thank you! Your vote has been recorded.

    Enter 'P' to proceed with the next voter.
    Enter 'E' to exit and show the poll results.

    The results will look something like this:

    The winner of the 2008 National Presidential Straw Poll
    is show the name of the candidate in all CAPS.

    1. Hillary Clinton (D) 140
    2. John Edwards (D) 90
    3. Rudy Giuliani (R) 70
    4. John McCain (R) 60
    5. Barack Obama (D) 130
    6. Mitt Romney (R) 80
    7. Fred Thompson (R) 60


    --------------------------------------------------------------------------------------------------------------------
    I am lost and I dont even know if this is right.

    import staugIO.StaugIO ;
    public class RamosEPA3
    {//BEGIN RamosEPA3
    public static void main(String[] args)
    {//BEGIN main


    class Election2008
    {//BEGIN Election2008 class

    //DEFINE VARIABLES AND OBJECTS
    private int choice = 0;
    private int choice1 = 0;
    private int choice2 = 0;
    private int choice3 = 0;
    private int choice4 = 0;
    private int choice5 = 0;
    private int choice6 = 0;
    private int choice7 = 0;
    private int max_vote = 0;
    private String candidateName = " ";
    private char answer = 'P';
    private StaugIO io = new StaugIO();


    //Election2008 CONSTRUCTOR METHOD
    public Election2008()
    {
    }//END Election2008


    //beginVote METHOD
    public void beginVote()
    {
    }//END beginVote



    public void getVote()
    {


    do {

    switch(choice)
    {
    case 1: candidateName = "Hillary Clinton (D)";

    break;
    case 2: candidateName = "John Edwards (D)";

    break;
    case 3: candidateName = "Rudy Giuliani (R)";

    break;
    case 4: candidateName = "John McCain (R)";

    break;
    case 5: candidateName = "Barack Obama (D)";

    break;
    case 6: candidateName = "Mitt Romney (R)";

    break;
    case 7: candidateName = "Fred Thompson (R)";
    tallyVote()
    break;
    default: io.writeInfo("I nvalid choice!");
    io.writeInfo("D o you want to try again?\n\n");



    System.out.prin tln("Enter 'P' to proceed or 'E' to exit: ");

    }//END switch/case
    }
    }//END getVote()
    1.) Use code tags if you have to post code.
    2.) Why don't you go through a basics tutorial first. Read about how to use the Scanner to take user's input and how to use while loops.

    Comment

    Working...