Create an Account

Already have account?

Forgot Your Password ?

Home / Questions / Write a GUI application that calculates a cars gas mileage The application should let the ...

Write a GUI application that calculates a cars gas mileage The application should let the user enter the number of gallons of gas the car holds and the number of miles it can be driven on a full

  1. Write a GUI application that calculates a car’s gas mileage. The application should let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked, the application should display the number of miles that the car may be driven per gallon of gas. Use the following formula to calculate MPG: 

 

MPG = Miles / Gallons.

 

//Here are the given class fields and layout to help you with the coding.

 

public class MPGCalculator extends JFrame

 

//Components

private JPanel panel;

private JTextField gallonsInput;

private JTextField milesInput;

private JButton calcButton;

 

//Constants for the window size

private final int WINDOW_WIDTH = 360;

private final int WINDOW_HEIGHT = 130;

 

//Constructor 

 

// Set the title

 

          

 

           // Specify what happens when the close button is clicked.

           setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

 

           // Build the panel that contains the other components.

 

 

 

           // Add the panel to the content pane.

 

 

 

 

           // Size and display the window.

 

 

 

 

      //build panel method 

Jun 15 2020 View more View Less

Answer (Solved)

question Subscribe To Get Solution

Related Questions