-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVehicleAxlesPanel.java
More file actions
executable file
·100 lines (74 loc) · 2.69 KB
/
VehicleAxlesPanel.java
File metadata and controls
executable file
·100 lines (74 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @(#)VehicleAxlesPanel.java
*
*
* @Derick Warshaw // Lab 12 // COSC1337
* @version 1.00 2014/4/24
*/
import javax.swing.*;
import java.awt.*;
/**The VehicleAxlesPanel class allows the user to select how many axles the
*vehicle has */
public class VehicleAxlesPanel extends JPanel
{
private JRadioButton twoVehicleAxleButton; // select 2 vehicle axle
private JRadioButton threeVehicleAxleButton;// select 3 vehicle axle
private JRadioButton fourVehicleAxleButton;// select 4 vehicle axle
private JRadioButton fiveOrMoreVehicleAxleButton;// 5 or more
private ButtonGroup vehicleAxlesGroup; // radio button group
/**VehicleAxlesPanel Constructor performs setup operations */
public VehicleAxlesPanel()
{
// grid layout
setLayout(new GridLayout(4,1));
// create radio buttons with 2 axles being the default
twoVehicleAxleButton = new JRadioButton("2 ", true);
threeVehicleAxleButton = new JRadioButton("3 ");
fourVehicleAxleButton = new JRadioButton("4 ");
fiveOrMoreVehicleAxleButton = new JRadioButton("5 or more ");
// add radio buttons to group
vehicleAxlesGroup = new ButtonGroup();
vehicleAxlesGroup.add(twoVehicleAxleButton);
vehicleAxlesGroup.add(threeVehicleAxleButton);
vehicleAxlesGroup.add(fourVehicleAxleButton);
vehicleAxlesGroup.add(fiveOrMoreVehicleAxleButton);
// add a border around the panel
setBorder(BorderFactory.createTitledBorder("Vehicle Axles"));
//add the radio buttons to the panel
add(twoVehicleAxleButton);
add(threeVehicleAxleButton);
add(fourVehicleAxleButton);
add(fiveOrMoreVehicleAxleButton);
}
/**The getVehicleAxleCost method determines how much to charge
*@returns cost is a double data type fee
* */
public double getVehicleAxleCost()
{
// constant values for tolls
final double VEHICLE_AXLES_2 = 0.25;
final double VEHICLE_AXLES_3 = 0.50;
final double VEHICLE_AXLES_4 = 0.75;
final double VEHICLE_AXLES_5_OR_MORE = 1.00;
// cost is a calculated value for the appropriate toll
double cost = 0.0;
// determining which toll is appropriate given number of axles selected
if(twoVehicleAxleButton.isSelected())
{
cost = VEHICLE_AXLES_2;
}
else if(threeVehicleAxleButton.isSelected())
{
cost = VEHICLE_AXLES_3;
}
else if(fourVehicleAxleButton.isSelected())
{
cost = VEHICLE_AXLES_4;
}
else if(fiveOrMoreVehicleAxleButton.isSelected())
{
cost = VEHICLE_AXLES_5_OR_MORE;
}
return cost;
}
}