Issuing random numbers

Guys please please can somebody help me out, I?m having a problem with my java programme,
My programme issues out seats in a theatre, I have two arrays working in my script, the first is Economy and the Second is Gallery
The first user prompt of the programme is to select where you would like to sit in the theatre. E for Economy, and G for Gallery.
Once this selection is made a random seat number from either the Economy array or Gallery array is printed out depending on where the user chose to sit.
because its a theatre and only one seat can be issued to one person at any one time thus I cant have an array element printed out more than once,
Is there a way of removing deleting or conditioning an array element so that it can not be used again through the duration of the programme?
Or possible is there a simpler method of achieving this.
any advice will be brilliant
this is how my code appears
import java.util.Scanner;
* Write a description of class SquareCube here.
* @author (your name)
* @version (a version number or a date)
import java.util.Scanner;
import java.util.Random;
import java.util.ArrayList;
public class BookingTickets
public static void main (String [] args)
Scanner myScanner = new Scanner(System.in);
double Price = 0.00;
String SeatArea;
int Count;
int[] SeatNumberEconomy1 = {1,2,3,4,5,6,7,8,9,10};
int[] SeatNumberGallery = {11,12,13,14,15};
int NumberSelectorEconomy;
int NumberSelectorGallery;
ArrayList SeatNumberEconomy = new ArrayList(10);
NumberSelectorEconomy = (int)(java.lang.Math.random()*10);
NumberSelectorGallery = (int)(java.lang.Math.random()*10);
for (Count = 0; Count <=14; Count++)
System.out.println ("Please select where you would prefer to sit");
System.out.println ("Input (E) for Economy and (G) for Gallery;- ");
SeatArea = myScanner.next();
if (SeatArea.equalsIgnoreCase("E"))
SeatArea = ("Economy");
Price = 10.00;
System.out.println (" ");
System.out.println ("You have Selected...");
System.out.println (SeatArea + " Priced at ?" + Price + " per ticket");
System.out.println ("Your Seat Number is;- " + SeatNumberEconomy[NumberSelectorEconomy]);
System.out.println (" ");
if (SeatArea.equalsIgnoreCase("G"))
SeatArea = ("Gallery");
Price = 20.00;
System.out.println (" ");
System.out.println ("You have Selected...");
System.out.println (SeatArea + " Priced at ?" + Price + " per ticket");
System.out.println ("Your Seat Number is;- " + SeatNumberGallery[NumberSelectorGallery]);
System.out.println (" ");
System.out.println (" ");
System.out.println("Sorry All Seats have been Booked, Please try again tomorrow");
System.out.println (" ");
}

kilessi wrote:
That sounds great, the numberes i will need to pull out of the bag, as such, will always be 1 to 15.1) Create the Set to hold the seats
2) Iterate from 1 to 15 and add each one to the set.
>
though i need them to be pulled out in random order it is however imperitive that the same number is not pulled out twice, since im trying to find a method of booking out seats in a theatre it wouldnt make sence.which is why I say use a Set not a Bag.
>
if you could help with this it would be a great burden lifted off my soulders, Help - yes. Provide code for you to submit as your homework - no!

