Write a GUI program that calculates a car's gas mileage. The programs window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles or kilometers it can be driven on a full tank. When a Calculate MPG button is clicked, the program should display the number of miles or kilometers that the car may be driven per gallon of gas. Use the following formula to calculate miles-per-gallon:

MPG = miles / gallons
miles = kilometers x 0.6214

NOTE: The user should be able to choose a radio button for Miles or Kilometers, then the corresponding label should appear. Because some of the functionality to remove/ replace a label and/or frame are beyond the scope of this course, you only required to display according to one selection.

ASSUMPTIONS - The user will:

  • enter appropriate, numerical data.
  • NOT click the Calculate MPG button until after appropriate data is entered.
  • choose either Miles or Kilometers and NOT switch back and forth.
  • execute just one run of the program, then click the Quit button which closes the program.

The GUI must display as follows (please do NOT deviate from the images below):

Images and explanation of what user should see

Initial screen. No radio button should be selected: see image.

If the user chooses Miles, the appropriate label should display. Notice it says "Enter the number of miles": see image.

After the user enters data, the appropriate calculation should display. At this point, the user will click Quit and the window closes: see image.

After the initial screen, if the user chooses Kilometers, the appropriate label should display. Notice it says "Enter the number of kilometers": see image.

After the user enters data, the appropriate calculation should display. At this point, the user will click Quit and the window closes: see image.

Write the code for the program in one file.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.