Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

When gasoline is $100 per barrel, then the consumer’s price at the pump is betwe

ID: 3679778 • Letter: W

Question

When gasoline is $100 per barrel, then the consumer’s price at the pump is between $3.50 and $4.00 per gallon. Create a class named GasPrices. Its main() method holds an integer variable named pricePerBarrel to which you will assign a value entered by a user at the keyboard. Create a method to which you pass pricePerBarrel. The method displays the range of possible prices per gallon. For example, if gas is $120 per barrel, then the price at the pump should be between $4.20 and $4.80. Save the application as GasPrices.java.

Explanation / Answer

import java.util.*;

public class GasPrices
   {
       public static void main(String[] args)
           {
               Scanner enter = new Scanner(System.in);
               System.out.println("Please enter the price of gas per barrel");
               int pricePerBarrel = enter.nextInt();
               calculateMinPricePerGallon(pricePerBarrel);
           }
       public static void calculateMinPricePerGallon(int pricePerBarrel)
           {
               double MIN = (float) (pricePerBarrel * 0.035);
               double MAX = (float) (pricePerBarrel * 0.040);
               System.out.println("If gas is " + pricePerBarrel + " per barrel the minimum at the pump " +
                                   "would be " + MIN + " per gallon and the maximum would be "
                                   + MAX + " per gallon.");
           }
   }

   sample output
  
Please enter the price of gas per barrel                                                                                                                    
100                                                                                                                                                         
If gas is 100 per barrel the minimum at the pump would be 3.5 per gallon and the maximum would be 4.0 per gallon.                                           

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote