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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education