Similar Messages

  • Problem with Purchase Order creation with Random numbers .

    Hi Experts
    Currently i am facing an issue with Bapi BAPI_PO_CREATE1 to create Purchase order with random numbers for example items 1, 3,5.
    Please let me know the settings .
    Thanks in Advance

    Hi Neha,
    A reset of the release strategy only takes place if
    -  the changeability of the release indicator is set to '4' in
       case of a purchase requisition and '4' or '6' in case of
       another purchasing document (purchase order, request for
       quotation, contract, scheduling agreement),
    -  the document is still subject to the previous release
       strategy,
    -  the new TOTAL NET ORDER VALUE is higher than the old one.
    The total net order value is linked to CEKKO-GNETW for a purchase order,
    CEBAN-GSWRT for a purchase requisition item-wise release and CEBAN-GFWRT
    for a purchase requisition overall release.
    If you have maintained a Tolerance for value changes during release
    (V_161S-TLFAE), the release strategy is reset when the value of the
    document is higher than the percentage you have specified and if the
    document is still subject to the previous release strategy.
    Review the SAP note 365604 and 493900 for more
    information about Release strategy.
    Regards,
    Ashwini.

  • Hi, I have an iPhone 4 which rings people when it is locked, whether or not in my pocket.  I always lock it when not using it.  Can anyone help? It is calling random numbers, not the last person or anyone even recently called on my recents list. Thanks

    Hi, I have an iPhone 4 which rings people when it is locked, whether or not in my pocket.  I always lock it when not using it.  Can anyone help? It is calling random numbers, not the last person or anyone even recently called on my recents list. Thanks

    Pay no attention to iinami, the amount of replies to people saying their handsets must have been jailbroken everytime iTunes throws out an error is tremendous. (Clearly you don't need to have any real knowledge to get to level 3 on these forums, let's hope apple's geniuses know a lot more than some of their customers.)
    http://support.apple.com/kb/TS3694
    Solution below.
    Error 9
    This error occurs when the device unexpectedly loses its USB connection with iTunes. This can occur if the device is manually disconnected during the restore process. This issue can be resolved by performing USB troubleshooting, using a different USB dock-connector cable, trying another USB port, restoring on another computer, or by eliminating conflicts from third-party security software.

  • Generating random numbers, while excluding some numbers

    I want to generate random numbers between 1 and 13 (including 1 and 13), while excluding numbers 6 and 9
    Please tell me theres an easy fix to this issue --

    lemme know if it compiles
    import java.util.*;
    public class RandomNumber {
    public static void main( String[] args) {
    int numWins = 0;
    for( int i = 1; i < 101; i++) {
    boolean x = true, y = true;
    int number = 0;
    while(!x && !y && number != 6 && number != 9)
    number = 1 + (int) (Math.random() % 13);
    x = number >= 1;
    y = number <= 13;
    int number2 = 0;
    while(!x && !y && number2 != 6 && number2 != 9)
    number2 = 1 + (int) (Math.random() % 13);
    x = number2 >= 1;
    y = number2 <= 13;
    int number3 = 0;
    while(!x && !y && number3 != 6 && number3 != 9)
    number3 = 1 + (int) (Math.random() % 13);
    x = number3 >= 1;
    y = number3 <= 13;
    int number4 = 0;
    while(!x && !y && number4 != 6 && number4 != 9)
    number4 = 1 + (int) (Math.random() % 13);
    x = number4 >= 1;
    y = number4 <= 13;
    int DrawAgain = 2;
    if (number == DrawAgain) {
    System.out.println( "A Random number between 1 and 10: " + number);
    System.out.println( "A second Random number between 1 and 10: " + number2);
    if (number2 == 8) {
    System.out.println( " Piece made it home successfully");
    numWins++;
    if (number2 == DrawAgain) {
    System.out.println( "A third Random number between 1 and 10: " + number3);
    if (number2 == 7) {
    System.out.println( " Piece made it home successfully");
    numWins++;
    if (number3 == DrawAgain) {
    if (number4 == 7)
    System.out.println( " Piece made it home successfully");
    numWins++;
    else {
    System.out.println( "A Random number between 1 and 10: " + number);
    if (number == 10) {
    System.out.println( " Piece made it home successfully");
    numWins++;
    System.out.println(" Number of times piece made it home successfully " + numWins);
    }

  • My iPhone 5 types random letters and dials random numbers

    MY iPhone 5 types random letters and dials random numbers even when I am not holding the phone

    Hello diana239,
    If your iPhone is randomly accessing apps and dialing out, then take a look at the article below to troubleshoot issues with the display on your iPhone. 
    If the screen on your iPhone, iPad, or iPod touch doesn't respond to touch
    http://support.apple.com/en-us/HT201406
    Regards,
    -Norm G. 

  • Bips and random numbers while making calls

    When talking on the phone (iPhone 4 with iOS 6) I get beeping noises and random numbers generated at the top of the screen. Has anyone else encountered this? HELP!

    I'm having the same issue and it has just started after the recent OS update. I have a 5S. Hope there is a fix, as it is terribly annoying.

  • How to generate random numbers that doesnt contain characters?

    How do we generate random numbers in ESB ROuting Service/ XSL transformation that does not contain characters. I have been using "orcl:generate-guid()" , but it contains some characters, so, I substring it to get only numbers. I dont want to take this risk and in future, my substring itself may contain characters.
    Has anybdy tried this before?
    Thanks,

    If the goal is to have a pseudo random number then consider using the translate function to replace the occurances of the A - E characters with another digit. For example:
    translate(orcl:generate-guid(),'0123456789ABCDEF','0123456789123456')
    This will produce a 1 for A, 2 for B, etc. While not a valid hex to decimal conversion of the GUID value, it does get around the hex issue and might be sufficient for your purposes.
    I would perform a large sample test to see just how unique the values end up being.
    As for why hex is used, well GUID's are most commonly written in text as a sequence of hexadecimal digits such as: 3F2504E0-4F89-11D3-9A0C-0305E82C3301. i.e. 128 bits represented in 32 characters formatted into 5 sections.
    Hope this helps,
    Peter

  • Polymorphism and Random Numbers

    Im having issues correctly using random numbers in this program.All I want to do is: generate 4 random ints,and 3 random operators,then prints the results in a toString() method
    import java.util.Random;
    public class TestArithmetic2 {
        // evaluate (int / int) - (int * int)) = result
          //((8.0 / 8.0) - (2.0 * 5.0)) = -10.0
        public static void main(String[] args) {
            Node n = new RandomOps(
                new RandomOps(
                new RandomConst(), new RandomConst()),
                new RandomOps(new RandomConst(), new RandomConst()));
                   public Character RandomOperator(){
                        Random random = new Random();
                        //char array with characters
                        char[] chars = new char[]{'+','-','*','/'};
                        //Generate a random number
                        int r = randomChar.nextInt(chars.length);
                        //Get char at random index
                        char randomOps = chars[r];
                   public int RandomConstant(){
                        int randomConst = 1 + (int)(Math.random() * 20);
                   public String toString(){
                        return "(" + "(" + lChild.eval() + "-" + rChild.eval() + ")" + ")" + "=" n.eval();
            System.out.println(""+ n.eval());
    }

    Opps.Sorry.Here's everything that should help it compile.
    public class Node {
        public Node() {}
        public double eval() {
            System.out.println("Error: eval Node");
            return 0;
    import java.util.Random;
    public class TestArithmetic2 {
        // evaluate (int / int) - (int * int)) = result
          //((8.0 / 8.0) - (2.0 * 5.0)) = -10.0
        public static void main(String[] args) {
            Node n = new RandomOps(
                new RandomOps(
                new RandomConst(), new RandomConst()),
                new RandomOps(new RandomConst(), new RandomConst()));
                   public Character RandomOperator(){
                        Random random = new Random();
                        //char array with characters
                        char[] chars = new char[]{'+','-','*','/'};
                        //Generate a random number
                        int r = randomChar.nextInt(chars.length);
                        //Get char at random index
                        char randomOps = chars[r];
                   public int RandomConstant(){
                        int randomConst = 1 + (int)(Math.random() * 20);
                   public String toString(){
                        return "(" + "(" + lChild.eval() + "-" + rChild.eval() + ")" + ")" + "=" n.eval();
            System.out.println(""+ n.eval());
    public class Binop extends Node {
        protected Node lChild, rChild;
        public Binop(Node l, Node r) {
             lChild = l; rChild = r;
    }

  • 3G S dialing random numbers

    I searched and searched and can't find a conclusive answer to the issue I am having.
    Every two weeks or so, my 3G S gets busy...
    There are two symptoms:
    1. When I dial out a number, a second, random number is dialled (and registered as an outgoing call) and a phone, somewhere rings. I can talk to the person I actually dialled, the other person just hears a quiet hum.
    2. While off, it dials random numbers in quick succession. Usually it picks two numbers from the "Recent" list and rings them. Yesterday it rang a friend of mine 3 times. After the first call was hung up by my friend, his phone rang instantly - he refused this time just to have the phone ring again (which he answered). Another person had 3 phone calls from me at around 20 minutes intervals.
    A few days ago, I pulled my phone from my pocket, turned it on, just to see the green bar up top saying "... to return to the call..." - the phone was happily recording a voice message on my work colleague answering service.
    And yes, the phone is turned off after every use, not rattled about in my pockets while on etc.
    I did a reset, a reset with data deleted, restore, everything I could think of.
    Any thoughts (on the subject) would be appreciated.
    cheers

    I've seen this behavior before, & the only time I could successfully trace the cause, was to a bluetooth headset, still turned on & placed in a purse where the movement was randomly pressing the last number dialed button, thus causing the phone of course to place a call. If you don't have any active bluetooth headsets in the vicinity & bluetooth is in fact turned OFF on your phone, the only thing I can suggest is to restore your phone as a "new" device in itunes & then re-sync your itunes content. If the issue persists after doing that, an appointment at an Apple store for a replacement would be in order.

  • I am trying to generate an array of 30 random numbers. after every 5 readings a new vi should open and tell the user that 5 readings has been completed. and again carry on with the generation of array.

    since i do not have a transducer now, i am currently generating an array of 30 random numbers. after every 5 readings a warning should be given to the user that 5 readngs are complete. this cycle should repeat. the array size is 30.
    please help me out,  waiting for reply asap.
    once i have the transducer, i will be taking 30 analog samples and then after every 5 smaples that wraning will be displaye din a new VI
    Solved!
    Go to Solution.

    Use a while loop with a time delay representing your sampling period.
    Use the count terminal to check if equals 4, so 4th iteration=5th sample.
    Use a case structure. The true case will only be executed on the 4th iteration.
    In the true case place a subVI  with your desired message in the front panel. Go to the VI properties window and set "open front panel when called".
    The closing condition of the warnign is not giving in your description.
    Consider that rather than usign a subvi for this, you could use the "One/Two/Three button dialog" or "display message" vis at the "dialog and user interface" pallete.
    Please give it a try and send your own VI. Do not expect us to provide a working solution.
    Regards,

  • How can you generate Multiple random numbers from 1 to 49?

    I am very new at programming with the iPhone SDK and I need some help with a project I am working on. What I want to do is set up a window with 6 labels and 1 button. When the user clicks the button, the program will populate 6 randomized numbers each ranging from 1 to 49, and then place each of 6 numbers in a label. But each time the program ends and starts again the numbers cannot be the same, and also when the user clicks the button, no label can have the same number twice, so for example. If label 1 had the number 10, the other 5 labels cannot have that number until the button is clicked again. I know how to set up the interface, I just need the code. I would so greatly appreciate someone's help in this matter. I have been trying to do this for days and I cannot figure it out. Possibly someone who knows tons about Objective C programming can help me!
    Thank-you so very much!!

    I see that you're writing a lottery number generator. Perhaps the easiest way to do it is to emulate a real lottery: fill an array (NSMutableArray, probably) with the numbers between 1 and 49, pick one at random, remove that number from the array, and repeat. (You can think of the numbers as being the balls and the array as being the machine that pops them out.)
    One simple way to get the random indices needed is to extract six random bytes from Randomization Services using SecRandomCopyBytes, then loop over them, using the modulo operator (%) to select an index within the size of the array.
    And no, I'm not going to write your code for you. If I was going to do that, I could package and sell the app myself.

  • I need help with this program ( Calculating Pi using random numbers)

    hi
    please understand that I am not trying to ask anymore to do this hw for me. I am new to java and working on the assignment. below is the specification of this program:
    Calculate PI using Random Numbers
    In geometry the ratio of the circumference of a circle to its diameter is known as �. The value of � can be estimated from an infinite series of the form:
    � / 4 = 1 - (1/3) + (1/5) - (1/7) + (1/9) - (1/11) + ...
    There is another novel approach to calculate �. Imagine that you have a dart board that is 2 units square. It inscribes a circle of unit radius. The center of the circle coincides with the center of the square. Now imagine that you throw darts at that dart board randomly. Then the ratio of the number of darts that fall within the circle to the total number of darts thrown is the same as the ratio of the area of the circle to the area of the square dart board. The area of a circle with unit radius is just � square unit. The area of the dart board is 4 square units. The ratio of the area of the circle to the area of the square is � / 4.
    To simuluate the throwing of darts we will use a random number generator. The Math class has a random() method that can be used. This method returns random numbers between 0.0 (inclusive) to 1.0 (exclusive). There is an even better random number generator that is provided the Random class. We will first create a Random object called randomGen. This random number generator needs a seed to get started. We will read the time from the System clock and use that as our seed.
    Random randomGen = new Random ( System.currentTimeMillis() );
    Imagine that the square dart board has a coordinate system attached to it. The upper right corner has coordinates ( 1.0, 1.0) and the lower left corner has coordinates ( -1.0, -1.0 ). It has sides that are 2 units long and its center (as well as the center of the inscribed circle) is at the origin.
    A random point inside the dart board can be specified by its x and y coordinates. These values are generated using the random number generator. There is a method nextDouble() that will return a double between 0.0 (inclusive) and 1.0 (exclusive). But we need random numbers between -1.0 and +1.0. The way we achieve that is:
    double xPos = (randomGen.nextDouble()) * 2 - 1.0;
    double yPos = (randomGen.nextDouble()) * 2 - 1.0;
    To determine if a point is inside the circle its distance from the center of the circle must be less than the radius of the circle. The distance of a point with coordinates ( xPos, yPos ) from the center is Math.sqrt ( xPos * xPos + yPos * yPos ). The radius of the circle is 1 unit.
    The class that you will be writing will be called CalculatePI. It will have the following structure:
    import java.util.*;
    public class CalculatePI
    public static boolean isInside ( double xPos, double yPos )
    public static double computePI ( int numThrows )
    public static void main ( String[] args )
    In your method main() you want to experiment and see if the accuracy of PI increases with the number of throws on the dartboard. You will compare your result with the value given by Math.PI. The quantity Difference in the output is your calculated value of PI minus Math.PI. Use the following number of throws to run your experiment - 100, 1000, 10,000, and 100,000. You will call the method computePI() with these numbers as input parameters. Your output will be of the following form:
    Computation of PI using Random Numbers
    Number of throws = 100, Computed PI = ..., Difference = ...
    Number of throws = 1000, Computed PI = ..., Difference = ...
    Number of throws = 10000, Computed PI = ..., Difference = ...
    Number of throws = 100000, Computed PI = ..., Difference = ...
    * Difference = Computed PI - Math.PI
    In the method computePI() you will simulate the throw of a dart by generating random numbers for the x and y coordinates. You will call the method isInside() to determine if the point is inside the circle or not. This you will do as many times as specified by the number of throws. You will keep a count of the number of times a dart landed inside the circle. That figure divided by the total number of throws is the ratio � / 4. The method computePI() will return the computed value of PI.
    and below is what i have so far:
    import java.util.*;
    public class CalculatePI
      public static boolean isInside ( double xPos, double yPos )
         double distance = Math.sqrt( xPos * xPos + yPos * yPos );        
      public static double computePI ( int numThrows )
        Random randomGen = new Random ( System.currentTimeMillis() );
        double xPos = (randomGen.nextDouble()) * 2 - 1.0;
        double yPos = (randomGen.nextDouble()) * 2 - 1.0;
        int hits = 0;
        int darts = 0;
        int i = 0;
        int areaSquare = 4 ;
        while (i <= numThrows)
            if (distance< 1)
                hits = hits + 1;
            if (distance <= areaSquare)
                darts = darts + 1;
            double PI = 4 * ( hits / darts );       
            i = i+1;
      public static void main ( String[] args )
        Scanner sc = new Scanner (System.in);
        System.out.print ("Enter number of throws:");
        int numThrows = sc.nextInt();
        double Difference = PI - Math.PI;
        System.out.println ("Number of throws = " + numThrows + ", Computed PI = " + PI + ", Difference = " + difference );       
    }when I tried to compile it says "cannot find variable 'distance' " in the while loop. but i thought i already declare that variable in the above method. Please give me some ideas to solve this problem and please check my program to see if there is any other mistakes.
    Thanks a lot.

    You've declared a local variable, distance, in the method isInside(). The scope of this variable is limited to the method in which it is declared. There is no declaration for distance in computePI() and that is why the compiler gives you an error.
    I won't check your entire program but I did notice that isInside() is declared to be a boolean method but doesn't return anything, let alone a boolean value. In fact, it doesn't even compute a boolean value.

  • Program to create random numbers in plsql

    How do we Write a program to create random numbers.
    Thanks

    No need to - we have DBMS_RANDOM :)

  • HELPwith array of random numbers!!!

    can anyone please write up a program that uses an array of random numbers from 0-100 and sort them out...
    if anyone can help me that would be great...i tried but i cannot figure it out...
    please just write the program so I just have to copy and paste :)

    This has to be the most asked question here, or at least it's way up there with classpath and path questions.
    Use the search feature to search the forum for random number generation and I swear you'll find more answers and code than you could possibly want.
    Good luck
    Lee

  • Can't validate outlook on iPad - random numbers and letters don't display - only a question mark in a blue box

    If I have to validate Outlook on PC or Mac - I have no problem - the random numbers and letters display fine - but if I am requested to validate outlook before sending a mail when using my iPad, the operation fails as the test numbers and letters are not shown - only a snap blue box with a question mark.  How do I convert the box into the image of a new validation code?  Thanks in advance.

    Hello,
    The question mark means it can't find it where it was when you put it in the Dock.
    I'd get EasyFind...
    http://www.macupdate.com/info.php/id/11076
    Use it to search your whole drive for Files & Folders, case insensitive & show invisibles...
    Complete
    That will show any with that word in the name at all.

Maybe you are looking for