Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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


 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. (20 points)

3. Create a GUI that pops up ONLY if the truck is selected. This new window should contain JLabels with JTextFields that allow the user to enter in all the truck's relevant information - e.g. Make, Model, Year, Number of Doors, Fuel Tank Capacity, Driving Range, Towing Capacity, and Payload Capacity. 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 21.0. (20 points)

4. Create a GUI error message that pops up if the user enters invalid information into the GUI from question #2. (20 points)

5. Create a GUI error message that pops up if the user enters invalid information into the GUI from question #3. (20 points) Develop a report that contains an overview of the source code. It should also include print screens of the GUIs from each scenario mentioned above. Develop, compile, and run source code in Repl.it. No marks will be given to code that does not compile/run. Copy source code and paste in the report's

Appendix. Note, all responses should be contained in ONE WORD or PDF document. Other formats will not be accepted.

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;

}

public String getMake(){

return make;

}

public String getModel(){ re

turn 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(" ");

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());

}

}

Step by Step Solution

3.38 Rating (148 Votes )

There are 3 Steps involved in it

Step: 1

To create the GUIs and error messages as described you would typically use a GUI framework like Swing or JavaFX Below is an example of how you could i... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intermediate Microeconomics

Authors: Hal R. Varian

9th edition

978-0393123975, 393123979, 393123960, 978-0393919677, 393919676, 978-0393123968

More Books

Students also viewed these Programming questions