Quantcast
Channel: Why is my if statement not working? - Stack Overflow
Viewing all articles
Browse latest Browse all 6

Why is my if statement not working?

$
0
0

I am trying to check if a gas pump is free for use && full of gas, and then I am trying to make that pump the pump to be used by the cars in a queue.

Thread carThreads[]=new Thread[TOTAL_CARS];  try {    Pump pump1 = new Pump();    pump1.setName("pump1");    pump1.setFuelAmount(2000);    pump1.setState(0);    Pump pump2 = new Pump();    pump2.setName("pump2");    pump2.setFuelAmount(2500);    pump2.setState(0);    Pump chosenPump = new Pump();    if( pump1.getState()==0 && pump1.getFuelAmount()<0 ){      chosenPump = pump1;      System.out.println("Pump1 is free and has a fuel amount of: "+ (pump1.getFuelAmount()) );    }    else if ( pump2.getState()==0 && pump2.getFuelAmount()<0 ){      chosenPump = pump2;      System.out.println("Pump2 is free and has a fuel amount of: "+ (pump2.getFuelAmount()) );    }    //else{    //  System.out.println("Must wait for the tanker. It should be here soon");    //}    Random r = new Random();    Car car;    for(int i = 0; i<TOTAL_CARS; i++){      car = new Car(i, chosenPump);      System.out.println("car"+ car.getID() +" was created");      (carThreads[i] = new Thread(car)).start();      Thread.currentThread().sleep(r.nextInt(10000));      line.enqueue(car);      chosenPump.usePump( (Car)line.getfirst(), chosenPump, line );      System.out.println("this is the new line size for gas: "+ line.size());    }//end for  }//end try  catch (Exception e){  }}//end of main

Viewing all articles
Browse latest Browse all 6

Latest Images

Trending Articles





Latest Images