Question

Its an app) (Miles-per-Gallon Calculator App) In java with comments Place AnchorPane in design and set...

Its an app) (Miles-per-Gallon Calculator App) In java with comments

Place AnchorPane in design and set its attributes

Place mileTextField, gallonsTextField and calcButton on the AnchorPane and set their attributes

Place label that will show the calculated value and set its attributes

Drivers often want to know the miles per gallon their cars get so they can estimate gasoline costs. Develop an app that allows the user to input the number of miles driven and the number of gallons used and calculates and displays the corresponding miles per gallon.

1 0
Add a comment Improve this question Transcribed image text
Answer #1

Java Code:

import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

public class GuiGasMilage extends Applet implements ActionListener {

      TextField miles, gallons, milageCalculated;

      JButton calculate;

      JPanel buttonPanel;

      //You can change the class name with your name here

      public GuiGasMilage() {

            setLayout(new GridLayout(6,3));

            //You can change the color here

            setBackground(Color.blue);

            //Creating the text fields

            miles = new TextField(15);

            gallons = new TextField(15);

            milageCalculated= new TextField(15);

            calculate= new JButton();

            JButton calculate = new JButton("Calculate");

            calculate.addActionListener(this);

            //Press Enter when all the values are entered

            add(new Label("Enter Miles: "));

            add(miles);

            add(new Label("Enter Gallons: "));

            add(gallons);

            add(new Label("Milage miles/gallon:"));

            add(milageCalculated);

           

            add(calculate);

      }

      @Override

      public void actionPerformed(ActionEvent arg0) {

            // TODO Auto-generated method stub

            double mile = Double.parseDouble(miles.getText());

            double gallon = Double.parseDouble(gallons.getText());

            double milage = (mile)/(gallon);

            milageCalculated.setText("Milage: " + milage+" miles/gallon");

      }

}

Output:

Add a comment
Know the answer?
Add Answer to:
Its an app) (Miles-per-Gallon Calculator App) In java with comments Place AnchorPane in design and set...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 7. Miles-per-Gallon 6pts A car’s miles-per-gallon (MPG) can be calculated with the following formula: MPG =...

    7. Miles-per-Gallon 6pts A car’s miles-per-gallon (MPG) can be calculated with the following formula: MPG = Miles driven / Gallons of gas used Design a program that asks the user for the number of miles driven and the gallons of gas used. It should calculate the car’s miles-per-gallon and display the result on the screen.Draw a flowchart in algorithmic language

  • I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas...

    I need trying to figure out how I can make create a code in Python with this exercise for I am having trouble doing so. Miles Per Gallon Calculator Write a GUI program that calculates a car's gas mileage. The program's window should have Entry widgets that 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,...

  • Classwork 2-2: Input & Formatting A car's miles-per-gallon (MPG) can be calculated using the formula: MPG...

    Classwork 2-2: Input & Formatting A car's miles-per-gallon (MPG) can be calculated using the formula: MPG - miles driven/gallons of gas used Write a program that asks the user for the car's make, number of miles driven and the gallons of gas used. It should calculate the car's MPG and displays the result rounded to 2 decimal places. Example "Your Honda's MPG is 28.56" On Blackboard, submit a screenshot of successfully running and testing your code on HackerRank.com: www.hackerrank.com/csc124-chapter-2-classwork (2nd...

  • Drivers are concerned with the mileage their automobiles get. One driver has kept track of several...

    Drivers are concerned with the mileage their automobiles get. One driver has kept track of several tankfuls of gasoline by recording the miles driven and gallons used for each tankful. Develop a C# app that will input the miles driven and gallons used (both as integers) for each tankful. The app should calculate and display the miles per gallon obtained for each tankful and display the combined miles per gallon obtained for all tankfuls up to this point. All averaging...

  • create an application in VISUAL BASIC that calculates a cars gas mileage. The formula for calculating...

    create an application in VISUAL BASIC that calculates a cars gas mileage. The formula for calculating the miles that a car can travel per gallon of gas is MPG = Miles/Gallon In the formula MPG is miles-per-gallon, miles is the number of miles that can be driven on a full tank of gas, and gallons is the number of gallons that the tank holds. The applications form should have TextBox controls that let the user enter the number of gallons...

  • The corporate average fuel economy (CAFE) standard for mileage is currently 26.5 miles per gallon of gasoline (the defen...

    The corporate average fuel economy (CAFE) standard for mileage is currently 26.5 miles per gallon of gasoline (the defender) for passenger cars. To conserve fuel and reduce air pollution, suppose the u.s Congress sets the CAFE standard at 35 miles per gallon(the challenger) in 2010. An auto will emit on average 0.8 pounds of carbon dioxide(c02) per mile driven at 26.5 miles per gallon, and will emit 0.65 pounds of CO2 per mile driven at 35 miles per gallon. A....

  • Hi, Hi, I need someone to write a program in Phython 3.6, and please I will...

    Hi, Hi, I need someone to write a program in Phython 3.6, and please I will appreciate if the code is error free and indented correctly. The output would be preferable. thanks Write a GUI program that translates the Latin words to English. The window should have three buttons, one for each Latin word. When the user clicks a button, the program displays the English translation in a label. 3. Miles Per Gallon Calculator Write a GUI program that calculates...

  • Use a java program that does the following: . (10 points) Write a program as follows...

    Use a java program that does the following: . (10 points) Write a program as follows a. Prompt the user to input two positive integers: nl and n2 (nl should be less than n2) b. If the user enters the negative number(s), convert it/them to positive number(s) c. If nl is greater than n2, swap them. d. Use a while loop to output all the even numbers between nl and n2 e. Use a while loop to output the sum...

  • 7.11 Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track...

    7.11 Drivers are concerned with the mileage obtained by their automobiles. One driver has kept track of several tankfuls of gasoline by recording the number of miles driven and the number of gallons used for each tankful. Develop a script that will take as input the miles driven and gallons used (both as integers) for each tankful. The script should calculate and output HTML5 text that displays the number of miles per gallon obtained for each tankful and the combined...

  • A liter is 0.264179 gallons. Write a program that will read in the number of liters...

    A liter is 0.264179 gallons. Write a program that will read in the number of liters of gasoline consumed by the user's car and the number of miles per gallon the car delivered. Your program should allow the user to repeat this calculation as often as the user wishes. Define a function to compute the number of miles per gallon. Your program should use a globally defined constant for the number of liters per gallon. After doing this... Modify your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT