1. Create a GUI that has two check boxes which allow a user to select between a car and a truck and also create a GUI that pops up ONLY if the car is selected.

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter16: Graphics
Section: Chapter Questions
Problem 2GZ
icon
Related questions
Question

1. Create a GUI that has two check boxes which allow a user to select between a car and a truck and also create a GUI that pops up ONLY if the car is selected. This new window should contain JLabels with JTextFields that allow the user to enter in all the car's relevant information - e.g. Make, Model, Year, Number of Doors, Fuel Tank Capacity, and Driving Range. Use the same inputs from Main.java in the Appendix. The new window should also include a calculate MPG button which computes and outputs the miles per gallon when pressed. In this case, the MPG is 24.0. 

Using the appendix code below:

Appendix
// Traits.java
public interface Traits{
 public String getMake();
 public String getModel();

}
// Vehicle.java
public class Vehicle implements Traits{
 private String make;
 private String model;
 private int year;
 private int number_of_doors;
 private double fuel_tank_capacity;
 private int driving_range;
 public Vehicle(String vehicle_make, String vehicle_model, int vehicle_year, int
vehicle_number_of_doors, double fuel_capacity, int range){
 make = vehicle_make;
 model = vehicle_model;
 year = vehicle_year;
 number_of_doors = vehicle_number_of_doors;
 fuel_tank_capacity = fuel_capacity;
 driving_range = range;
 }

 //get methods
 public String getMake(){
 return make;
 }
 public String getModel(){
 return model;
 }
 public int getYear(){
 return year;
 }
 public int getNumberOfDoors(){
 return number_of_doors;
 }
 public double getFuelCapacity (){
 return fuel_tank_capacity;
 }
 public int getRange (){
 return driving_range;
 }
 public double calcMPG(){
 return driving_range / fuel_tank_capacity;
 }
}
// Truck.java
public class Truck extends Vehicle{
 private int towing_capacity;
 private int payload_capacity;
 public Truck (String make, String model, int year, int number_of_doors, double
fuel_capacity, int range, int towing, int payload){
 super(make, model, year, number_of_doors, fuel_capacity, range);
 towing_capacity = towing;
 payload_capacity = payload;
 }
 public int getTowingCapacity(){
 return towing_capacity;
 }
 public int getPayloadCapacity(){
 return payload_capacity;
 }
}
// Main.java
class Main {
 public static void main(String[] args) {
 Vehicle car = new Vehicle("Ford","Mustang",2022,2,15.5,372);
 Truck truck = new Truck("Ford","F150",2022,4,23,483,8200,2629);
 System.out.println("Make: " + car.getMake());
 System.out.println("Model: " + car.getModel());
 System.out.println("Year: " + car.getYear());
 System.out.println("Number of Doors: " + car.getNumberOfDoors());
 System.out.println("Fuel Tank Capacity: " + car.getFuelCapacity());
 System.out.println("Driving Range: " + car.getRange());
 System.out.println("MPG: " + car.calcMPG());
 System.out.println("\n");
 System.out.println("Make: " + truck.getMake());
 System.out.println("Model: " + truck.getModel());
 System.out.println("Year: " + truck.getYear());
 System.out.println("Number of Doors: " + truck.getNumberOfDoors());
 System.out.println("Fuel Tank Capacity: " + truck.getFuelCapacity());
 System.out.println("Driving Range: " + truck.getRange());
 System.out.println("Towing Capacity: " + truck.getTowingCapacity());
 System.out.println("Payload Capacity: " + truck.getPayloadCapacity());
 System.out.println("MPG: " + truck.calcMPG());
}
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Running Time of Application
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage