Results 1 to 4 of 4
  1. #1
    chrisLU5 is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default Need help with loop!!

    Hi my tutor set me a task to complete, basically i need my program here to loop back to the optionSelected part of my code, i know how to write to it counts the vote ect, i just need to know how to loop the whole sequence so it doesn't just close when a user votes for a team....

    Java Code:
    import Barnfield.Dialogs;
    class VoteSystem {
    	public static void main (String args[]) {
    		int optionSelected;
    		double total;
    		Vote question1 = new Vote();
    		Vote question2 = new Vote();
    		question2.setQuestion("Bayern Munich");
    		Vote question3 = new Vote();
    		Vote question4 = new Vote();
    		optionSelected = Dialogs.integerInput("Select: \n 1: View \n 2: Vote \n 3:Exit");
    		if (optionSelected > 3){
    			Dialogs.errorMessage("You entered a wrong number");
    		if (optionSelected == 1){
    			Dialogs.outputMessage("The current score is ");
    		if (optionSelected == 2){
    			optionSelected = Dialogs.integerInput("Enter a number for the following answers: \n 1: Arsenal \n 2: Bayern Munich \n 3: Chelsea \n 4: Fenebarche");
    		if (optionSelected == 1)
    			Dialogs.outputMessage("You Voted For :" + " " + question1.getQuestion());
    		if (optionSelected == 2)
    			Dialogs.outputMessage("You Voted For :" + " " + question2.getQuestion());
    		if (optionSelected == 3)
    			Dialogs.outputMessage("You Voted For :" + " " + question3.getQuestion());
    		if (optionSelected == 4)
    			Dialogs.outputMessage("You Voted For :" + " " + question4.getQuestion());
    		if (optionSelected > 4){
    			Dialogs.errorMessage("You entered a wrong number");
    		if (optionSelected == 3){
    			Dialogs.outputMessage("Program Closing");
    Many Thanks Chris

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    Do you understand the three types of loops? Do ... While, while, and for.

    Do while ensures that the loop body is performed at least once
    Java Code:
      Something fun
    }while(condition is true);
    While is good for looping x times, where x is unknown
    Java Code:
    while(condition is true){
      Do something less fun
    A for loop is good for doing something x times, where x is known
    Java Code:
    for(int i = 0; condition is true; i++){
      Do something more fun
    The oracle tutorials have more detailed explanations of all three. Which loop you need is upmto what you want, all three loops can function the same way.
    Last edited by sunde887; 04-24-2011 at 04:17 PM.

  3. #3
    chrisLU5 is offline Member
    Join Date
    Apr 2011
    Rep Power


    I dont understand them fully, i just need a starting point, i don't understand that when option 2 is selected and the user votes for a team how to return back to the main menu to select option 1 to view the score?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

Similar Threads

  1. JTextField loop 2x for-loop WEIRD!
    By Streetproject in forum AWT / Swing
    Replies: 2
    Last Post: 02-16-2011, 06:46 PM
  2. [Q] Loop issue (while loop)
    By iriscience in forum New To Java
    Replies: 9
    Last Post: 01-31-2011, 05:21 PM
  3. Convert do while loop to for loop
    By sandeeptheviper in forum New To Java
    Replies: 3
    Last Post: 01-03-2011, 01:37 PM
  4. Replies: 5
    Last Post: 04-30-2010, 06:05 PM
  5. while-loop stopping on first loop
    By davester in forum New To Java
    Replies: 6
    Last Post: 06-26-2009, 09:46 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