Results 1 to 5 of 5
  1. #1
    511prs is offline Member
    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Default How to repeat a command

    Hi I made this little program but at the end of it the no of hrs can't be <= 0 or decimal numbers, the no of hrs is given by the user so If the user introduce -8 hrs i want the program to repeat from the beginning asking the user to intoduce the nom of hours


    import javax.swing.JOptionPane;

    public class park {

    public static void main (String[] args)

    {
    //declaration
    double numDesHrs = 0f;
    int tHrs = 5;
    int uHrs = 1;
    int journee = 12;
    int charge = 0;
    int dias = 0;

    numDesHrs = Double.parseDouble(JOptionPane.showInputDialog(nul l,"Entrez le Numero des Heures"));

    //calcul

    if (numDesHrs < 24) {

    charge = (int) ((numDesHrs - 3) + 5) ;

    JOptionPane.showMessageDialog(null, "Vous avez laisé votre voiture " + numDesHrs+"heures, et vous devez payer" + charge+"$");
    }
    else if (numDesHrs >= 24) {

    dias = (int) (numDesHrs/24);
    charge = (int) ((dias*12) + (numDesHrs - dias * 24));

    JOptionPane.showMessageDialog(null, "Vous avez laisé votre voiture " + numDesHrs+"heures, et vous devez payer" + charge+"$");

    } // here is my problem
    else if (numDesHrs <= 0){

    }
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default Re: How to repeat a command

    You need to loop.
    Something along the lines of:
    Java Code:
    while (not valid)
        Ask user for input.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    511prs is offline Member
    Join Date
    Aug 2012
    Posts
    6
    Rep Power
    0

    Default Re: How to repeat a command

    where should I put that in my code ?

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: How to repeat a command

    BB Code List - Java Programming Forum

    And Java has statements. Not commands.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

Similar Threads

  1. nextInt() repeat
    By trishtren in forum New To Java
    Replies: 3
    Last Post: 10-09-2011, 06:20 PM
  2. how to repeat a task again after it has been done
    By eyal3400 in forum New To Java
    Replies: 2
    Last Post: 07-19-2011, 11:03 PM
  3. how to repeat my method?
    By poupas in forum New To Java
    Replies: 6
    Last Post: 11-20-2010, 06:29 PM
  4. turning off key-repeat
    By gib65 in forum Advanced Java
    Replies: 4
    Last Post: 08-25-2010, 02:58 PM
  5. Help with a repeat
    By leeavital in forum New To Java
    Replies: 1
    Last Post: 01-01-2010, 09:42 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
  •