Question: import javax.swing.*; public class TaxiFareFrame extends JFrame { private JButton btnGetQuote; private JTextField txtDistance; private JTextField txtPeople; private JCheckBox chkNightTime; private JLabel lblFare; TaxiFareFrame() {
import javax.swing.*;
public class TaxiFareFrame extends JFrame { private JButton btnGetQuote; private JTextField txtDistance; private JTextField txtPeople; private JCheckBox chkNightTime; private JLabel lblFare; TaxiFareFrame() { txtDistance = new JTextField(4); txtPeople = new JTextField(2); chkNightTime = new JCheckBox("Night (12am-6am)?"); btnGetQuote = new JButton("Get Quote"); lblFare = new JLabel(" "); setLayout(new GridLayout(0,2,5,5)); add(new JLabel("Distance:")); add(txtDistance); add(new JLabel("Passengers:")); add(txtPeople); add(chkNightTime); add(btnGetQuote); add(new JLabel("Fare per passenger:")); add(lblFare); btnGetQuote.addActionListener( // Missing Code needs to go here. ); } }
We need to add further code (at the indicated place), so that when the button labelled "Get Quote" is clicked, it will interpret the user's input to calculate a fare and display this in the label lblFare. The fare is calculated by first multiplying the distance (an integer) by $2.20. If it is a night-time fare, then there is a 35% surcharge, which is calculated by multiplying the basic fare price by 1.35. Finally it works out how many passengers there are, and divides the total fare by the number of passengers to report the amount each passenger has to pay. The distance must be a valid positive integer value and there must be at least one passenger, otherwise it will report "Error with Input or Calculations" instead of the fare.
TASK: Write the missing code, which needs to make use of an anonymous inner class, so that the button will behave as described. For your answer you can either type/paste an answer in the first box, or you can upload a file to the second box.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
