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 betw

ID: 661869 • 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, the the price at the pubp should be between $4.20 and 4.80. Save the application as GasPrices.java.

Explanation / Answer

import java.util.*;
public class GasPrices
{
   public double perbarrel = 120;
   public double pergallon_low = 4.20;
   public double pergallon_high = 4.80;
  
   public static
   void main (String args[])
   {
       Scanner s = new Scanner ( System.in );
       System.out.print ( "pricePerBarrel : " );
       double pricePerBarrel = s.nextDouble ();
       System.out.printf
       (
           "pricePerGallon : %.2f to %.2f ",
           getBecomes2 ( 120, 4.20, pricePerBarrel ),
           getBecomes2 ( 120, 4.80, pricePerBarrel )
       );
   }
  
  
   public static
   double getBecomes2
   (
       double what,
       double becomes,
       double what2
   )
   {
       /*
       * what -> becomes
           what2 -> n ?
           becomes x what2
           n =   ----------------
                  what
       */
      
       /*
      
       System.out.println (what, "->", becomes);
       System.out.println (what2, "-> ?");
      
       */
      
       double result =
       ( becomes * what2 ) / what;
      
       /*
       System.out.println (what, "->", becomes);
       System.out.println (what2, "->", result);
       */
      
       return
       result;
   }
}

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