use math.random to generate license plate numbers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ard9232
    New Member
    • Jul 2008
    • 1

    use math.random to generate license plate numbers

    I"m really really confused on how to do this problem. I need to use math.random and type-casting to print out 20 license plates but I'm just really lost. Can anyone help me out?


    Use Java’s type-casting mechanism to write a program that prints 20
    “random” license plate numbers, each one consisting of three randomly-
    chosen digits followed by three randomly chosen upper-case letters. The
    first digit cannot be zero.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Start by writing down your algorithm then.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      The Random class has a bit more convenient methods than the Math class
      but it doesn't matter much; try to come up with a way to generate a number in
      the interval [n,m) and most of the job is done.

      kind regards,

      Jos

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Another hint: one way to choose a character from a sequence of characters is to start with a String containing those characters and then randomly select the index of a character in that string:
        [CODE=Java]
        String vowels = "aeiouy";
        int index = ...
        char selected = ...
        [/CODE]

        Comment

        • Gangreen
          New Member
          • Feb 2008
          • 98

          #5
          also add your already generated plates to an arraylist, and check with each new plate it doesn't already exists, so you're sure you won't have two identical plates.

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by Gangreen
            also add your already generated plates to an arraylist, and check with each new plate it doesn't already exists, so you're sure you won't have two identical plates.
            Better add them to a Set then ...

            kind regards,

            Jos

            Comment

            Working...