Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3353516
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:09:38+00:00 2026-05-18T02:09:38+00:00

I am trying to check if a gas pump is free for use &&

  • 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:09:39+00:00Added an answer on May 18, 2026 at 2:09 am

    You are checking pump1.getFuelAmount()<0

    This will check if the pump has a negative amount of fuel. If you want to see if it has a positive amount of fuel, you need to do pump1.getFuelAmount()>0 and pump2.getFuelAmount()>0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to check that an address isn't being used before I delete
I'm trying to check if a file exists. If I use this: NSData *data
I'm trying to check to make sure an item is visible before I start
I'm trying to check a check box, if the value for that field is
Im trying to check if a string (important that it is a string) that
Trying to check if a text box is visible then the user should enter
I'm trying to check that the fields in the form below have been filled
I'm trying to check that a user of this code runs this program from
Trying to check and see if two cells are both false, and use a
I am trying to check a series of buttons to see if they have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.